summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Rice <michael.p.rice@intel.com>2019-04-29 21:21:17 +0000
committerMike Rice <michael.p.rice@intel.com>2019-04-29 21:21:17 +0000
commit8e6b618dacf4ea1f54007bb2aecdedac400d323d (patch)
tree57e1f32950aa5a595244f584e680f3d1ccf2b060
parent49c79db1f9b52237211136e3aa190a9a36b30d40 (diff)
When skipping code at the start of a file during PCH use, Preprocessor::Lex
is not used since it consumes all preprocessor directives until it returns a real token. Using the specific Lexer (i.e. CurLexer->Lex) makes it possible to stop skipping after an #include or #pragma hdrstop. Previously the skipping code was only handling CurLexer, now all will be handled correctly. Fixes: llvm.org/PR41585 Differential Revision: https://reviews.llvm.org/D61217 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359506 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Lex/Preprocessor.cpp19
-rw-r--r--test/PCH/Inputs/pch-through-macro.h3
-rw-r--r--test/PCH/pch-through4.cpp12
-rw-r--r--test/PCH/pch-through4a.cpp16
4 files changed, 48 insertions, 2 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index ebd4ae07ba..e16c8ac1f3 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -625,8 +625,23 @@ void Preprocessor::SkipTokensWhileUsingPCH() {
bool UsingPragmaHdrStop = SkippingUntilPragmaHdrStop;
Token Tok;
while (true) {
- bool InPredefines = (CurLexer->getFileID() == getPredefinesFileID());
- CurLexer->Lex(Tok);
+ bool InPredefines =
+ (CurLexer && CurLexer->getFileID() == getPredefinesFileID());
+ switch (CurLexerKind) {
+ case CLK_Lexer:
+ CurLexer->Lex(Tok);
+ break;
+ case CLK_TokenLexer:
+ CurTokenLexer->Lex(Tok);
+ break;
+ case CLK_CachingLexer:
+ bool IsNewToken;
+ CachingLex(Tok, IsNewToken);
+ break;
+ case CLK_LexAfterModuleImport:
+ LexAfterModuleImport(Tok);
+ break;
+ }
if (Tok.is(tok::eof) && !InPredefines) {
ReachedMainFileEOF = true;
break;
diff --git a/test/PCH/Inputs/pch-through-macro.h b/test/PCH/Inputs/pch-through-macro.h
new file mode 100644
index 0000000000..bb33c32ede
--- /dev/null
+++ b/test/PCH/Inputs/pch-through-macro.h
@@ -0,0 +1,3 @@
+#pragma once
+#define Source(x,y)
+#define InOut(size) Source(InOut, (size))
diff --git a/test/PCH/pch-through4.cpp b/test/PCH/pch-through4.cpp
new file mode 100644
index 0000000000..bdd50a9acb
--- /dev/null
+++ b/test/PCH/pch-through4.cpp
@@ -0,0 +1,12 @@
+// expected-no-diagnostics
+// Create PCH with #pragma hdrstop processing.
+// RUN: %clang_cc1 -verify -I %S -emit-pch -pch-through-hdrstop-create \
+// RUN: -fms-extensions -o %t.pch -x c++-header %s
+
+// Create the PCH object
+// RUN: %clang_cc1 -verify -I %S -emit-obj -include-pch %t.pch \
+// RUN: -pch-through-hdrstop-create -fms-extensions -o %t.obj -x c++ %s
+
+#pragma once
+#include "Inputs/pch-through-macro.h"
+void f(InOut(a) char *b, unsigned long a);
diff --git a/test/PCH/pch-through4a.cpp b/test/PCH/pch-through4a.cpp
new file mode 100644
index 0000000000..c13edf5382
--- /dev/null
+++ b/test/PCH/pch-through4a.cpp
@@ -0,0 +1,16 @@
+// expected-no-diagnostics
+// Create PCH with a through header.
+// RUN: %clang_cc1 -verify -I %S -emit-pch \
+// RUN: -pch-through-header=Inputs/pch-through1.h \
+// RUN: -fms-extensions -o %t.pch -x c++-header %s
+
+// Create the PCH object
+// RUN: %clang_cc1 -verify -I %S -emit-obj -include-pch %t.pch \
+// RUN: -pch-through-header=Inputs/pch-through1.h \
+// RUN: -fms-extensions -o %t.obj -x c++ %s
+
+#define Source(x,y)
+#define InOut(size) Source(InOut, (size))
+void f(InOut(a) char *b, unsigned long a);
+#include "Inputs/pch-through1.h"
+int other;