Skip to content

Commit cd07125

Browse files
authored
[Driver] Don't alias -mstrict-align to -mno-unaligned-access
GCC ports only supports one of the options, with -mstrict-align preferred by newer ports. They reject adding -m[no-]unaligned-access to newer ports that use -m[no-]strict-align. (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111555). We should not support aliases, either. Since the behavior has been long-time for ARM (a146a48), support both forms for ARM for now but remove -m[no-]unaligned-access for RISC-V/LoongArch (see also riscv-non-isa/riscv-c-api-doc#62). While here, add TargetSpecific to ensure errors on unsupported targets (https://reviews.llvm.org/D151590) and remove unneeded CC1 options. Pull Request: #85350
1 parent b8db3e7 commit cd07125

File tree

10 files changed

+43
-67
lines changed

10 files changed

+43
-67
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ Removed Compiler Flags
191191
-------------------------
192192

193193
- The ``-freroll-loops`` flag has been removed. It had no effect since Clang 13.
194+
- ``-m[no-]unaligned-access`` is removed for RISC-V and LoongArch.
195+
``-m[no-]strict-align``, also supported by GCC, should be used instead.
196+
(`#85350 <https://github.com/llvm/llvm-project/pull/85350>`_.)
194197

195198
Attribute Changes in Clang
196199
--------------------------

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4696,21 +4696,17 @@ def mrvv_vector_bits_EQ : Joined<["-"], "mrvv-vector-bits=">, Group<m_Group>,
46964696
" (RISC-V only)")>;
46974697

46984698
def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_Group>,
4699-
HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64/LoongArch/RISC-V only)">;
4699+
HelpText<"Allow memory accesses to be unaligned (AArch32 only)">;
47004700
def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_Group>,
4701-
HelpText<"Force all memory accesses to be aligned (AArch32/AArch64/LoongArch/RISC-V only)">;
4701+
HelpText<"Force all memory accesses to be aligned (AArch32 only)">;
47024702
def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group<m_Group>,
47034703
HelpText<"Expect external char-aligned symbols to be without ABI alignment (SystemZ only)">;
47044704
def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, Group<m_Group>,
47054705
HelpText<"Expect external char-aligned symbols to be without ABI alignment (SystemZ only)">;
4706-
} // let Flags = [TargetSpecific]
4707-
def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>,
4708-
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
4709-
HelpText<"Force all memory accesses to be aligned (same as mno-unaligned-access)">;
4710-
def mno_strict_align : Flag<["-"], "mno-strict-align">, Alias<munaligned_access>,
4711-
Flags<[HelpHidden]>, Visibility<[ClangOption, CC1Option]>,
4712-
HelpText<"Allow memory accesses to be unaligned (same as munaligned-access)">;
4713-
let Flags = [TargetSpecific] in {
4706+
def mstrict_align : Flag<["-"], "mstrict-align">,
4707+
HelpText<"Force all memory accesses to be aligned (AArch64/LoongArch/RISC-V only)">;
4708+
def mno_strict_align : Flag<["-"], "mno-strict-align">,
4709+
HelpText<"Allow memory accesses to be unaligned (AArch64/LoongArch/RISC-V only)">;
47144710
def mno_thumb : Flag<["-"], "mno-thumb">, Group<m_arm_Features_Group>;
47154711
def mrestrict_it: Flag<["-"], "mrestrict-it">, Group<m_arm_Features_Group>,
47164712
HelpText<"Disallow generation of complex IT blocks. It is off by default.">;

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,11 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
321321
}
322322
}
323323

324-
if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
325-
options::OPT_munaligned_access)) {
326-
if (A->getOption().matches(options::OPT_mno_unaligned_access))
324+
if (Arg *A = Args.getLastArg(
325+
options::OPT_mstrict_align, options::OPT_mno_strict_align,
326+
options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
327+
if (A->getOption().matches(options::OPT_mstrict_align) ||
328+
A->getOption().matches(options::OPT_mno_unaligned_access))
327329
Features.push_back("+strict-align");
328330
} else if (Triple.isOSOpenBSD())
329331
Features.push_back("+strict-align");

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,21 +868,24 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
868868
}
869869
}
870870

