diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-11 21:18:22 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-04-11 21:18:22 +0000 |
commit | 75f9681874252ac96db002a80df4202ec2cdd2f8 (patch) | |
tree | f5f585fac34b89251395afacd92b5f94bd338f71 /clang/lib/Lex/Preprocessor.cpp | |
parent | 6ffa1511eaedfae67ea4c66c2264b46eaccbbd7d (diff) | |
download | bcm5719-llvm-75f9681874252ac96db002a80df4202ec2cdd2f8.tar.gz bcm5719-llvm-75f9681874252ac96db002a80df4202ec2cdd2f8.zip |
Remove use of lookahead from _Pragma handling and from all other
internal lexing steps in the preprocessor.
It is not safe to use the preprocessor's token lookahead except when
operating on the final sequence of tokens that would be produced by
phase 4 of translation. Doing so corrupts the token lookahead cache used
by the parser. (See added testcase for an example.) Lookahead should
instead be viewed as a layer on top of the normal lexer.
Added assertions to catch any further incorrect uses of lookahead within
lexing actions.
llvm-svn: 358230
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index ff040a28d4b..d1c02c942da 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -862,6 +862,8 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) { } void Preprocessor::Lex(Token &Result) { + ++LexLevel; + // We loop here until a lex function returns a token; this avoids recursion. bool ReturnedToken; do { @@ -893,6 +895,7 @@ void Preprocessor::Lex(Token &Result) { } LastTokenWasAt = Result.is(tok::at); + --LexLevel; } /// Lex a header-name token (including one formed from header-name-tokens if |