Repository navigation
Fix #15300: internalError with invalid integer literal in unknown macro #9106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8944,6 +8944,15 @@ void Tokenizer::findGarbageCode() const | |
| "typedef", | ||
| "while" }; | ||
|
|
||
| const auto isTooLargeInt = [](const Token *tok) { | ||
| try { | ||
| (void)MathLib::toBigUNumber(tok); | ||
| return false; | ||
| } catch (const InternalError & /*e*/) { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| for (const Token *tok = tokens(); tok; tok = tok->next()) { | ||
| // initialization: = { | ||
| if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} (")) | ||
|
|
@@ -8995,6 +9004,19 @@ void Tokenizer::findGarbageCode() const | |
| syntaxError(tok); | ||
| } | ||
|
|
||
| // Invalid integer literal as argument of a possible macro | ||
| if (tok->isNumber() && MathLib::isInt(tok->str()) && isTooLargeInt(tok)) { | ||
| const Token *prev = tok->previous(); | ||
| while (prev && !Token::Match(prev, "(|;|{|}")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review The walk back from the literal stops at |
||
| if (Token::Match(prev, ")|]")) | ||
| prev = prev->link(); | ||
| prev = prev->previous(); | ||
| } | ||
| if (prev && prev->str() == "(" && Token::Match(prev->previous(), "%name% (") && !prev->previous()->isKeyword()) | ||
| unknownMacroError(prev->previous()); | ||
|
ludviggunne marked this conversation as resolved.
Resolved
|
||
| syntaxError(tok, "integer literal too large"); | ||
| } | ||
|
|
||
| if (tok->isControlFlowKeyword()) { | ||
| if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... } | ||
| if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI review
This throws at the first too-large literal it meets in the main loop. The checks later in
findGarbageCodethat would give a more specific error never run on the rest of the code.For
int x = STR(a; 123456789012345678901234567890123456789);:If STR is a macro then please configure it. [unknownMacro]syntax error: integer literal too largeOne fix is to remember the first too-large literal and throw only after the loop has finished. Another is to do this check in a separate pass at the end of
findGarbageCode.