[clang] cb0d130 - [Clang][ARM] Ensure both -mno-unaligned-access and -munaligned-access are passed to multilib selection logic (#134099)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 3 03:16:08 PDT 2025
Author: Simi Pallipurath
Date: 2025-04-03T11:16:05+01:00
New Revision: cb0d1305d12ea6637a541028eb0a4438750164b9
URL: https://github.com/llvm/llvm-project/commit/cb0d1305d12ea6637a541028eb0a4438750164b9
DIFF: https://github.com/llvm/llvm-project/commit/cb0d1305d12ea6637a541028eb0a4438750164b9.diff
LOG: [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.
Added:
Modified:
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/print-multi-selection-flags.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 8a922b283daf5..ad73814b3efba 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -239,13 +239,10 @@ static void getAArch64MultilibFlags(const Driver &D,
Result.push_back(BranchProtectionArg->getAsString(Args));
}
- if (Arg *AlignArg = Args.getLastArg(
- options::OPT_mstrict_align, options::OPT_mno_strict_align,
- options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
- if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
- AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
- Result.push_back(AlignArg->getAsString(Args));
- }
+ if (FeatureSet.contains("+strict-align"))
+ Result.push_back("-mno-unaligned-access");
+ else
+ Result.push_back("-munaligned-access");
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
options::OPT_mlittle_endian)) {
@@ -313,13 +310,10 @@ static void getARMMultilibFlags(const Driver &D,
Result.push_back(BranchProtectionArg->getAsString(Args));
}
- if (Arg *AlignArg = Args.getLastArg(
- options::OPT_mstrict_align, options::OPT_mno_strict_align,
- options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
- if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
- AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
- Result.push_back(AlignArg->getAsString(Args));
- }
+ if (FeatureSet.contains("+strict-align"))
+ Result.push_back("-mno-unaligned-access");
+ else
+ Result.push_back("-munaligned-access");
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
options::OPT_mlittle_endian)) {
diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c
index 5a35ae374f011..5f9383fbed8f4 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -69,9 +69,19 @@
// CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
// 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
+// 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
+// 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
// 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
+// 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
// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
+// 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
+// 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
+// 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
+// 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
+// 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
+// CHECK-UNALIGNED-ACCESS: -munaligned-access
+
// 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
// 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
// CHECK-BIG-ENDIAN: -mbig-endian
More information about the cfe-commits
mailing list