Skip to content

Commit fe58eee

Browse files
authored
[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: #110325
1 parent 6e2f08b commit fe58eee

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/Driver/ToolChain.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,8 @@ void ToolChain::TranslateXarchArgs(
16511651
const InputArgList &BaseArgs = Args.getBaseArgs();
16521652
unsigned Index = BaseArgs.MakeIndex(A->getValue(ValuePos));
16531653
unsigned Prev = Index;
1654-
std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(Args, Index));
1654+
std::unique_ptr<llvm::opt::Arg> XarchArg(Opts.ParseOneArg(
1655+
Args, Index, llvm::opt::Visibility(clang::driver::options::ClangOption)));
16551656

16561657
// If the argument parsing failed or more than one argument was
16571658
// consumed, the -Xarch_ argument's parameter tried to consume

clang/test/Driver/Xarch.c

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818

1919
// RUN: %clang -target x86_64-unknown-linux-gnu -Xarch_x86_64 -Wl,foo %s -### 2>&1 | FileCheck -check-prefix=LINKER %s
2020
// LINKER: "foo"
21+
22+
// RUN: %clang -target x86_64-unknown-linux-gnu -Xarch_x86_64 -O1 %s -S -### 2>&1 | FileCheck -check-prefix=O1ONCE %s
23+
// O1ONCE: "-O1"
24+
// O1ONCE-NOT: "-O1"

0 commit comments

Comments
 (0)