diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index ebd4ae07ba4c..e16c8ac1f34d 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/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/clang/test/PCH/Inputs/pch-through-macro.h b/clang/test/PCH/Inputs/pch-through-macro.h new file mode 100644 index 000000000000..bb33c32edeab --- /dev/null +++ b/clang/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/clang/test/PCH/pch-through4.cpp b/clang/test/PCH/pch-through4.cpp new file mode 100644 index 000000000000..bdd50a9acbdb --- /dev/null +++ b/clang/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/clang/test/PCH/pch-through4a.cpp b/clang/test/PCH/pch-through4a.cpp new file mode 100644 index 000000000000..c13edf53823f --- /dev/null +++ b/clang/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;