Skip to content

Commit b94eaec

Browse files
committed
ValueFlow: For convenience, return constant folded value
1 parent b26dd1c commit b94eaec

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

lib/valueflow.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,13 +2377,14 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg
23772377
}
23782378
}
23792379

2380-
void ValueFlow::valueFlowConstantFoldAST(const Token *expr)
2380+
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr)
23812381
{
2382-
if (!expr || !expr->values.empty())
2383-
return;
2384-
valueFlowConstantFoldAST(expr->astOperand1());
2385-
valueFlowConstantFoldAST(expr->astOperand2());
2386-
valueFlowSetConstantValue(expr);
2382+
if (expr && expr->values.empty()) {
2383+
valueFlowConstantFoldAST(expr->astOperand1());
2384+
valueFlowConstantFoldAST(expr->astOperand2());
2385+
valueFlowSetConstantValue(expr);
2386+
}
2387+
return expr && expr->values.size() == 1U && expr->values.front().isKnown() ? &expr->values.front() : nullptr;
23872388
}
23882389

23892390

lib/valueflow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace ValueFlow {
9595
};
9696

9797
/// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues).
98-
void valueFlowConstantFoldAST(const Token *expr);
98+
const ValueFlow::Value * valueFlowConstantFoldAST(const Token *expr);
9999

100100
/// Perform valueflow analysis.
101101
void setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings);

0 commit comments

Comments
 (0)