Skip to content

Commit

Permalink
[Driver,X86] Ignore -mfpmath= for assembler input
Browse files Browse the repository at this point in the history
Some options are only claimed in AddX86TargetArgs/etc (called by
Clang::RenderTargetOptions).
For assembler input, `Add*TargetArgs` is not called. If an option is
unclaimed, it either leads to a -Wunused-command-line-argument warning
or an error (if `TargetSpecific` is set)
```
// clang '-###' --target=x86_64 -mfpmath=sse -c a.s
clang: error: unsupported option '-mfpmath=sse' for target 'x86_64'
```

For -mfpmath=, it's actually claimed by RenderFloatingPointOptions,
which should be moved to AddARMTargetArgs/AddX86TargetArgs later
(non-AArch32-non-x86 targets give a frontend error).
This change is localized and similar to D153691, for release/17.x
backporting.

Fix llvm#65023

Reviewed By: thesamesam

Differential Revision: https://reviews.llvm.org/D159010

(cherry picked from commit 081afa3)
  • Loading branch information
MaskRay authored and tru committed Aug 29, 2023
1 parent 0638df0 commit ed108ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion clang/lib/Driver/ToolChains/Arch/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args,

void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector<StringRef> &Features) {
std::vector<StringRef> &Features, bool ForAS) {
if (ForAS) {
// Some target-specific options are only handled in AddX86TargetArgs, which
// is not called by ClangAs::ConstructJob. Claim them here.
Args.claimAllArgs(options::OPT_mfpmath_EQ);
}

// Claim and report unsupported -mabi=. Note: we don't support "sysv_abi" or
// "ms_abi" as default function attributes.
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mabi_EQ)) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Arch/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::string getX86TargetCPU(const Driver &D, const llvm::opt::ArgList &Args,

void getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args,
std::vector<llvm::StringRef> &Features);
std::vector<llvm::StringRef> &Features, bool ForAS);

} // end namespace x86
} // end namespace target
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
break;
case llvm::Triple::x86:
case llvm::Triple::x86_64:
x86::getX86TargetFeatures(D, Triple, Args, Features);
x86::getX86TargetFeatures(D, Triple, Args, Features, ForAS);
break;
case llvm::Triple::hexagon:
hexagon::getHexagonTargetFeatures(D, Triple, Args, Features);
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/x86-mfpmath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %clang -### -c --target=x86_64 -mfpmath=sse %s 2>&1 | FileCheck %s
// CHECK: "-mfpmath" "sse"

/// Don't warn for assembler input.
// RUN: %clang -### -Werror -c --target=x86_64 -mfpmath=sse -x assembler %s 2>&1 | FileCheck /dev/null --implicit-check-not='"-mfpmath"'

0 comments on commit ed108ee

Please sign in to comment.