Skip to content

[Driver,CodeGen] Report error when enabling 64-bit-only features on non-64-bit arch #101151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions clang/lib/Driver/ToolChains/Arch/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,29 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
}

bool IsNegative = Name.starts_with("no-");

bool Not64Bit = ArchType != llvm::Triple::x86_64;
if (Not64Bit && Name == "uintr")
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getSpelling() << Triple.getTriple();

if (A->getOption().matches(options::OPT_mapx_features_EQ) ||
A->getOption().matches(options::OPT_mno_apx_features_EQ)) {

if (Not64Bit && !IsNegative)
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< StringRef(A->getSpelling().str() + "|-mapxf")
<< Triple.getTriple();

for (StringRef Value : A->getValues()) {
if (Value == "egpr" || Value == "push2pop2" || Value == "ppx" ||
Value == "ndd" || Value == "ccmp" || Value == "nf" ||
Value == "cf" || Value == "zu") {
Features.push_back(
Args.MakeArgString((IsNegative ? "-" : "+") + Value));
continue;
}
D.Diag(clang::diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Value;
if (Value != "egpr" && Value != "push2pop2" && Value != "ppx" &&
Value != "ndd" && Value != "ccmp" && Value != "nf" &&
Value != "cf" && Value != "zu")
D.Diag(clang::diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Value;

Features.push_back(
Args.MakeArgString((IsNegative ? "-" : "+") + Value));
}
continue;
}
Expand Down
13 changes: 11 additions & 2 deletions clang/test/Driver/x86-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@
// HRESET: "-target-feature" "+hreset"
// NO-HRESET: "-target-feature" "-hreset"

// RUN: %clang --target=i386 -march=i386 -muintr %s -### 2>&1 | FileCheck -check-prefix=UINTR %s
// RUN: %clang --target=i386 -march=i386 -mno-uintr %s -### 2>&1 | FileCheck -check-prefix=NO-UINTR %s
// RUN: %clang --target=x86_64 -muintr %s -### 2>&1 | FileCheck -check-prefix=UINTR %s
// RUN: %clang --target=x86_64 -mno-uintr %s -### 2>&1 | FileCheck -check-prefix=NO-UINTR %s
// UINTR: "-target-feature" "+uintr"
// NO-UINTR: "-target-feature" "-uintr"

Expand Down Expand Up @@ -409,6 +409,15 @@
// NONX86-NEXT: warning: argument unused during compilation: '-msse4.2' [-Wunused-command-line-argument]
// NONX86-NEXT: error: unsupported option '-mno-sgx' for target 'aarch64'

// RUN: not %clang -### --target=i386 -muintr %s 2>&1 | FileCheck --check-prefix=NON-UINTR %s
// RUN: %clang -### --target=i386 -mno-uintr %s 2>&1 > /dev/null
// RUN: not %clang -### --target=i386 -mapx-features=ndd %s 2>&1 | FileCheck --check-prefix=NON-APX %s
// RUN: not %clang -### --target=i386 -mapxf %s 2>&1 | FileCheck --check-prefix=NON-APX %s
// RUN: %clang -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
// NON-UINTR: error: unsupported option '-muintr' for target 'i386'
// NON-APX: error: unsupported option '-mapx-features=|-mapxf' for target 'i386'
// NON-APX-NOT: error: {{.*}} -mapx-features=

// RUN: %clang --target=i386 -march=i386 -mharden-sls=return %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-RET,NO-SLS %s
// RUN: %clang --target=i386 -march=i386 -mharden-sls=indirect-jmp %s -### -o %t.o 2>&1 | FileCheck -check-prefixes=SLS-IJMP,NO-SLS %s
// 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
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/X86/X86Subtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
FullFS += ",+evex512";
}

// Disable 64-bit only features in non-64-bit mode.
SmallVector<StringRef, 9> FeaturesIn64BitOnly = {
"egpr", "push2pop2", "ppx", "ndd", "ccmp", "nf", "cf", "zu", "uintr"};
if (FullFS.find("-64bit-mode") != std::string::npos)
llvm::for_each(FeaturesIn64BitOnly,
[&](StringRef F) { FullFS += ",-" + F.str(); });

// Parse features string and set the CPU.
ParseSubtargetFeatures(CPU, TuneCPU, FullFS);

Expand Down
15 changes: 15 additions & 0 deletions llvm/test/CodeGen/X86/apx/i386-ndd.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=i386-linux-gnu -mattr=+cmov,+ndd < %s | FileCheck %s
define i32 @test(i1 %cmp, i32 %x, i32 %y) nounwind {
; CHECK-LABEL: test:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: testb $1, {{[0-9]+}}(%esp)
; CHECK-NEXT: leal {{[0-9]+}}(%esp), %eax
; CHECK-NEXT: leal {{[0-9]+}}(%esp), %ecx
; CHECK-NEXT: cmovnel %eax, %ecx
; CHECK-NEXT: movl (%ecx), %eax
; CHECK-NEXT: retl
entry:
%cmov = select i1 %cmp, i32 %x, i32 %y
ret i32 %cmov
}
Loading