[cfe-commits] r99417 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Driver/Options.td include/clang/Frontend/HeaderSearchOptions.h lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitHeaderSearch.cpp test/Driver/nostdincxx.cpp

Douglas Gregor dgregor at apple.com
Wed Mar 24 13:13:48 PDT 2010


Author: dgregor
Date: Wed Mar 24 15:13:48 2010
New Revision: 99417

URL: http://llvm.org/viewvc/llvm-project?rev=99417&view=rev
Log:
Implement support for -nostdc++. Fixes PR6446.

Added:
    cfe/trunk/test/Driver/nostdincxx.cpp
Modified:
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Mar 24 15:13:48 2010
@@ -407,6 +407,8 @@
 
 def nostdinc : Flag<"-nostdinc">,
   HelpText<"Disable standard #include directories">;
+def nostdincxx : Flag<"-nostdinc++">,
+  HelpText<"Disable standard #include directories for the C++ standard library">;
 def nobuiltininc : Flag<"-nobuiltininc">,
   HelpText<"Disable builtin #include directories">;
 def F : JoinedOrSeparate<"-F">, MetaVarName<"<directory>">,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Mar 24 15:13:48 2010
@@ -470,6 +470,7 @@
 def noseglinkedit : Flag<"-noseglinkedit">;
 def nostartfiles : Flag<"-nostartfiles">;
 def nostdinc : Flag<"-nostdinc">;
+def nostdincxx : Flag<"-nostdinc++">;
 def nostdlib : Flag<"-nostdlib">;
 def object : Flag<"-object">;
 def o : JoinedOrSeparate<"-o">, Flags<[DriverOption, RenderAsInput]>,

Modified: cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/HeaderSearchOptions.h Wed Mar 24 15:13:48 2010
@@ -71,13 +71,17 @@
   /// Include the system standard include search directories.
   unsigned UseStandardIncludes : 1;
 
+  /// Include the system standard C++ library include search directories.
+  unsigned UseStandardCXXIncludes : 1;
+
   /// Whether header search information should be output as for -v.
   unsigned Verbose : 1;
 
 public:
   HeaderSearchOptions(llvm::StringRef _Sysroot = "/")
     : Sysroot(_Sysroot), UseBuiltinIncludes(true),
-      UseStandardIncludes(true), Verbose(false) {}
+      UseStandardIncludes(true), UseStandardCXXIncludes(true),
+      Verbose(false) {}
 
   /// AddPath - Add the \arg Path path to the specified \arg Group list.
   void AddPath(llvm::StringRef Path, frontend::IncludeDirGroup Group,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Mar 24 15:13:48 2010
@@ -948,6 +948,7 @@
     CmdArgs.push_back("-g");
 
   Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
+  Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
   Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
 
   // Pass the path to compiler resource files.
@@ -1706,6 +1707,7 @@
   if (!Args.hasArg(options::OPT_Q))
     CmdArgs.push_back("-quiet");
   Args.AddAllArgs(CmdArgs, options::OPT_nostdinc);
+  Args.AddAllArgs(CmdArgs, options::OPT_nostdincxx);
   Args.AddLastArg(CmdArgs, options::OPT_v);
   Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F);
   Args.AddLastArg(CmdArgs, options::OPT_P);

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Mar 24 15:13:48 2010
@@ -436,6 +436,8 @@
   }
   if (!Opts.UseStandardIncludes)
     Res.push_back("-nostdinc");
+  if (!Opts.UseStandardCXXIncludes)
+    Res.push_back("-nostdinc++");
   if (Opts.Verbose)
     Res.push_back("-v");
 }
@@ -1014,6 +1016,7 @@
   Opts.Verbose = Args.hasArg(OPT_v);
   Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
   Opts.UseStandardIncludes = !Args.hasArg(OPT_nostdinc);
+  Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx);
   Opts.ResourceDir = getLastArgValue(Args, OPT_resource_dir);
 
   // Add -I... and -F... options in order.

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=99417&r1=99416&r2=99417&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Wed Mar 24 15:13:48 2010
@@ -82,7 +82,8 @@
   /// AddDefaultSystemIncludePaths - Adds the default system include paths so
   ///  that e.g. stdio.h is found.
   void AddDefaultSystemIncludePaths(const LangOptions &Lang,
-                                    const llvm::Triple &triple);
+                                    const llvm::Triple &triple,
+                                    bool UseStandardCXXIncludes);
 
   /// Realize - Merges all search path lists into one list and send it to
   /// HeaderSearch.
@@ -594,8 +595,9 @@
 }
 
 void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
-                                                    const llvm::Triple &triple) {
-  if (Lang.CPlusPlus)
+                                                    const llvm::Triple &triple,
+                                                  bool UseStandardCXXIncludes) {
+  if (Lang.CPlusPlus && UseStandardCXXIncludes)
     AddDefaultCPlusPlusIncludePaths(triple);
 
   AddDefaultCIncludePaths(triple);
@@ -765,7 +767,8 @@
   }
 
   if (HSOpts.UseStandardIncludes)
-    Init.AddDefaultSystemIncludePaths(Lang, Triple);
+    Init.AddDefaultSystemIncludePaths(Lang, Triple, 
+                                      HSOpts.UseStandardCXXIncludes);
 
   Init.Realize();
 }

Added: cfe/trunk/test/Driver/nostdincxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/nostdincxx.cpp?rev=99417&view=auto
==============================================================================
--- cfe/trunk/test/Driver/nostdincxx.cpp (added)
+++ cfe/trunk/test/Driver/nostdincxx.cpp Wed Mar 24 15:13:48 2010
@@ -0,0 +1,4 @@
+// RUN: %clangxx -nostdinc++ %s 2>&1 | FileCheck %s
+
+// CHECK: file not found
+#include <vector> 





More information about the cfe-commits mailing list