]> granicus.if.org Git - clang/commitdiff
reject the #__include_macros directive unless it comes from the
authorChris Lattner <sabre@nondot.org>
Wed, 8 Apr 2009 18:46:40 +0000 (18:46 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 8 Apr 2009 18:46:40 +0000 (18:46 +0000)
predefines buffer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68627 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
include/clang/Lex/Preprocessor.h
lib/Lex/PPDirectives.cpp

index 74a1b5903a4ddee75ca74b985aac6ed11fdb5c29..adce63c48909043a721f81b7144462cbf74c0a57 100644 (file)
@@ -85,6 +85,8 @@ def warn_hex_escape_too_large : ExtWarn<"hex escape sequence out of range">;
 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">;
index 7e03d196c409f9759b6e578df896617ad441cb1c..0e16ef8287cf454f19dfe9135d45d15763e4c7d0 100644 (file)
@@ -748,6 +748,7 @@ private:
                               const DirectoryLookup *LookupFrom = 0,
                               bool isImport = false);
   void HandleIncludeNextDirective(Token &Tok);
+  void HandleIncludeMacrosDirective(Token &Tok);
   void HandleImportDirective(Token &Tok);
   
   // Macro handling.
index a60d9ba4e1ff97566a43b57292fb99ec346faf8a..034d484a934434042ffa8bfcf0213844abbc00e8 100644 (file)
@@ -530,7 +530,7 @@ TryAgain:
     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 @@ void Preprocessor::HandleImportDirective(Token &ImportTok) {
   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.
 //===----------------------------------------------------------------------===//