[PATCH] D159010: [Driver,X86] Ignore -mfpmath= for assembler input
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 28 12:11:47 PDT 2023
MaskRay created this revision.
MaskRay added reviewers: mgorny, thesamesam.
Herald added subscribers: pengfei, kristof.beyls.
Herald added a reviewer: ctetreau.
Herald added a reviewer: ctetreau.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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 <https://reviews.llvm.org/D153691>, for release/17.x
backporting.
Fix https://github.com/llvm/llvm-project/issues/65023
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159010
Files:
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/lib/Driver/ToolChains/Arch/X86.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/x86-mfpmath.c
Index: clang/test/Driver/x86-mfpmath.c
===================================================================
--- /dev/null
+++ clang/test/Driver/x86-mfpmath.c
@@ -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"'
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -528,7 +528,7 @@
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);
Index: clang/lib/Driver/ToolChains/Arch/X86.h
===================================================================
--- clang/lib/Driver/ToolChains/Arch/X86.h
+++ clang/lib/Driver/ToolChains/Arch/X86.h
@@ -26,7 +26,7 @@
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
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -118,7 +118,13 @@
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)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159010.554010.patch
Type: text/x-patch
Size: 2472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230828/27641fbf/attachment.bin>
More information about the cfe-commits
mailing list