871-
// Kernel code has more strict alignment requirements.
872-
if (KernelOrKext) {
873-
Features.push_back("+strict-align");
874-
} else if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
875-
options::OPT_munaligned_access)) {
876-
if (A->getOption().matches(options::OPT_munaligned_access)) {
871+
if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
872+
options::OPT_munaligned_access,
873+
options::OPT_mstrict_align,
874+
options::OPT_mno_strict_align)) {
875+
// Kernel code has more strict alignment requirements.
876+
if (KernelOrKext ||
877+
A->getOption().matches(options::OPT_mno_unaligned_access) ||
878+
A->getOption().matches(options::OPT_mstrict_align)) {
879+
Features.push_back("+strict-align");
880+
} else {
877881
// No v6M core supports unaligned memory access (v6M ARM ARM A3.2).
878882
if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
879883
D.Diag(diag::err_target_unsupported_unaligned) << "v6m";
880884
// v8M Baseline follows on from v6M, so doesn't support unaligned memory
881885
// access either.
882886
else if (Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
883887
D.Diag(diag::err_target_unsupported_unaligned) << "v8m.base";
884-
} else
885-
Features.push_back("+strict-align");
888+
}
886889
} else {
887890
// Assume pre-ARMv6 doesn't support unaligned accesses.
888891
//

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
165165
}
166166
}
167167

168-
// Select the `ual` feature determined by -m[no-]unaligned-access
169-
// or the alias -m[no-]strict-align.
170-
AddTargetFeature(Args, Features, options::OPT_munaligned_access,
171-
options::OPT_mno_unaligned_access, "ual");
168+
// Select the `ual` feature determined by -m[no-]strict-align.
169+
AddTargetFeature(Args, Features, options::OPT_mno_strict_align,
170+
options::OPT_mstrict_align, "ual");
172171

173172
// Accept but warn about these TargetSpecific options.
174173
if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))

clang/lib/Driver/ToolChains/Arch/RISCV.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
167167
Features.push_back("-relax");
168168
}
169169

170-
// -mno-unaligned-access is default, unless -munaligned-access is specified.
171-
AddTargetFeature(Args, Features, options::OPT_munaligned_access,
172-
options::OPT_mno_unaligned_access, "fast-unaligned-access");
170+
// -mstrict-align is default, unless -mno-strict-align is specified.
171+
AddTargetFeature(Args, Features, options::OPT_mno_strict_align,
172+
options::OPT_mstrict_align, "fast-unaligned-access");
173173

174174
// Now add any that the user explicitly requested on the command line,
175175
// which may override the defaults.

clang/test/Driver/apple-kext-mkernel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// CHECK-X86-2: "-fno-rtti"
1414
// CHECK-X86-2-NOT: "-fno-common"
1515

16-
// RUN: not %clang -target x86_64-apple-darwin11 -arch armv7 -mkernel -mstrict-align -### -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
17-
// RUN: not %clang -target x86_64-apple-darwin11 -arch armv7 -mkernel -mstrict-align -### -fsyntax-only -fbuiltin -fno-builtin -fcommon -fno-common %s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
16+
// RUN: %clang --target=x86_64-apple-darwin11 -arch armv7 -mkernel -mstrict-align -### -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
17+
// RUN: %clang --target=x86_64-apple-darwin11 -arch armv7 -mkernel -mstrict-align -### -fsyntax-only -fbuiltin -fno-builtin -fcommon -fno-common %s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
1818

1919
// CHECK-ARM: "-target-feature" "+long-calls"
2020
// CHECK-ARM: "-target-feature" "+strict-align"
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,35 @@
11
/// Test -m[no-]unaligned-access and -m[no-]strict-align options.
22

3-
// RUN: %clang --target=loongarch64 -munaligned-access -fsyntax-only %s -### 2>&1 | \
4-
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
5-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \
6-
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
73
// RUN: %clang --target=loongarch64 -mstrict-align -fsyntax-only %s -### 2>&1 | \
84
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
95
// RUN: %clang --target=loongarch64 -mno-strict-align -fsyntax-only %s -### 2>&1 | \
106
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
11-
// RUN: %clang --target=loongarch64 -munaligned-access -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \
12-
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
13-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -munaligned-access -fsyntax-only %s -### 2>&1 | \
14-
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
157
// RUN: %clang --target=loongarch64 -mstrict-align -mno-strict-align -fsyntax-only %s -### 2>&1 | \
168
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
179
// RUN: %clang --target=loongarch64 -mno-strict-align -mstrict-align -fsyntax-only %s -### 2>&1 | \
1810
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
19-
// RUN: %clang --target=loongarch64 -munaligned-access -mstrict-align -fsyntax-only %s -### 2>&1 | \
20-
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
21-
// RUN: %clang --target=loongarch64 -mstrict-align -munaligned-access -fsyntax-only %s -### 2>&1 | \
22-
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
23-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -mno-strict-align -fsyntax-only %s -### 2>&1 | \
24-
// RUN: FileCheck %s --check-prefix=CC1-UNALIGNED
25-
// RUN: %clang --target=loongarch64 -mno-strict-align -mno-unaligned-access -fsyntax-only %s -### 2>&1 | \
26-
// RUN: FileCheck %s --check-prefix=CC1-NO-UNALIGNED
2711

28-
// RUN: %clang --target=loongarch64 -munaligned-access -S -emit-llvm %s -o - | \
29-
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
30-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -S -emit-llvm %s -o - | \
31-
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
3212
// RUN: %clang --target=loongarch64 -mstrict-align -S -emit-llvm %s -o - | \
3313
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
3414
// RUN: %clang --target=loongarch64 -mno-strict-align -S -emit-llvm %s -o - | \
3515
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
36-
// RUN: %clang --target=loongarch64 -munaligned-access -mno-unaligned-access -S -emit-llvm %s -o - | \
37-
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
38-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -munaligned-access -S -emit-llvm %s -o - | \
39-
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
4016
// RUN: %clang --target=loongarch64 -mstrict-align -mno-strict-align -S -emit-llvm %s -o - | \
4117
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
4218
// RUN: %clang --target=loongarch64 -mno-strict-align -mstrict-align -S -emit-llvm %s -o - | \
4319
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
44-
// RUN: %clang --target=loongarch64 -munaligned-access -mstrict-align -S -emit-llvm %s -o - | \
45-
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
46-
// RUN: %clang --target=loongarch64 -mstrict-align -munaligned-access -S -emit-llvm %s -o - | \
47-
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
48-
// RUN: %clang --target=loongarch64 -mno-unaligned-access -mno-strict-align -S -emit-llvm %s -o - | \
49-
// RUN: FileCheck %s --check-prefix=IR-UNALIGNED
50-
// RUN: %clang --target=loongarch64 -mno-strict-align -mno-unaligned-access -S -emit-llvm %s -o - | \
51-
// RUN: FileCheck %s --check-prefix=IR-NO-UNALIGNED
20+
21+
// RUN: not %clang -### --target=loongarch64 -mno-unaligned-access -munaligned-access %s 2>&1 | \
22+
// RUN: FileCheck %s --check-prefix=ERR
5223

5324
// CC1-UNALIGNED: "-target-feature" "+ual"
5425
// CC1-NO-UNALIGNED: "-target-feature" "-ual"
5526

5627
// IR-UNALIGNED: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+ual{{(,.*)?}}"
5728
// IR-NO-UNALIGNED: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-ual{{(,.*)?}}"
5829

30+
// ERR: error: unsupported option '-mno-unaligned-access' for target 'loongarch64'
31+
// ERR: error: unsupported option '-munaligned-access' for target 'loongarch64'
32+
5933
int foo(void) {
6034
return 3;
6135
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/// Check -m[no-]unaligned-access and -m[no-]strict-align are warned unused on a target that does not support them.
1+
/// Check -m[no-]unaligned-access and -m[no-]strict-align are errored on a target that does not support them.
22

33
// RUN: not %clang --target=x86_64 -munaligned-access -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=unaligned-access
44
// RUN: not %clang --target=x86_64 -mno-unaligned-access -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=no-unaligned-access
5-
// RUN: not %clang --target=x86_64 -mstrict-align -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=strict-align
6-
// RUN: not %clang --target=x86_64 -mno-strict-align -fsyntax-only %s -### 2>&1 | FileCheck %s -DOPTION=no-strict-align
5+
// RUN: not %clang --target=x86_64 -mno-strict-align -mstrict-align -fsyntax-only %s -### 2>&1 | FileCheck %s --check-prefix=ALIGN
76

87
// CHECK: error: unsupported option '-m{{(no-)?}}unaligned-access' for target '{{.*}}'
8+
// ALIGN: error: unsupported option '-mno-strict-align' for target '{{.*}}'
9+
// ALIGN: error: unsupported option '-mstrict-align' for target '{{.*}}'

clang/test/Driver/riscv-features.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
// NO-FORCE-SW-SCS: "-target-feature" "-forced-sw-shadow-stack"
3434
// DEFAULT-NOT: "-target-feature" "+forced-sw-shadow-stack"
3535

36-
// RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS
37-
// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-unaligned-access 2>&1 | FileCheck %s -check-prefix=NO-FAST-UNALIGNED-ACCESS
3836
// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS
3937
// RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | FileCheck %s -check-prefix=NO-FAST-UNALIGNED-ACCESS
4038

0 commit comments

Comments
 (0)