Skip to content

Commit 6311b11

Browse files
authored
[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.
1 parent 7b0409a commit 6311b11

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

clang/docs/UsersManual.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5146,6 +5146,7 @@ Execute ``clang-cl /?`` to see a list of supported options:
51465146
-v Show commands to run and use verbose output
51475147
-W<warning> Enable the specified warning
51485148
-Xclang <arg> Pass <arg> to the clang compiler
5149+
-Xclangas <arg> Pass <arg> to the clang assembler
51495150

51505151
The /clang: Option
51515152
^^^^^^^^^^^^^^^^^^

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,18 @@ def Xclang : Separate<["-"], "Xclang">,
958958
HelpText<"Pass <arg> to clang -cc1">, MetaVarName<"<arg>">,
959959
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
960960
Group<CompileOnly_Group>;
961+
def Xclangas : Separate<["-"], "Xclangas">,
962+
HelpText<"Pass <arg> to clang -cc1as">, MetaVarName<"<arg>">,
963+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
964+
Group<CompileOnly_Group>;
961965
def : Joined<["-"], "Xclang=">, Group<CompileOnly_Group>,
962966
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
963967
Alias<Xclang>,
964968
HelpText<"Alias for -Xclang">, MetaVarName<"<arg>">;
969+
def : Joined<["-"], "Xclangas=">, Group<CompileOnly_Group>,
970+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
971+
Alias<Xclangas>,
972+
HelpText<"Alias for -Xclangas">, MetaVarName<"<arg>">;
965973
def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
966974
HelpText<"Pass <arg> to fatbinary invocation">, MetaVarName<"<arg>">;
967975
def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8895,6 +8895,12 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
88958895
CollectArgsForIntegratedAssembler(C, Args, CmdArgs,
88968896
getToolChain().getDriver());
88978897

8898+
// Forward -Xclangas arguments to -cc1as
8899+
for (auto Arg : Args.filtered(options::OPT_Xclangas)) {
8900+
Arg->claim();
8901+
CmdArgs.push_back(Arg->getValue());
8902+
}
8903+
88988904
Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
88998905

89008906
if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.isFilename())

clang/test/Driver/Xclangas.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Check that -Xclangas/-Xclangas= are passed to -cc1as.
2+
// RUN: %clang -### -Werror -Xclangas -target-feature -Xclangas=+v5t %s 2>&1 | FileCheck %s
3+
// CHECK: -cc1as
4+
// CHECK-SAME: "-target-feature" "+v5t"

0 commit comments

Comments
 (0)