1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[AsmParser] Avoid recursing when lexing ';'. NFC.

This should prevent stack overflows in non-optimized builds on
.ll files with lots of consecutive commented-out lines.

Instead of recursing into LexToken(), continue into a 'while (true)'.

llvm-svn: 287170
This commit is contained in:
Ahmed Bougacha 2016-11-16 22:25:05 +00:00
parent 040d69db42
commit 8d7afbaec0

View File

@ -180,61 +180,63 @@ int LLLexer::getNextChar() {
} }
lltok::Kind LLLexer::LexToken() { lltok::Kind LLLexer::LexToken() {
TokStart = CurPtr; while (true) {
TokStart = CurPtr;
int CurChar = getNextChar(); int CurChar = getNextChar();
switch (CurChar) { switch (CurChar) {
default: default:
// Handle letters: [a-zA-Z_] // Handle letters: [a-zA-Z_]
if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_') if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
return LexIdentifier(); return LexIdentifier();
return lltok::Error; return lltok::Error;
case EOF: return lltok::Eof; case EOF: return lltok::Eof;
case 0: case 0:
case ' ': case ' ':
case '\t': case '\t':
case '\n': case '\n':
case '\r': case '\r':
// Ignore whitespace. // Ignore whitespace.
return LexToken(); continue;
case '+': return LexPositive(); case '+': return LexPositive();
case '@': return LexAt(); case '@': return LexAt();
case '$': return LexDollar(); case '$': return LexDollar();
case '%': return LexPercent(); case '%': return LexPercent();
case '"': return LexQuote(); case '"': return LexQuote();
case '.': case '.':
if (const char *Ptr = isLabelTail(CurPtr)) { if (const char *Ptr = isLabelTail(CurPtr)) {
CurPtr = Ptr; CurPtr = Ptr;
StrVal.assign(TokStart, CurPtr-1); StrVal.assign(TokStart, CurPtr-1);
return lltok::LabelStr; return lltok::LabelStr;
}
if (CurPtr[0] == '.' && CurPtr[1] == '.') {
CurPtr += 2;
return lltok::dotdotdot;
}
return lltok::Error;
case ';':
SkipLineComment();
continue;
case '!': return LexExclaim();
case '#': return LexHash();
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '-':
return LexDigitOrNegative();
case '=': return lltok::equal;
case '[': return lltok::lsquare;
case ']': return lltok::rsquare;
case '{': return lltok::lbrace;
case '}': return lltok::rbrace;
case '<': return lltok::less;
case '>': return lltok::greater;
case '(': return lltok::lparen;
case ')': return lltok::rparen;
case ',': return lltok::comma;
case '*': return lltok::star;
case '|': return lltok::bar;
} }
if (CurPtr[0] == '.' && CurPtr[1] == '.') {
CurPtr += 2;
return lltok::dotdotdot;
}
return lltok::Error;
case ';':
SkipLineComment();
return LexToken();
case '!': return LexExclaim();
case '#': return LexHash();
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '-':
return LexDigitOrNegative();
case '=': return lltok::equal;
case '[': return lltok::lsquare;
case ']': return lltok::rsquare;
case '{': return lltok::lbrace;
case '}': return lltok::rbrace;
case '<': return lltok::less;
case '>': return lltok::greater;
case '(': return lltok::lparen;
case ')': return lltok::rparen;
case ',': return lltok::comma;
case '*': return lltok::star;
case '|': return lltok::bar;
} }
} }