Skip to content

[Clang] Only allow clang arguments to -Xarch #126101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Feb 6, 2025

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

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Feb 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/126101.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChain.cpp (+2-1)
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

@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/126101.diff

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChain.cpp (+2-1)
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

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: llvm#110325
@jhuber6 jhuber6 merged commit fe58eee into llvm:main Feb 6, 2025
8 checks passed
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
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: llvm#110325
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-Xarch_device fails to propagate -O1
3 participants