Skip to content

Commit ed108ee

Browse files
MaskRaytru
authored andcommitted
[Driver,X86] Ignore -mfpmath= for assembler input
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 #65023 Reviewed By: thesamesam Differential Revision: https://reviews.llvm.org/D159010 (cherry picked from commit 081afa3)
1 parent 0638df0 commit ed108ee

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args,
118118

119119
void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
120120
const ArgList &Args,
121-
std::vector<StringRef> &Features) {
121+
std::vector<StringRef> &Features, bool ForAS) {
122+
if (ForAS) {
123+
// Some target-specific options are only handled in AddX86TargetArgs, which
124+
// is not called by ClangAs::ConstructJob. Claim them here.
125+
Args.claimAllArgs(options::OPT_mfpmath_EQ);
126+
}
127+
122128
// Claim and report unsupported -mabi=. Note: we don't support "sysv_abi" or
123129
// "ms_abi" as default function attributes.
124130
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_mabi_EQ)) {

clang/lib/Driver/ToolChains/Arch/X86.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::string getX86TargetCPU(const Driver &D, const llvm::opt::ArgList &Args,
2626

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

3131
} // end namespace x86
3232
} // end namespace target

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
528528
break;
529529
case llvm::Triple::x86:
530530
case llvm::Triple::x86_64:
531-
x86::getX86TargetFeatures(D, Triple, Args, Features);
531+
x86::getX86TargetFeatures(D, Triple, Args, Features, ForAS);
532532
break;
533533
case llvm::Triple::hexagon:
534534
hexagon::getHexagonTargetFeatures(D, Triple, Args, Features);

clang/test/Driver/x86-mfpmath.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang -### -c --target=x86_64 -mfpmath=sse %s 2>&1 | FileCheck %s
2+
// CHECK: "-mfpmath" "sse"
3+
4+
/// Don't warn for assembler input.
5+
// RUN: %clang -### -Werror -c --target=x86_64 -mfpmath=sse -x assembler %s 2>&1 | FileCheck /dev/null --implicit-check-not='"-mfpmath"'

0 commit comments

Comments
 (0)