Skip to content

Commit 5fd5f80

Browse files
committed
[Driver] Mark m_x86_Features_Group options as TargetSpecific
so that they lead to an error when compiled for non-x86 targets. Follow-up to D151590. ``` % aarch64-linux-gnu-gcc -c -mavx a.c aarch64-linux-gnu-gcc: error: unrecognized command-line option ‘-mavx’ % clang --target=aarch64-unknown-linux-gnu -c -mavx a.c # without this patch clang: warning: argument unused during compilation: '-mavx' [-Wunused-command-line-argument] ... % clang --target=aarch64-unknown-linux-gnu -c -mavx a.c # with this patch clang: error: unsupported option '-mavx' for target 'aarch64-unknown-linux-gnu' ``` As a workaround for llvm#63270, we don't report an error for -msse4.2. Reviewed By: pengfei, skan Differential Revision: https://reviews.llvm.org/D156962
1 parent fcf1a10 commit 5fd5f80

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,6 +4890,7 @@ foreach i = {0-7} in
48904890
} // let Flags = [TargetSpecific]
48914891

48924892
// X86 feature flags
4893+
let Flags = [TargetSpecific] in {
48934894
def mx87 : Flag<["-"], "mx87">, Group<m_x86_Features_Group>;
48944895
def mno_x87 : Flag<["-"], "mno-x87">, Group<m_x86_Features_Group>;
48954896
def m80387 : Flag<["-"], "m80387">, Alias<mx87>;
@@ -4923,7 +4924,11 @@ def mssse3 : Flag<["-"], "mssse3">, Group<m_x86_Features_Group>;
49234924
def mno_ssse3 : Flag<["-"], "mno-ssse3">, Group<m_x86_Features_Group>;
49244925
def msse4_1 : Flag<["-"], "msse4.1">, Group<m_x86_Features_Group>;
49254926
def mno_sse4_1 : Flag<["-"], "mno-sse4.1">, Group<m_x86_Features_Group>;
4927+
} // let Flags = [TargetSpecific]
4928+
// TODO: Make -msse4.2 TargetSpecific after
4929+
// https://github.com/llvm/llvm-project/issues/63270 is fixed.
49264930
def msse4_2 : Flag<["-"], "msse4.2">, Group<m_x86_Features_Group>;
4931+
let Flags = [TargetSpecific] in {
49274932
def mno_sse4_2 : Flag<["-"], "mno-sse4.2">, Group<m_x86_Features_Group>;
49284933
def msse4 : Flag<["-"], "msse4">, Alias<msse4_2>;
49294934
// -mno-sse4 turns off sse4.1 which has the effect of turning off everything
@@ -5104,6 +5109,7 @@ def mretpoline_external_thunk : Flag<["-"], "mretpoline-external-thunk">, Group<
51045109
def mno_retpoline_external_thunk : Flag<["-"], "mno-retpoline-external-thunk">, Group<m_x86_Features_Group>;
51055110
def mvzeroupper : Flag<["-"], "mvzeroupper">, Group<m_x86_Features_Group>;
51065111
def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, Group<m_x86_Features_Group>;
5112+
} // let Flags = [TargetSpecific]
51075113

51085114
// These are legacy user-facing driver-level option spellings. They are always
51095115
// aliases for options that are spelled using the more common Unix / GNU flag

clang/test/Driver/x86-target-features.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@
374374
// CRC32: "-target-feature" "+crc32"
375375
// NO-CRC32: "-target-feature" "-crc32"
376376

377+
// RUN: not %clang -### --target=aarch64 -mcrc32 -msse4.1 -msse4.2 -mno-sgx %s 2>&1 | FileCheck --check-prefix=NONX86 %s
378+
// NONX86: error: unsupported option '-mcrc32' for target 'aarch64'
379+
// NONX86-NEXT: error: unsupported option '-msse4.1' for target 'aarch64'
380+
/// TODO: This warning is a workaround for https://github.com/llvm/llvm-project/issues/63270
381+
// NONX86-NEXT: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
382+
// NONX86-NEXT: error: unsupported option '-mno-sgx' for target 'aarch64'
383+
377384
// RUN: %clang --target=i386 -march=i386 -mharden-sls=return %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-RET,NO-SLS %s
378385
// RUN: %clang --target=i386 -march=i386 -mharden-sls=indirect-jmp %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,NO-SLS %s
379386
// RUN: %clang --target=i386 -march=i386 -mharden-sls=none -mharden-sls=all %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,SLS-RET %s

0 commit comments

Comments
 (0)