Fix #10828 Internal error. Token::Match called with varid 0 (#3859)

* Fix #10828 Internal error. Token::Match called with varid 0

* Fix test
This commit is contained in:
chrchr-github 2022-02-26 23:48:29 +01:00 committed by GitHub
parent 441b437cea
commit d79d6e60db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -6083,32 +6083,32 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
getProgramMemory(tok2->astTop(), expr, ValueFlow::Value(value), settings))))
break;
else if (Token::simpleMatch(tok2, ") {") && Token::findmatch(tok2->link(), "%varid%", tok2, vartok->varId())) {
if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(1), vartok->varId())) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop variable bailout on conditional continue|break|return");
break;
}
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop variable skipping conditional scope");
tok2 = tok2->next()->link();
if (Token::simpleMatch(tok2, "} else {")) {
if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(2), vartok->varId())) {
else if (Token::simpleMatch(tok2, ") {")) {
if (vartok->varId() && Token::findmatch(tok2->link(), "%varid%", tok2, vartok->varId())) {
if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(1), vartok->varId())) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop variable bailout on conditional continue|break|return");
break;
}
tok2 = tok2->linkAt(2);
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop variable skipping conditional scope");
tok2 = tok2->next()->link();
if (Token::simpleMatch(tok2, "} else {")) {
if (Token::findmatch(tok2, "continue|break|return", tok2->linkAt(2), vartok->varId())) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop variable bailout on conditional continue|break|return");
break;
}
tok2 = tok2->linkAt(2);
}
}
else {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop skipping {} code");
tok2 = tok2->linkAt(1);
if (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->linkAt(2);
}
}
else if (Token::simpleMatch(tok2, ") {")) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "For loop skipping {} code");
tok2 = tok2->linkAt(1);
if (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->linkAt(2);
}
}
}

View File

@ -4171,6 +4171,19 @@ private:
" }\n"
"}\n";
testValueOfX(code, 0, 0); // <- don't throw
code = "struct C {\n" // #10828
" int& v() { return i; }\n"
" int& w() { return j; }\n"
" int i{}, j{};\n"
"};\n"
"void f() {\n"
" C c;\n"
" for (c.w() = 0; c.w() < 2; c.w()++) {\n"
" for (c.v() = 0; c.v() < 24; c.v()++) {}\n"
" }\n"
"}\n";
testValueOfX(code, 0, 0); // <- don't throw
}
void valueFlowSubFunction() {