summaryrefslogtreecommitdiff
path: root/lib/AsmParser
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2016-11-16 22:25:05 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2016-11-16 22:25:05 +0000
commit10adab0d54dca2f6e66f8c517ee4fa5dbd354d4c (patch)
tree73e81bf0d7e2dd4a695a77291dd0a24c75a96fe4 /lib/AsmParser
parent03cebfbba99b59953fd96fd4bd55d15c64df3fb7 (diff)
[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)'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287170 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r--lib/AsmParser/LLLexer.cpp106
1 files changed, 54 insertions, 52 deletions
diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp
index 2ead37198b1..ca30a4f1c78 100644
--- a/lib/AsmParser/LLLexer.cpp
+++ b/lib/AsmParser/LLLexer.cpp
@@ -180,61 +180,63 @@ int LLLexer::getNextChar() {
}
lltok::Kind LLLexer::LexToken() {
- TokStart = CurPtr;
+ while (true) {
+ TokStart = CurPtr;
- int CurChar = getNextChar();
- switch (CurChar) {
- default:
- // Handle letters: [a-zA-Z_]
- if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
- return LexIdentifier();
+ int CurChar = getNextChar();
+ switch (CurChar) {
+ default:
+ // Handle letters: [a-zA-Z_]
+ if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
+ return LexIdentifier();
- return lltok::Error;
- case EOF: return lltok::Eof;
- case 0:
- case ' ':
- case '\t':
- case '\n':
- case '\r':
- // Ignore whitespace.
- return LexToken();
- case '+': return LexPositive();
- case '@': return LexAt();
- case '$': return LexDollar();
- case '%': return LexPercent();
- case '"': return LexQuote();
- case '.':
- if (const char *Ptr = isLabelTail(CurPtr)) {
- CurPtr = Ptr;
- StrVal.assign(TokStart, CurPtr-1);
- return lltok::LabelStr;
- }
- if (CurPtr[0] == '.' && CurPtr[1] == '.') {
- CurPtr += 2;
- return lltok::dotdotdot;
+ return lltok::Error;
+ case EOF: return lltok::Eof;
+ case 0:
+ case ' ':
+ case '\t':
+ case '\n':
+ case '\r':
+ // Ignore whitespace.
+ continue;
+ case '+': return LexPositive();
+ case '@': return LexAt();
+ case '$': return LexDollar();
+ case '%': return LexPercent();
+ case '"': return LexQuote();
+ case '.':
+ if (const char *Ptr = isLabelTail(CurPtr)) {
+ CurPtr = Ptr;
+ StrVal.assign(TokStart, CurPtr-1);
+ 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;
}
- 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;
}
}