llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Simi Pallipurath (simpal01)

<details>
<summary>Changes</summary>

Update the multilib selection logic to bypass the alignment option based on 
each architecture’s feature set, rather than relying on command-line options.

Previously, alignment option was bypassed only when -mno-unaligned-access was 
explicitly specified on the command line. This change makes the selection more 
robust and architecture aware.

---
Full diff: https://github.com/llvm/llvm-project/pull/134099.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+12-12) 
- (modified) clang/test/Driver/print-multi-selection-flags.c (+6) 


``````````diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 8a922b283daf5..476026f82b32b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -239,12 +239,12 @@ 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");
+    Result.push_back("-mstrict-align");
+  } else {
+    Result.push_back("-munaligned-access");
+    Result.push_back("-mno-strict-align");
   }
 
   if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
@@ -313,12 +313,12 @@ 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");
+    Result.push_back("-mstrict-align");
+  } else {
+    Result.push_back("-munaligned-access");
+    Result.push_back("-mno-strict-align");
   }
 
   if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 5a35ae374f011..b21c2d11c1009 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -69,9 +69,15 @@
 // 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 | 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
 // 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 -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 -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

``````````

</details>


https://github.com/llvm/llvm-project/pull/134099
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to