diff options
| author | Dmitri Gribenko <gribozavr@gmail.com> | 2013-12-03 00:48:09 +0000 |
|---|---|---|
| committer | Dmitri Gribenko <gribozavr@gmail.com> | 2013-12-03 00:48:09 +0000 |
| commit | fc13b8baf10f1c26857ef8eea1386850daf82f44 (patch) | |
| tree | 86210147d59faf9136faa15655cf664fd8211459 /clang/lib/Parse/ParseStmt.cpp | |
| parent | be2513e143a23d5ac20a9c13fd70e0302299770a (diff) | |
| download | bcm5719-llvm-fc13b8baf10f1c26857ef8eea1386850daf82f44.tar.gz bcm5719-llvm-fc13b8baf10f1c26857ef8eea1386850daf82f44.zip | |
MS inline asm: When LLVM called back to Clang to parse a name and do name
lookup, if parsing failed, we did not restore the lexer state properly, and
eventually crashed. This change ensures that we always consume all the tokens
from the new token stream we started to parse the name from inline asm.
llvm-svn: 196182
Diffstat (limited to 'clang/lib/Parse/ParseStmt.cpp')
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 5f939fc354a..6cbb68e9ddc 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1920,30 +1920,33 @@ ExprResult Parser::ParseMSAsmIdentifier(llvm::SmallVectorImpl<Token> &LineToks, TemplateKWLoc, Id); - // If we've run into the poison token we inserted before, or there - // was a parsing error, then claim the entire line. - if (Invalid || Tok.is(EndOfStream)) { - NumLineToksConsumed = LineToks.size() - 2; - - // Otherwise, claim up to the start of the next token. + // Figure out how many tokens we are into LineToks. + unsigned LineIndex = 0; + if (Tok.is(EndOfStream)) { + LineIndex = LineToks.size() - 2; } else { - // Figure out how many tokens we are into LineToks. - unsigned LineIndex = 0; while (LineToks[LineIndex].getLocation() != Tok.getLocation()) { LineIndex++; assert(LineIndex < LineToks.size() - 2); // we added two extra tokens } + } + // If we've run into the poison token we inserted before, or there + // was a parsing error, then claim the entire line. + if (Invalid || Tok.is(EndOfStream)) { + NumLineToksConsumed = LineToks.size() - 2; + } else { + // Otherwise, claim up to the start of the next token. NumLineToksConsumed = LineIndex; } - - // Finally, restore the old parsing state by consuming all the - // tokens we staged before, implicitly killing off the - // token-lexer we pushed. - for (unsigned n = LineToks.size() - 2 - NumLineToksConsumed; n != 0; --n) { + + // Finally, restore the old parsing state by consuming all the tokens we + // staged before, implicitly killing off the token-lexer we pushed. + for (unsigned i = 0, e = LineToks.size() - LineIndex - 2; i != e; ++i) { ConsumeAnyToken(); } - ConsumeToken(EndOfStream); + assert(Tok.is(EndOfStream)); + ConsumeToken(); // Leave LineToks in its original state. LineToks.pop_back(); |

