diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f141abd0c..20863e533 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2470,6 +2470,16 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti if (!arg->isConst() && arg->isReference()) return true; } + if (addressOf && tok1->astParent()->isUnaryOp("&")) { + const Token* castToken = tok1->astParent(); + while (castToken->astParent()->isCast()) + castToken = castToken->astParent(); + if (Token::Match(castToken->astParent(), ",|(") && + castToken->valueType() && + castToken->valueType()->isIntegral() && + castToken->valueType()->pointer == 0) + return true; + } if (!conclusive && inconclusive) { *inconclusive = true; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 589a057b7..1aac082a2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5590,6 +5590,16 @@ private: values = tokenValues(code, "& y :", ValueFlow::Value::ValueType::UNINIT); ASSERT_EQUALS(1, values.size()); ASSERT_EQUALS(true, values.front().isUninitValue()); + + // #12012 - function init variable + code = "void init(uintptr_t p);\n" + "void fp() {\n" + " int x;\n" + " init((uintptr_t)&x);\n" + " if (x > 0) {}\n" + "}\n"; + values = tokenValues(code, "x >", ValueFlow::Value::ValueType::UNINIT); + ASSERT_EQUALS(0, values.size()); } void valueFlowConditionExpressions() {