[PATCH] clang-cl: add support for /? and /help

Hans Wennborg hans at chromium.org
Thu Jul 25 19:22:57 PDT 2013


  While we figure out the best way to organize and opt-in stuff from the current set of clang options, I've uploaded the part of the patch that only deals with CL-compatibility flags, with Chandler's comments addressed.

  Do you think we can land this before moving on to deal with the rest?

Hi chandlerc, rnk,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1215?vs=2998&id=3017#toc

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

Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- /dev/null
+++ include/clang/Driver/CLCompatOptions.td
@@ -0,0 +1,21 @@
+//===--- CLCompatOptions.td - Options for clang-cl ------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the options accepted by clang-cl.
+//
+//===----------------------------------------------------------------------===//
+
+def cl_Group : OptionGroup<"<clang-cl options>">,
+    HelpText<"CL.EXE COMPATIBILITY OPTIONS">;
+
+class CLFlag<string name> : Option<["/", "-"], name, KIND_FLAG>,
+    Group<cl_Group>, Flags<[CLOption]>;
+
+def _QUESTION : CLFlag<"?">, Alias<help>, HelpText<"Display available options">;
+def cl_help : CLFlag<"help">, Alias<help>, HelpText<"Display available options">;
Index: include/clang/Driver/Driver.h
===================================================================
--- include/clang/Driver/Driver.h
+++ include/clang/Driver/Driver.h
@@ -396,6 +396,11 @@
 
   /// @}
 
+
+  /// \brief Determine option flags to include/exclude based on driver mode.
+  void MakeIncludeExcludeFlags(unsigned &FlagsToInclude,
+                               unsigned &FlagsToExclude) const;
+
 public:
   /// GetReleaseVersion - Parse (([0-9]+)(.([0-9]+)(.([0-9]+)?))?)? and
   /// return the grouped values as integers. Numbers which are not
Index: include/clang/Driver/Makefile
===================================================================
--- include/clang/Driver/Makefile
+++ include/clang/Driver/Makefile
@@ -5,7 +5,7 @@
 
 include $(CLANG_LEVEL)/Makefile
 
-$(ObjDir)/Options.inc.tmp : Options.td CC1Options.td $(LLVM_TBLGEN) $(ObjDir)/.dir
+$(ObjDir)/Options.inc.tmp : Options.td CC1Options.td CLCompatOptions.td $(LLVM_TBLGEN) $(ObjDir)/.dir
 	$(Echo) "Building Clang Driver Option tables with tblgen"
 	$(Verb) $(LLVMTableGen) -gen-opt-parser-defs -o $(call SYSPATH, $@) $<
 
Index: include/clang/Driver/Options.h
===================================================================
--- include/clang/Driver/Options.h
+++ include/clang/Driver/Options.h
@@ -27,8 +27,9 @@
   LinkerInput = (1 << 5),
   NoArgumentUnused = (1 << 6),
   Unsupported = (1 << 7),
-  CC1Option = (1 << 8),
-  NoDriverOption = (1 << 9)
+  CLOption = (1 << 8),
+  CC1Option = (1 << 9),
+  NoDriverOption = (1 << 10)
 };
 
 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;
 
+// 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;
+
 // CC1Option - This option should be accepted by clang -cc1.
 def CC1Option : OptionFlag;
 
@@ -97,6 +101,7 @@
 //   _ => __
 //   - => _
 //   # => _HASH
+//   ? => _QUESTION
 //   , => _COMMA
 //   = => _EQ
 //   C++ => CXX
@@ -1314,4 +1319,6 @@
 def Z_reserved_lib_cckext : Flag<["-"], "Z-reserved-lib-cckext">,
     Flags<[LinkerInput, NoArgumentUnused, Unsupported]>, Group<reserved_lib_Group>;
 
+include "CLCompatOptions.td"
+
 include "CC1Options.td"
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -108,9 +108,15 @@
 
 InputArgList *Driver::ParseArgStrings(ArrayRef<const char *> ArgList) {
   llvm::PrettyStackTraceString CrashInfo("Command line argument parsing");
+
+  unsigned FlagsToInclude;
+  unsigned FlagsToExclude;
+  MakeIncludeExcludeFlags(FlagsToInclude, FlagsToExclude);
+
   unsigned MissingArgIndex, MissingArgCount;
   InputArgList *Args = getOpts().ParseArgs(ArgList.begin(), ArgList.end(),
-                                           MissingArgIndex, MissingArgCount);
+                                           MissingArgIndex, MissingArgCount,
+                                           FlagsToInclude, FlagsToExclude);
 
   // Check for missing argument error.
   if (MissingArgCount)
@@ -607,9 +613,17 @@
 }
 
 void Driver::PrintHelp(bool ShowHidden) const {
-  getOpts().PrintHelp(
-      llvm::outs(), Name.c_str(), DriverTitle.c_str(), /*Include*/ 0,
-      /*Exclude*/ options::NoDriverOption | (ShowHidden ? 0 : HelpHidden));
+  unsigned FlagsToInclude;
+  unsigned FlagsToExclude;
+  MakeIncludeExcludeFlags(FlagsToInclude, FlagsToExclude);
+
+  FlagsToExclude |= options::NoDriverOption;
+
+  if (!ShowHidden)
+    FlagsToExclude |= HelpHidden;
+
+  getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
+                      FlagsToInclude, FlagsToExclude);
 }
 
 void Driver::PrintVersion(const Compilation &C, raw_ostream &OS) const {
@@ -1848,3 +1862,17 @@
   HadExtra = true;
   return true;
 }
+
+void Driver::MakeIncludeExcludeFlags(unsigned &FlagsToInclude,
+                                     unsigned &FlagsToExclude) const {
+  FlagsToInclude = 0;
+  FlagsToExclude = 0;
+
+  if (Mode == CLMode) {
+    // Only allow CL options.
+    // FIXME: Also allow "core" Clang options.
+    FlagsToInclude = options::CLOption;
+  } else {
+    FlagsToExclude |= options::CLOption;
+  }
+}
Index: test/Driver/cl.c
===================================================================
--- test/Driver/cl.c
+++ test/Driver/cl.c
@@ -1,3 +1,21 @@
-// RUN: %clang_cl -fsyntax-only -c %s
+// Check that clang-cl options are not available by default.
+// RUN: %clang -help | FileCheck %s -check-prefix=DEFAULT
+// DEFAULT-NOT: CL.EXE COMPATIBILITY OPTIONS
+// DEFAULT-NOT: {{/[?]}}
+// DEFAULT-NOT: /help
+// RUN: not %clang /?
+// RUN: not %clang -?
+// RUN: not %clang /help
 
-void f();
+// Check that /? and /help are available as clang-cl options.
+// RUN: %clang_cl /? | FileCheck %s -check-prefix=CL
+// RUN: %clang_cl /help | FileCheck %s -check-prefix=CL
+// RUN: %clang_cl -help | FileCheck %s -check-prefix=CL
+// CL: CL.EXE COMPATIBILITY OPTIONS
+// CL: {{/[?]}}
+// CL: /help
+
+// Options which are not "core" clang options nor cl.exe compatible options
+// are not available in clang-cl.
+// DEFAULT: -fapple-kext
+// CL-NOT: -fapple-kext
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1215.2.patch
Type: text/x-patch
Size: 6450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130725/f3309495/attachment.bin>


More information about the cfe-commits mailing list