Skip to content

Commit

Permalink
Partial fix for #12182 (speedup valueFlow by only running valueFlowNu…
Browse files Browse the repository at this point in the history
…mber once)
  • Loading branch information
danmar committed Nov 19, 2023
1 parent e01e090 commit 42e2da4
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,16 @@ static void setTokenValue(Token* tok,
}
}

// C++ init
else if (parent->str() == "{" && Token::simpleMatch(parent->previous(), "= {") && Token::simpleMatch(parent->link(), "} ;")) {
const Token* lhs = parent->previous()->astOperand1();
if (lhs && lhs->valueType()) {
if (lhs->valueType()->isIntegral() || lhs->valueType()->isFloat() || (lhs->valueType()->pointer > 0 && value.isIntValue())) {
setTokenValue(parent, value, settings);
}
}
}

else if (Token::Match(parent, ":: %name%") && parent->astOperand2() == tok) {
setTokenValue(parent, value, settings);
}
Expand Down Expand Up @@ -1335,16 +1345,12 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok->next(), std::move(value), settings);
} else if (Token::Match(tok, "%name% = {") && tok->variable() &&
(tok->variable()->isPointer() || (tok->variable()->valueType() && tok->variable()->valueType()->isIntegral()))) {
if (Token::simpleMatch(tok->tokAt(3), "}")) {
} else if (Token::Match(tok, "= { } ;")) {
const Token* lhs = tok->astOperand1();
if (lhs && lhs->valueType() && (lhs->valueType()->isIntegral() || lhs->valueType()->pointer > 0)) {
ValueFlow::Value value(0);
value.setKnown();
setTokenValue(tok->tokAt(2), std::move(value), settings);
} else if (tok->tokAt(2)->astOperand1() && tok->tokAt(2)->astOperand1()->hasKnownIntValue()) {
ValueFlow::Value value(tok->tokAt(2)->astOperand1()->getKnownIntValue());
value.setKnown();
setTokenValue(tok->tokAt(2), std::move(value), settings);
setTokenValue(tok->next(), std::move(value), settings);
}
}
return tok->next();
Expand Down Expand Up @@ -9448,7 +9454,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
VFA(valueFlowUnknownFunctionReturn(tokenlist, settings)),
VFA(valueFlowGlobalConstVar(tokenlist, settings)),
VFA(valueFlowEnumValue(symboldatabase, settings)),
VFA(valueFlowNumber(tokenlist, settings)),
//VFA(valueFlowCppInit(tokenlist, settings)),
VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
VFA(valueFlowPointerAlias(tokenlist, settings)),
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
Expand Down

0 comments on commit 42e2da4

Please sign in to comment.