Skip to content

Commit

Permalink
Fix invalid warnings for header guards in preambles
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv committed Jul 5, 2017
1 parent d93a35a commit 795eee9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions clang/include/clang/Lex/Preprocessor.h
Expand Up @@ -1048,6 +1048,10 @@ class Preprocessor {
/// 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();

Expand Down Expand Up @@ -1733,11 +1737,6 @@ class Preprocessor {
/// \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.
///
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/Lexer.cpp
Expand Up @@ -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();
}
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Lex/PPLexerChange.cpp
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Lex/Preprocessor.cpp
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Parse/Parser.cpp
Expand Up @@ -516,6 +516,8 @@ void Parser::Initialize() {

// Prime the lexer look-ahead.
ConsumeToken();

PP.replayPreambleConditionalStack();
}

void Parser::LateTemplateParserCleanupCallback(void *P) {
Expand Down

0 comments on commit 795eee9

Please sign in to comment.