[Driver] Add -Xclang= as an alias for -Xclang
authorFangrui Song <i@maskray.me>
Tue, 9 Aug 2022 02:05:24 +0000 (19:05 -0700)
committerFangrui Song <i@maskray.me>
Tue, 9 Aug 2022 02:05:24 +0000 (19:05 -0700)
Driver options taking a value typically use `=` as the separator, instead of a
space. Unfortunately many older driver options do not stick with the rule, but I
find -Xclang used a lot and will be convenient if -Xclang= exists.

For build systems using a string array instead of a string to indicate compiler options,
`["-Xclang=-foo"]` is more convenient than `["-Xclang", "-foo"]`.
If a tool wants to filter out -Xclang=-foo, it is trivial for the `=` form, but
complex for the space separated form.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D131455

clang/include/clang/Driver/Options.td
clang/test/Driver/disable-llvm.c

index abd7410..8c9901d 100644 (file)
@@ -815,8 +815,10 @@ def Xassembler : Separate<["-"], "Xassembler">,
   HelpText<"Pass <arg> to the assembler">, MetaVarName<"<arg>">,
   Group<CompileOnly_Group>;
 def Xclang : Separate<["-"], "Xclang">,
-  HelpText<"Pass <arg> to the clang compiler">, MetaVarName<"<arg>">,
+  HelpText<"Pass <arg> to clang -cc1">, MetaVarName<"<arg>">,
   Flags<[NoXarchOption, CoreOption]>, Group<CompileOnly_Group>;
+def : Joined<["-"], "Xclang=">, Group<CompileOnly_Group>, Flags<[NoXarchOption, CoreOption]>, Alias<Xclang>,
+  HelpText<"Alias for -Xclang">, MetaVarName<"<arg>">;
 def Xcuda_fatbinary : Separate<["-"], "Xcuda-fatbinary">,
   HelpText<"Pass <arg> to fatbinary invocation">, MetaVarName<"<arg>">;
 def Xcuda_ptxas : Separate<["-"], "Xcuda-ptxas">,
index 3ac6b9e..531c315 100644 (file)
@@ -1,6 +1,10 @@
 // We support a CC1 option for disabling LLVM's passes.
 // RUN: %clang -O2 -Xclang -disable-llvm-passes -### %s 2>&1 \
 // RUN:     | FileCheck --check-prefix=DISABLED %s
+
+// Try -Xclang=.
+// RUN: %clang -O2 -Xclang=-disable-llvm-passes -### %s 2>&1 \
+// RUN:     | FileCheck --check-prefix=DISABLED %s
 // DISABLED: -cc1
 // DISABLED-NOT: "-mllvm" "-disable-llvm-passes"
 // DISABLED: "-disable-llvm-passes"