Fix 11889: FP knownArgument with array element (#5395)

This commit is contained in:
Paul Fultz II 2023-09-02 07:29:38 -05:00 committed by GitHub
parent 6c0a5a5859
commit ffbcfae988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -3704,8 +3704,7 @@ static bool isVariableExpression(const Token* tok)
return isVariableExpression(tok->astOperand1()) &&
isVariableExpression(tok->astOperand2());
if (Token::simpleMatch(tok, "["))
return isVariableExpression(tok->astOperand1()) &&
tok->astOperand2() && tok->astOperand2()->hasKnownIntValue();
return isVariableExpression(tok->astOperand1());
return false;
}

View File

@ -11053,6 +11053,20 @@ private:
" if (g(k(i))) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #11889
check("struct S {\n"
" int a[5];\n"
" void f(int i);\n"
"}\n"
"void g(int);\n"
"void S::f(int i) {\n"
" if (a[i] == 1) {\n"
" a[i] = 0;\n"
" g(a[i]);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void knownArgumentHiddenVariableExpression() {