[cfe-commits] r68627 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td include/clang/Lex/Preprocessor.h lib/Lex/PPDirectives.cpp

Chris Lattner sabre at nondot.org
Wed Apr 8 11:46:40 PDT 2009


Author: lattner
Date: Wed Apr  8 13:46:40 2009
New Revision: 68627

URL: http://llvm.org/viewvc/llvm-project?rev=68627&view=rev
Log:
reject the #__include_macros directive unless it comes from the 
predefines buffer.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=68627&r1=68626&r2=68627&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Wed Apr  8 13:46:40 2009
@@ -85,6 +85,8 @@
 def pp_hash_warning : Warning<"#warning%0">;
 def pp_include_next_in_primary : Warning<
   "#include_next in primary source file">;
+def pp_include_macros_out_of_predefines : Error<
+  "the #__include_macros directive is only for internal use by -imacros">;
 def pp_include_next_absolute_path : Warning<"#include_next with absolute path">;
 def ext_c99_whitespace_required_after_macro_name : ExtWarn<
   "ISO C99 requires whitespace after the macro name">;

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=68627&r1=68626&r2=68627&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Apr  8 13:46:40 2009
@@ -748,6 +748,7 @@
                               const DirectoryLookup *LookupFrom = 0,
                               bool isImport = false);
   void HandleIncludeNextDirective(Token &Tok);
+  void HandleIncludeMacrosDirective(Token &Tok);
   void HandleImportDirective(Token &Tok);
   
   // Macro handling.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=68627&r1=68626&r2=68627&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Apr  8 13:46:40 2009
@@ -530,7 +530,7 @@
     case tok::pp_include:
       return HandleIncludeDirective(Result);       // Handle #include.
     case tok::pp___include_macros:
-      return HandleIncludeDirective(Result);       // Handle #__include_macros.
+      return HandleIncludeMacrosDirective(Result); // Handle -imacros.
         
     // C99 6.10.3 - Macro Replacement.
     case tok::pp_define:
@@ -1126,6 +1126,25 @@
   return HandleIncludeDirective(ImportTok, 0, true);
 }
 
+/// HandleIncludeMacrosDirective - The -imacros command line option turns into a
+/// pseudo directive in the predefines buffer.  This handles it by sucking all
+/// tokens through the preprocessor and discarding them (only keeping the side
+/// effects on the preprocessor).
+void Preprocessor::HandleIncludeMacrosDirective(Token &IncludeMacrosTok) {
+  // This directive should only occur in the predefines buffer.  If not, emit an
+  // error and reject it.
+  SourceLocation Loc = IncludeMacrosTok.getLocation();
+  if (strcmp(SourceMgr.getBufferName(Loc), "<built-in>") != 0) {
+    Diag(IncludeMacrosTok.getLocation(),
+         diag::pp_include_macros_out_of_predefines);
+    DiscardUntilEndOfDirective();
+    return;
+  }
+  
+  // TODO: implement me :)
+  DiscardUntilEndOfDirective();
+}
+
 //===----------------------------------------------------------------------===//
 // Preprocessor Macro Directive Handling.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list