aboutsummaryrefslogtreecommitdiffstats
path: root/dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch')
-rw-r--r--dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch82
1 files changed, 82 insertions, 0 deletions
diff --git a/dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch b/dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch
new file mode 100644
index 00000000000..d7e17fc13ea
--- /dev/null
+++ b/dist/clang/patches/D34882_Fix-invalid-warnings-for-header-guards-in-preambles.patch
@@ -0,0 +1,82 @@
+diff --git a/tools/clang/include/clang/Lex/Preprocessor.h b/tools/clang/include/clang/Lex/Preprocessor.h
+index 3d1d9a86e0..0a02c977fc 100644
+--- a/tools/clang/include/clang/Lex/Preprocessor.h
++++ b/tools/clang/include/clang/Lex/Preprocessor.h
+@@ -1034,6 +1034,8 @@ public:
+ /// which implicitly adds the builtin defines etc.
+ void EnterMainSourceFile();
+
++ void replayPreambleConditionalStack();
++
+ /// \brief Inform the preprocessor callbacks that processing is complete.
+ void EndSourceFile();
+
+@@ -1700,11 +1702,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.
+ ///
+diff --git a/tools/clang/lib/Lex/Lexer.cpp b/tools/clang/lib/Lex/Lexer.cpp
+index 72f7011d4f..5953412608 100644
+--- a/tools/clang/lib/Lex/Lexer.cpp
++++ b/tools/clang/lib/Lex/Lexer.cpp
+@@ -2506,7 +2506,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();
+ }
+diff --git a/tools/clang/lib/Lex/PPLexerChange.cpp b/tools/clang/lib/Lex/PPLexerChange.cpp
+index 849a703671..e2eceafd98 100644
+--- a/tools/clang/lib/Lex/PPLexerChange.cpp
++++ b/tools/clang/lib/Lex/PPLexerChange.cpp
+@@ -46,12 +46,6 @@ bool Preprocessor::isInPrimaryFile() const {
+ return true;
+ }
+
+-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.
+diff --git a/tools/clang/lib/Lex/Preprocessor.cpp b/tools/clang/lib/Lex/Preprocessor.cpp
+index 1da60961a8..bb67b9c77a 100644
+--- a/tools/clang/lib/Lex/Preprocessor.cpp
++++ b/tools/clang/lib/Lex/Preprocessor.cpp
+@@ -531,7 +531,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());
+diff --git a/tools/clang/lib/Parse/Parser.cpp b/tools/clang/lib/Parse/Parser.cpp
+index f968f995d5..45662e7866 100644
+--- a/tools/clang/lib/Parse/Parser.cpp
++++ b/tools/clang/lib/Parse/Parser.cpp
+@@ -528,6 +528,8 @@ void Parser::Initialize() {
+
+ // Prime the lexer look-ahead.
+ ConsumeToken();
++
++ PP.replayPreambleConditionalStack();
+ }
+
+ void Parser::LateTemplateParserCleanupCallback(void *P) {