[clang] fe58eee - [Clang] Only allow `clang` arguments to `-Xarch` (#126101)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 14:36:12 PST 2025
Author: Joseph Huber
Date: 2025-02-06T16:36:08-06:00
New Revision: fe58eee60200c91b5b4131e9dc73a5e870b3cf4d
URL: https://github.com/llvm/llvm-project/commit/fe58eee60200c91b5b4131e9dc73a5e870b3cf4d
DIFF: https://github.com/llvm/llvm-project/commit/fe58eee60200c91b5b4131e9dc73a5e870b3cf4d.diff
LOG: [Clang] Only allow `clang` arguments to `-Xarch` (#126101)
Summary:
Currently the `-Xarch` argument needs to re-parse the option, which goes
through every single registered argument. This causes errors when trying
to pass `-O1` through it because it thinks it's a DXC option. This patch
changes the behavior to only allow `clang` options. Concievably we could
detect the driver mode to make this more robust, but I don't know if
there are other users for this.
Fixes: https://github.com/llvm/llvm-project/issues/110325
Added:
Modified:
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/Xarch.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index c25d1b6be14b50..56bc500da66b9f 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1651,7 +1651,8 @@ void ToolChain::TranslateXarchArgs(
const InputArgList &BaseArgs = Args.getBaseArgs();
unsigned Index = BaseArgs.MakeIndex(A->getValue(ValuePos));
unsigned Prev = Index;
- std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
+ std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(
+ Args, Index, llvm::opt::Visibility(clang::driver::options::ClangOption)));
// If the argument parsing failed or more than one argument was
// consumed, the -Xarch_ argument's parameter tried to consume
diff --git a/clang/test/Driver/Xarch.c b/clang/test/Driver/Xarch.c
index f35e2926f9c8d5..95bd0c502ddb31 100644
--- a/clang/test/Driver/Xarch.c
+++ b/clang/test/Driver/Xarch.c
@@ -18,3 +18,7 @@
// RUN: %clang -target x86_64-unknown-linux-gnu -Xarch_x86_64 -Wl,foo %s -### 2>&1 | FileCheck -check-prefix=LINKER %s
// LINKER: "foo"
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -Xarch_x86_64 -O1 %s -S -### 2>&1 | FileCheck -check-prefix=O1ONCE %s
+// O1ONCE: "-O1"
+// O1ONCE-NOT: "-O1"
More information about the cfe-commits
mailing list