[clang] 8d9d27d - [Driver] Add -Xclang= as an alias for -Xclang

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 8 19:05:28 PDT 2022


Author: Fangrui Song
Date: 2022-08-08T19:05:24-07:00
New Revision: 8d9d27db475943954fce00db47f8c9daf4dae600

URL: https://github.com/llvm/llvm-project/commit/8d9d27db475943954fce00db47f8c9daf4dae600
DIFF: https://github.com/llvm/llvm-project/commit/8d9d27db475943954fce00db47f8c9daf4dae600.diff

LOG: [Driver] Add -Xclang= as an alias for -Xclang

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index abd74103f61c3..8c9901d086eee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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">,

diff  --git a/clang/test/Driver/disable-llvm.c b/clang/test/Driver/disable-llvm.c
index 3ac6b9e919376..531c3159cd743 100644
--- a/clang/test/Driver/disable-llvm.c
+++ b/clang/test/Driver/disable-llvm.c
@@ -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"


        


More information about the cfe-commits mailing list