Ver código fonte

Fix invalid warnings for header guards in preambles

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
Erik Verbruggen 8 anos atrás
pai
commit
0fc70de55d

+ 4 - 5
include/clang/Lex/Preprocessor.h

@@ -1048,6 +1048,10 @@ public:
   /// which implicitly adds the builtin defines etc.
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
   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.
   /// \brief Inform the preprocessor callbacks that processing is complete.
   void EndSourceFile();
   void EndSourceFile();
 
 
@@ -1733,11 +1737,6 @@ public:
   /// \brief Return true if we're in the top-level file, not in a \#include.
   /// \brief Return true if we're in the top-level file, not in a \#include.
   bool isInPrimaryFile() const;
   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
   /// \brief Handle cases where the \#include name is expanded
   /// from a macro as multiple tokens, which need to be glued together. 
   /// from a macro as multiple tokens, which need to be glued together. 
   ///
   ///

+ 1 - 1
lib/Lex/Lexer.cpp

@@ -2550,7 +2550,7 @@ bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) {
     return true;
     return true;
   }
   }
   
   
-  if (PP->isRecordingPreamble() && !PP->isInMainFile()) {
+  if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
     PP->setRecordedPreambleConditionalStack(ConditionalStack);
     PP->setRecordedPreambleConditionalStack(ConditionalStack);
     ConditionalStack.clear();
     ConditionalStack.clear();
   }
   }

+ 0 - 6
lib/Lex/PPLexerChange.cpp

@@ -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
 /// getCurrentLexer - Return the current file lexer being lexed from.  Note
 /// that this ignores any potentially active macro expansions and _Pragma
 /// that this ignores any potentially active macro expansions and _Pragma
 /// expansions going on at the time.
 /// expansions going on at the time.

+ 2 - 0
lib/Lex/Preprocessor.cpp

@@ -535,7 +535,9 @@ void Preprocessor::EnterMainSourceFile() {
 
 
   // Start parsing the predefines.
   // Start parsing the predefines.
   EnterSourceFile(FID, nullptr, SourceLocation());
   EnterSourceFile(FID, nullptr, SourceLocation());
+}
 
 
+void Preprocessor::replayPreambleConditionalStack() {
   // Restore the conditional stack from the preamble, if there is one.
   // Restore the conditional stack from the preamble, if there is one.
   if (PreambleConditionalStack.isReplaying()) {
   if (PreambleConditionalStack.isReplaying()) {
     CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
     CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());

+ 2 - 0
lib/Parse/Parser.cpp

@@ -516,6 +516,8 @@ void Parser::Initialize() {
 
 
   // Prime the lexer look-ahead.
   // Prime the lexer look-ahead.
   ConsumeToken();
   ConsumeToken();
+
+  PP.replayPreambleConditionalStack();
 }
 }
 
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {
 void Parser::LateTemplateParserCleanupCallback(void *P) {