Skip to content

Commit be8180a

Browse files
committed
[clang][driver] Warn when '-mno-outline-atomics' is used with a non-AArch64 triple
The Linux kernel has a make macro called cc-option that invokes the compiler with an option in isolation to see if it is supported before adding it to CFLAGS. The exit code of the compiler is used to determine if the flag is supported and should be added to the compiler invocation. A call to cc-option with '-mno-outline-atomics' was added to prevent linking errors with newer GCC versions but this call succeeds with a non-AArch64 target because there is no warning from clang with '-mno-outline-atomics', just '-moutline-atomics'. Because the call succeeds and adds '-mno-outline-atomics' to the compiler invocation, there is a warning from LLVM because the 'outline-atomics target feature is only supported by the AArch64 backend. $ echo | clang -target x86_64 -moutline-atomics -Werror -x c -c -o /dev/null - clang-14: error: The 'x86_64' architecture does not support -moutline-atomics; flag ignored [-Werror,-Woption-ignored] $ echo $? 1 $ echo | clang -target x86_64 -mno-outline-atomics -Werror -x c -c -o /dev/null - '-outline-atomics' is not a recognized feature for this target (ignoring feature) $ echo $? 0 This does not match GCC's behavior, which errors when the flag is added to a non-AArch64 target. $ echo | gcc -moutline-atomics -x c -c -o /dev/null - gcc: error: unrecognized command-line option ‘-moutline-atomics’; did you mean ‘-finline-atomics’? $ echo | gcc -mno-outline-atomics -x c -c -o /dev/null - gcc: error: unrecognized command-line option ‘-mno-outline-atomics’; did you mean ‘-fno-inline-atomics’? $ echo | aarch64-linux-gnu-gcc -moutline-atomics -x c -c -o /dev/null - $ echo | aarch64-linux-gnu-gcc -mno-outline-atomics -x c -c -o /dev/null - To get closer to GCC's behavior, issue a warning when '-mno-outline-atomics' is used without an AArch64 triple and do not add '{-,+}outline-atomic" to the list of target features in these cases. Link: ClangBuiltLinux/linux#1552 Reviewed By: melver, nickdesaulniers Differential Revision: https://reviews.llvm.org/D116128
1 parent bf45624 commit be8180a

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def warn_drv_moutline_unsupported_opt : Warning<
568568
InGroup<OptionIgnored>;
569569

570570
def warn_drv_moutline_atomics_unsupported_opt : Warning<
571-
"'%0' does not support '-moutline-atomics'; flag ignored">,
571+
"'%0' does not support '-%1'; flag ignored">,
572572
InGroup<OptionIgnored>;
573573

574574
def warn_drv_darwin_sdk_invalid_settings : Warning<

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7007,18 +7007,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70077007

70087008
if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
70097009
options::OPT_mno_outline_atomics)) {
7010-
if (A->getOption().matches(options::OPT_moutline_atomics)) {
7011-
// Option -moutline-atomics supported for AArch64 target only.
7012-
if (!Triple.isAArch64()) {
7013-
D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
7014-
<< Triple.getArchName();
7015-
} else {
7010+
// Option -moutline-atomics supported for AArch64 target only.
7011+
if (!Triple.isAArch64()) {
7012+
D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
7013+
<< Triple.getArchName() << A->getOption().getName();
7014+
} else {
7015+
if (A->getOption().matches(options::OPT_moutline_atomics)) {
70167016
CmdArgs.push_back("-target-feature");
70177017
CmdArgs.push_back("+outline-atomics");
7018+
} else {
7019+
CmdArgs.push_back("-target-feature");
7020+
CmdArgs.push_back("-outline-atomics");
70187021
}
7019-
} else {
7020-
CmdArgs.push_back("-target-feature");
7021-
CmdArgs.push_back("-outline-atomics");
70227022
}
70237023
} else if (Triple.isAArch64() &&
70247024
getToolChain().IsAArch64OutlineAtomicsDefault(Args)) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang -target x86_64 -moutline-atomics -S %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OUTLINE-ATOMICS-X86
2+
// CHECK-OUTLINE-ATOMICS-X86: warning: 'x86_64' does not support '-moutline-atomics'; flag ignored [-Woption-ignored]
3+
// CHECK-OUTLINE-ATOMICS-X86-NOT: "-target-feature" "+outline-atomics"
4+
5+
// RUN: %clang -target x86_64 -mno-outline-atomics -S %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-NO-OUTLINE-ATOMICS-X86
6+
// CHECK-NO-OUTLINE-ATOMICS-X86: warning: 'x86_64' does not support '-mno-outline-atomics'; flag ignored [-Woption-ignored]
7+
// CHECK-NO-OUTLINE-ATOMICS-X86-NOT: "-target-feature" "-outline-atomics"
8+
9+
// RUN: %clang -target riscv64 -moutline-atomics -S %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-OUTLINE-ATOMICS-RISCV
10+
// CHECK-OUTLINE-ATOMICS-RISCV: warning: 'riscv64' does not support '-moutline-atomics'; flag ignored [-Woption-ignored]
11+
// CHECK-OUTLINE-ATOMICS-RISCV-NOT: "-target-feature" "+outline-atomics"
12+
13+
// RUN: %clang -target riscv64 -mno-outline-atomics -S %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-NO-OUTLINE-ATOMICS-RISCV
14+
// CHECK-NO-OUTLINE-ATOMICS-RISCV: warning: 'riscv64' does not support '-mno-outline-atomics'; flag ignored [-Woption-ignored]
15+
// CHECK-NO-OUTLINE-ATOMICS-RISCV-NOT: "-target-feature" "-outline-atomics"

0 commit comments

Comments
 (0)