Skip to content

Commit 764d6b8

Browse files
committed
[Clang][ARM]Ensure both -mno-unaligned-access and -munaligned-access are passed to multilib selection logic
We need to incorporate the upstreamed patch llvm/llvm-project#134099 into the 20.x branch. So applying this as patch file.
1 parent e4f1bb8 commit 764d6b8

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
From 0ab1883ad76b6687998e118064c98ac06f3deffa Mon Sep 17 00:00:00 2001
2+
From: Simi Pallipurath <[email protected]>
3+
Date: Thu, 3 Apr 2025 11:16:05 +0100
4+
Subject: [Clang][ARM] Ensure both -mno-unaligned-access and
5+
-munaligned-access are passed to multilib selection logic (#134099)
6+
7+
Previously, alignment option was passed to multilib selection logic only
8+
when -mno-unaligned-access was explicitly specified on the command line.
9+
10+
Now this change ensure both -mno-unaligned-access and -munaligned-access
11+
are passed to the multilib selection logic, which now also considers the
12+
target architecture when determining alignment access policy.
13+
14+
(cherry picked from commit cb0d1305d12ea6637a541028eb0a4438750164b9)
15+
---
16+
clang/lib/Driver/ToolChain.cpp | 22 +++++++------------
17+
.../test/Driver/print-multi-selection-flags.c | 10 +++++++++
18+
2 files changed, 18 insertions(+), 14 deletions(-)
19+
20+
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
21+
index acf9d264d631..c998535b07ad 100644
22+
--- a/clang/lib/Driver/ToolChain.cpp
23+
+++ b/clang/lib/Driver/ToolChain.cpp
24+
@@ -237,13 +237,10 @@ static void getAArch64MultilibFlags(const Driver &D,
25+
Result.push_back(BranchProtectionArg->getAsString(Args));
26+
}
27+
28+
- if (Arg *AlignArg = Args.getLastArg(
29+
- options::OPT_mstrict_align, options::OPT_mno_strict_align,
30+
- options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
31+
- if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
32+
- AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
33+
- Result.push_back(AlignArg->getAsString(Args));
34+
- }
35+
+ if (FeatureSet.contains("+strict-align"))
36+
+ Result.push_back("-mno-unaligned-access");
37+
+ else
38+
+ Result.push_back("-munaligned-access");
39+
40+
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
41+
options::OPT_mlittle_endian)) {
42+
@@ -311,13 +308,10 @@ static void getARMMultilibFlags(const Driver &D,
43+
Result.push_back(BranchProtectionArg->getAsString(Args));
44+
}
45+
46+
- if (Arg *AlignArg = Args.getLastArg(
47+
- options::OPT_mstrict_align, options::OPT_mno_strict_align,
48+
- options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
49+
- if (AlignArg->getOption().matches(options::OPT_mstrict_align) ||
50+
- AlignArg->getOption().matches(options::OPT_mno_unaligned_access))
51+
- Result.push_back(AlignArg->getAsString(Args));
52+
- }
53+
+ if (FeatureSet.contains("+strict-align"))
54+
+ Result.push_back("-mno-unaligned-access");
55+
+ else
56+
+ Result.push_back("-munaligned-access");
57+
58+
if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian,
59+
options::OPT_mlittle_endian)) {
60+
diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c
61+
index 5a35ae374f01..5f9383fbed8f 100644
62+
--- a/clang/test/Driver/print-multi-selection-flags.c
63+
+++ b/clang/test/Driver/print-multi-selection-flags.c
64+
@@ -69,9 +69,19 @@
65+
// CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
66+
67+
// 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
68+
+// 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
69+
+// 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
70+
// 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
71+
+// 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
72+
// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
73+
74+
+// 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
75+
+// 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
76+
+// 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
77+
+// 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
78+
+// 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
79+
+// CHECK-UNALIGNED-ACCESS: -munaligned-access
80+
+
81+
// 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
82+
// 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
83+
// CHECK-BIG-ENDIAN: -mbig-endian
84+
--
85+
2.34.1
86+

0 commit comments

Comments
 (0)