Index: lib/Lex/PPLexerChange.cpp =================================================================== --- lib/Lex/PPLexerChange.cpp +++ lib/Lex/PPLexerChange.cpp @@ -378,6 +378,8 @@ Result.startToken(); CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof); CurLexer.reset(); + if (CurLexerKind == CLK_Lexer) + CurLexerKind = CLK_CachingLexer; } else { assert(CurPTHLexer && "Got EOF but no current lexer set!"); CurPTHLexer->getEOF(Result); Index: test/CodeCompletion/include-within-declaration.c =================================================================== --- /dev/null +++ test/CodeCompletion/include-within-declaration.c @@ -0,0 +1,11 @@ +// RUN: rm -rf %t && mkdir %t +// RUN: echo 'MACRO(here)' > %t/y.h +// Clang will generate an error in this case (though internally the correct completions +// are present -- this can be seen via libclang) but it should not crash. If it crashes +// then `not` will fail, otherwise the test succeeds. +// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%t/y.h:1:7 -I %t %s + +enum { +#define MACRO(a) FOO +#include "y.h" +};