[PATCH] clang-cl: Add the /c, /W0 and /W1 options

Hans Wennborg hans at chromium.org
Tue Jul 30 16:39:38 PDT 2013


  I've uploaded a new version of the patch that just uses aliases and removes the translation code.

  I also realized adding the CLOption to -### was a bug, since that excludes it from the non-cl mode. I've made added the CoreOption flag instead.

  Please take another look.

Hi rnk,

http://llvm-reviews.chandlerc.com/D1232

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1232?vs=3061&id=3085#toc

Files:
  include/clang/Driver/CLCompatOptions.td
  include/clang/Driver/Options.h
  include/clang/Driver/Options.td
  lib/Driver/Driver.cpp
  test/Driver/cl-options.c

Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -12,10 +12,14 @@
 //===----------------------------------------------------------------------===//
 
 def cl_Group : OptionGroup<"<clang-cl options>">,
-    HelpText<"CL.EXE COMPATIBILITY OPTIONS">;
+  HelpText<"CL.EXE COMPATIBILITY OPTIONS">;
 
 class CLFlag<string name> : Option<["/", "-"], name, KIND_FLAG>,
-    Group<cl_Group>, Flags<[CLOption]>;
+  Group<cl_Group>, Flags<[CLOption, DriverOption]>;
 
 def _QUESTION : CLFlag<"?">, Alias<help>, HelpText<"Display available options">;
-def cl_help : CLFlag<"help">, Alias<help>, HelpText<"Display available options">;
+def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias<c>;
+def _SLASH_help : CLFlag<"help">, Alias<help>,
+  HelpText<"Display available options">;
+def _SLASH_W0 : CLFlag<"W0">, HelpText<"Disable all warnings">, Alias<w>;
+def _SLASH_W1 : CLFlag<"W1">, HelpText<"Enable -Wall">, Alias<Wall>;
Index: include/clang/Driver/Options.h
===================================================================
--- include/clang/Driver/Options.h
+++ include/clang/Driver/Options.h
@@ -27,9 +27,10 @@
   LinkerInput = (1 << 5),
   NoArgumentUnused = (1 << 6),
   Unsupported = (1 << 7),
-  CLOption = (1 << 8),
-  CC1Option = (1 << 9),
-  NoDriverOption = (1 << 10)
+  CoreOption = (1 << 8),
+  CLOption = (1 << 9),
+  CC1Option = (1 << 10),
+  NoDriverOption = (1 << 11)
 };
 
 enum ID {
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -33,6 +33,10 @@
 // lines that use it.
 def Unsupported : OptionFlag;
 
+// CoreOption - This is considered a "core" Clang option, available in both
+// clang and clang-cl modes.
+def CoreOption : OptionFlag;
+
 // CLOption - This is a cl.exe compatibility option. Options with this flag
 // are made available when the driver is running in CL compatibility mode.
 def CLOption : OptionFlag;
@@ -98,6 +102,7 @@
 // substitutions:
 //   _ => __
 //   - => _
+//   / => _SLASH
 //   # => _HASH
 //   ? => _QUESTION
 //   , => _COMMA
@@ -116,7 +121,8 @@
 
 class InternalDriverOpt : Group<internal_driver_Group>,
   Flags<[DriverOption, HelpHidden]>;
-def driver_mode : Joined<["--"], "driver-mode=">, InternalDriverOpt,
+def driver_mode : Joined<["--"], "driver-mode=">, Group<internal_driver_Group>,
+  Flags<[CoreOption, DriverOption, HelpHidden]>,
   HelpText<"Set the driver mode to either 'gcc', 'g++', 'cpp', or 'cl'">;
 def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, InternalDriverOpt,
   HelpText<"Name for native GCC compiler">,
@@ -171,7 +177,7 @@
 
 // Standard Options
 
-def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[DriverOption]>,
+def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[DriverOption, CoreOption]>,
     HelpText<"Print the commands to run for this compilation">;
 // The '--' option is here for the sake of compatibility with gcc, but is 
 // being ignored by the driver.
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1883,9 +1883,9 @@
   unsigned ExcludedFlagsBitmask = 0;
 
   if (Mode == CLMode) {
-    // Only allow CL options.
-    // FIXME: Also allow "core" Clang options.
-    IncludedFlagsBitmask = options::CLOption;
+    // Include CL and Core options.
+    IncludedFlagsBitmask |= options::CLOption;
+    IncludedFlagsBitmask |= options::CoreOption;
   } else {
     ExcludedFlagsBitmask |= options::CLOption;
   }
Index: test/Driver/cl-options.c
===================================================================
--- /dev/null
+++ test/Driver/cl-options.c
@@ -0,0 +1,10 @@
+// Don't attempt slash switches on msys bash.
+// REQUIRES: shell-preserves-root
+
+// RUN: %clang_cl /c /W0 %s -### 2>&1 | FileCheck -check-prefix=W0 %s
+// W0-DAG: -c
+// W0-DAG: -w
+
+// RUN: %clang_cl /c /W1 %s -### 2>&1 | FileCheck -check-prefix=W1 %s
+// W1-DAG: -c
+// W1-DAG: -Wall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1232.2.patch
Type: text/x-patch
Size: 4161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130730/fdb04649/attachment.bin>


More information about the cfe-commits mailing list