From 63d2e2bb4836ca46b4d48958c253263ec624a638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Fri, 26 Jul 2024 09:40:42 +0200 Subject: [PATCH] [clang][Driver] Support passing arbitrary args to -cc1as with -Xclangas. Closes #97517. --- clang/docs/UsersManual.rst | 1 + clang/include/clang/Driver/Options.td | 8 ++++++++ clang/lib/Driver/ToolChains/Clang.cpp | 6 ++++++ clang/test/Driver/Xclangas.s | 6 ++++++ 4 files changed, 21 insertions(+) create mode 100644 clang/test/Driver/Xclangas.s diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index e9b95739ea2ab5..7f55080321fea7 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -4876,6 +4876,7 @@ Execute ``clang-cl /?`` to see a list of supported options: -v Show commands to run and use verbose output -W Enable the specified warning -Xclang Pass to the clang compiler + -Xclangas Pass to the clang assembler The /clang: Option ^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 26811bf948ae5b..c7839c3941eb97 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1028,10 +1028,18 @@ def Xclang : Separate<["-"], "Xclang">, HelpText<"Pass to clang -cc1">, MetaVarName<"">, Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, Group; +def Xclangas : Separate<["-"], "Xclangas">, + HelpText<"Pass to clang -cc1as">, MetaVarName<"">, + Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, + Group; def : Joined<["-"], "Xclang=">, Group, Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, Alias, HelpText<"Alias for -Xclang">, MetaVarName<"">; +def : Joined<["-"], "Xclangas=">, Group, + Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, + Alias, + HelpText<"Alias for -Xclangas">, MetaVarName<"">; def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">, HelpText<"Pass to fatbinary invocation">, MetaVarName<"">; def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 4a94df7d5f42ee..90b8db11c46c65 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8711,6 +8711,12 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, CollectArgsForIntegratedAssembler(C, Args, CmdArgs, getToolChain().getDriver()); + // Forward -Xclangas arguments to -cc1as + for (auto Arg : Args.filtered(options::OPT_Xclangas)) { + Arg->claim(); + CmdArgs.push_back(Arg->getValue()); + } + Args.AddAllArgs(CmdArgs, options::OPT_mllvm); if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.isFilename()) diff --git a/clang/test/Driver/Xclangas.s b/clang/test/Driver/Xclangas.s new file mode 100644 index 00000000000000..c46391f29baa5c --- /dev/null +++ b/clang/test/Driver/Xclangas.s @@ -0,0 +1,6 @@ +// Check that -Xclangas passes args to -cc1as. +// RUN: %clang -### -Xclangas -target-feature -Xclangas +v5t %s 2>&1 | \ +// RUN: FileCheck -check-prefix=ARGS %s +// ARGS: -cc1as +// ARGS: -target-feature +// ARGS: +v5t