diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b822eefc2..213a37e3f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2377,13 +2377,14 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg } } -void ValueFlow::valueFlowConstantFoldAST(const Token *expr) +const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr) { - if (!expr || !expr->values.empty()) - return; - valueFlowConstantFoldAST(expr->astOperand1()); - valueFlowConstantFoldAST(expr->astOperand2()); - valueFlowSetConstantValue(expr); + if (expr && expr->values.empty()) { + valueFlowConstantFoldAST(expr->astOperand1()); + valueFlowConstantFoldAST(expr->astOperand2()); + valueFlowSetConstantValue(expr); + } + return expr && expr->values.size() == 1U && expr->values.front().isKnown() ? &expr->values.front() : nullptr; } diff --git a/lib/valueflow.h b/lib/valueflow.h index 1beec7934..643a2c227 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -95,7 +95,7 @@ namespace ValueFlow { }; /// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues). - void valueFlowConstantFoldAST(const Token *expr); + const ValueFlow::Value * valueFlowConstantFoldAST(const Token *expr); /// Perform valueflow analysis. void setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings);