Author: Alex Rønne Petersen Date: 2025-04-19T04:09:58+02:00 New Revision: 6311b11595f152a8f4aa02cfa544e72ede66688a
URL: https://github.com/llvm/llvm-project/commit/6311b11595f152a8f4aa02cfa544e72ede66688a DIFF: https://github.com/llvm/llvm-project/commit/6311b11595f152a8f4aa02cfa544e72ede66688a.diff LOG: [clang][Driver] Support passing arbitrary args to `-cc1as` with `-Xclangas`. (#100714) Unlike the `-Xassembler` idea mentioned in #97517, this one comes with no GCC compatibility concerns, and simply mirrors what `-Xclang` does for `-cc1`. This is useful for mostly the same reasons that `-Xclang` is. The motivating use case is `zig cc`, however, where we use `-Xclang -target-feature` to pass the exhaustive list of target features to Clang for C-family files. Before this commit, there was no way to do the same for assembly files. For context, Zig bases all of its target feature info directly on the info in LLVM's backends, including all the dependency relationships therein. So it just makes more sense for Zig to be able to directly pass all this info to the assembler, rather than having to manually reconstruct the corresponding frontend command line flags for every target. Closes #97517. Added: clang/test/Driver/Xclangas.s Modified: clang/docs/UsersManual.rst clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp Removed: ################################################################################ diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index 69256527f40c9..6c2053e01da8b 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -5146,6 +5146,7 @@ Execute ``clang-cl /?`` to see a list of supported options: -v Show commands to run and use verbose output -W<warning> Enable the specified warning -Xclang <arg> Pass <arg> to the clang compiler + -Xclangas <arg> Pass <arg> to the clang assembler The /clang: Option ^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 830d3459a1320..919c1c643d080 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -958,10 +958,18 @@ def Xclang : Separate<["-"], "Xclang">, HelpText<"Pass <arg> to clang -cc1">, MetaVarName<"<arg>">, Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, Group<CompileOnly_Group>; +def Xclangas : Separate<["-"], "Xclangas">, + HelpText<"Pass <arg> to clang -cc1as">, MetaVarName<"<arg>">, + Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, + Group<CompileOnly_Group>; def : Joined<["-"], "Xclang=">, Group<CompileOnly_Group>, Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, Alias<Xclang>, HelpText<"Alias for -Xclang">, MetaVarName<"<arg>">; +def : Joined<["-"], "Xclangas=">, Group<CompileOnly_Group>, + Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>, + Alias<Xclangas>, + HelpText<"Alias for -Xclangas">, MetaVarName<"<arg>">; def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">, HelpText<"Pass <arg> to fatbinary invocation">, MetaVarName<"<arg>">; def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 67a800a643cbe..f2f5231933c88 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8895,6 +8895,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 0000000000000..0d3911170eee1 --- /dev/null +++ b/clang/test/Driver/Xclangas.s @@ -0,0 +1,4 @@ +/// Check that -Xclangas/-Xclangas= are passed to -cc1as. +// RUN: %clang -### -Werror -Xclangas -target-feature -Xclangas=+v5t %s 2>&1 | FileCheck %s +// CHECK: -cc1as +// CHECK-SAME: "-target-feature" "+v5t" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits