reject the #__include_macros directive unless it comes from the 
predefines buffer.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68627 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index a60d9ba..034d484 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -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.
 //===----------------------------------------------------------------------===//