]> granicus.if.org Git - clang/commitdiff
Fix invalid warnings for header guards in preambles
authorErik Verbruggen <erikjv@me.com>
Wed, 5 Jul 2017 09:44:07 +0000 (09:44 +0000)
committerErik Verbruggen <erikjv@me.com>
Wed, 5 Jul 2017 09:44:07 +0000 (09:44 +0000)
Fixes https://bugs.llvm.org/show_bug.cgi?id=33574

Differential Revision: https://reviews.llvm.org/D34882

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

include/clang/Lex/Preprocessor.h
lib/Lex/Lexer.cpp
lib/Lex/PPLexerChange.cpp
lib/Lex/Preprocessor.cpp
lib/Parse/Parser.cpp

index 712e1ab9fbf5fffd3386f2f52dd3b271e2b83c38..62090d6496ed5a452313d85f90632ac219aab77f 100644 (file)
@@ -1048,6 +1048,10 @@ public:
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
 
+  /// \brief After parser warm-up, initialize the conditional stack from
+  /// the preamble.
+  void replayPreambleConditionalStack();
+
   /// \brief Inform the preprocessor callbacks that processing is complete.
   void EndSourceFile();
 
@@ -1733,11 +1737,6 @@ public:
   /// \brief Return true if we're in the top-level file, not in a \#include.
   bool isInPrimaryFile() const;
 
-  /// \brief Return true if we're in the main file (specifically, if we are 0
-  /// (zero) levels deep \#include. This is used by the lexer to determine if
-  /// it needs to generate errors about unterminated \#if directives.
-  bool isInMainFile() const;
-
   /// \brief Handle cases where the \#include name is expanded
   /// from a macro as multiple tokens, which need to be glued together. 
   ///
index 012189aa6f9f9ffe091b5efed8888b94a029d2a4..61bcef8cb760e52c9be65b05f70b44700d432b56 100644 (file)
@@ -2550,7 +2550,7 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
     return true;
   }
   
-  if (PP->isRecordingPreamble() && !PP->isInMainFile()) {
+  if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
     PP->setRecordedPreambleConditionalStack(ConditionalStack);
     ConditionalStack.clear();
   }
index 1c0cd5636835e25edef00d475cfd7e7e58be64a7..5a589d6a17b3607d588c82e5f0c54fbd7e345c5e 100644 (file)
@@ -46,12 +46,6 @@ bool Preprocessor::isInPrimaryFile() const {
   });
 }
 
-bool Preprocessor::isInMainFile() const {
-  if (IsFileLexer())
-    return IncludeMacroStack.size() == 0;
-  return true;
-}
-
 /// getCurrentLexer - Return the current file lexer being lexed from.  Note
 /// that this ignores any potentially active macro expansions and _Pragma
 /// expansions going on at the time.
index f9a399cd7fd783b6b14c3cf824c8c73936c4d23b..63f39524d12a24c585c8108da98e6807cb147abb 100644 (file)
@@ -535,7 +535,9 @@ void Preprocessor::EnterMainSourceFile() {
 
   // Start parsing the predefines.
   EnterSourceFile(FID, nullptr, SourceLocation());
+}
 
+void Preprocessor::replayPreambleConditionalStack() {
   // Restore the conditional stack from the preamble, if there is one.
   if (PreambleConditionalStack.isReplaying()) {
     CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
index 1ed7ef9663589ed87ccc24dddf2e7b7f73739879..4aa9a5971929193d88b012d7dac0c504e704703a 100644 (file)
@@ -516,6 +516,8 @@ void Parser::Initialize() {
 
   // Prime the lexer look-ahead.
   ConsumeToken();
+
+  PP.replayPreambleConditionalStack();
 }
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {