Skip to content

Commit cb0d130

Browse files
authored
[Clang][ARM] Ensure both -mno-unaligned-access and -munaligned-access are passed to multilib selection logic (#134099)
Previously, alignment option was passed to multilib selection logic only when -mno-unaligned-access was explicitly specified on the command line. Now this change ensure both -mno-unaligned-access and -munaligned-access are passed to the multilib selection logic, which now also considers the target architecture when determining alignment access policy.
1 parent 6c27817 commit cb0d130

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,10 @@ static void getAArch64MultilibFlags(const Driver &D,
239239
Result.push_back(BranchProtectionArg->getAsString(Args));
240240
}
241241

242-
if (Arg *AlignArg = Args.getLastArg(
243-
options::OPT_mstrict_align, options::OPT_mno_strict_align,
244-
options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
245-
if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
246-
AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
247-
Result.push_back(AlignArg->getAsString(Args));
248-
}
242+
if (FeatureSet.contains("+strict-align"))
243+
Result.push_back("-mno-unaligned-access");
244+
else
245+
Result.push_back("-munaligned-access");
249246

250247
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
251248
options::OPT_mlittle_endian)) {
@@ -313,13 +310,10 @@ static void getARMMultilibFlags(const Driver &D,
313310
Result.push_back(BranchProtectionArg->getAsString(Args));
314311
}
315312

316-
if (Arg *AlignArg = Args.getLastArg(
317-
options::OPT_mstrict_align, options::OPT_mno_strict_align,
318-
options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
319-
if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
320-
AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
321-
Result.push_back(AlignArg->getAsString(Args));
322-
}
313+
if (FeatureSet.contains("+strict-align"))
314+
Result.push_back("-mno-unaligned-access");
315+
else
316+
Result.push_back("-munaligned-access");
323317

324318
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
325319
options::OPT_mlittle_endian)) {

clang/test/Driver/print-multi-selection-flags.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@
6969
// CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
7070

7171
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
72+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mstrict-align | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
73+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
7274
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
75+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mstrict-align | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
7376
// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
7477

78+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mno-strict-align | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
79+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -munaligned-access | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
80+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
81+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mno-strict-align | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
82+
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -munaligned-access | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
83+
// CHECK-UNALIGNED-ACCESS: -munaligned-access
84+
7585
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mbig-endian | FileCheck --check-prefix=CHECK-BIG-ENDIAN %s
7686
// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mbig-endian | FileCheck --check-prefix=CHECK-BIG-ENDIAN %s
7787
// CHECK-BIG-ENDIAN: -mbig-endian

0 commit comments

Comments
 (0)