r307134 - Fix invalid warnings for header guards in preambles
Erik Verbruggen via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 5 02:44:08 PDT 2017
Author: erikjv
Date: Wed Jul 5 02:44:07 2017
New Revision: 307134
URL: http://llvm.org/viewvc/llvm-project?rev=307134&view=rev
Log:
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
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=307134&r1=307133&r2=307134&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 5 02:44:07 2017
@@ -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.
///
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=307134&r1=307133&r2=307134&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Jul 5 02:44:07 2017
@@ -2550,7 +2550,7 @@ bool Lexer::LexEndOfFile(Token &Result,
return true;
}
- if (PP->isRecordingPreamble() && !PP->isInMainFile()) {
+ if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
PP->setRecordedPreambleConditionalStack(ConditionalStack);
ConditionalStack.clear();
}
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=307134&r1=307133&r2=307134&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Jul 5 02:44:07 2017
@@ -46,12 +46,6 @@ bool Preprocessor::isInPrimaryFile() con
});
}
-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.
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=307134&r1=307133&r2=307134&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Jul 5 02:44:07 2017
@@ -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());
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=307134&r1=307133&r2=307134&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Jul 5 02:44:07 2017
@@ -516,6 +516,8 @@ void Parser::Initialize() {
// Prime the lexer look-ahead.
ConsumeToken();
+
+ PP.replayPreambleConditionalStack();
}
void Parser::LateTemplateParserCleanupCallback(void *P) {
More information about the cfe-commits
mailing list