r359506 - When skipping code at the start of a file during PCH use, Preprocessor::Lex
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 14:21:18 PDT 2019
Author: mikerice
Date: Mon Apr 29 14:21:17 2019
New Revision: 359506
URL: http://llvm.org/viewvc/llvm-project?rev=359506&view=rev
Log:
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
Added:
cfe/trunk/test/PCH/Inputs/pch-through-macro.h (with props)
cfe/trunk/test/PCH/pch-through4.cpp (with props)
cfe/trunk/test/PCH/pch-through4a.cpp (with props)
Modified:
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=359506&r1=359505&r2=359506&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Apr 29 14:21:17 2019
@@ -625,8 +625,23 @@ void Preprocessor::SkipTokensWhileUsingP
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;
Added: cfe/trunk/test/PCH/Inputs/pch-through-macro.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-macro.h?rev=359506&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/pch-through-macro.h (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-macro.h Mon Apr 29 14:21:17 2019
@@ -0,0 +1,3 @@
+#pragma once
+#define Source(x,y)
+#define InOut(size) Source(InOut, (size))
Propchange: cfe/trunk/test/PCH/Inputs/pch-through-macro.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/PCH/Inputs/pch-through-macro.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/PCH/Inputs/pch-through-macro.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/PCH/pch-through4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pch-through4.cpp?rev=359506&view=auto
==============================================================================
--- cfe/trunk/test/PCH/pch-through4.cpp (added)
+++ cfe/trunk/test/PCH/pch-through4.cpp Mon Apr 29 14:21:17 2019
@@ -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);
Propchange: cfe/trunk/test/PCH/pch-through4.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/PCH/pch-through4.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/PCH/pch-through4.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cfe/trunk/test/PCH/pch-through4a.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/pch-through4a.cpp?rev=359506&view=auto
==============================================================================
--- cfe/trunk/test/PCH/pch-through4a.cpp (added)
+++ cfe/trunk/test/PCH/pch-through4a.cpp Mon Apr 29 14:21:17 2019
@@ -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;
Propchange: cfe/trunk/test/PCH/pch-through4a.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/PCH/pch-through4a.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/PCH/pch-through4a.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list