From ffc707246b1b2ae6c00cd36e0a6dbc17e94ef89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 21 Jul 2015 17:56:40 +0200 Subject: [PATCH] ValueFlow: Better handling of Known/Possible values after conditional unknown function call --- lib/valueflow.cpp | 11 +++++++++++ test/testvalueflow.cpp | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 59dd30be4..9f37d37c5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -279,6 +279,17 @@ static bool isVariableChanged(const Token *start, const Token *end, const unsign if (Token::Match(tok->tokAt(-2), "[(,] & %var% [,)]")) return true; // TODO: check if function parameter is const + if (Token::Match(tok->previous(), "[(,] %var% [,)]")) { + const Token *parent = tok->astParent(); + while (parent && parent->str() == ",") + parent = parent->astParent(); + if (parent && parent->str() == "(") { + if (parent->astOperand1()->isName() && !parent->astOperand1()->function()) + return true; + // TODO: check if function parameter is non-const reference etc.. + } + } + const Token *parent = tok->astParent(); while (Token::Match(parent, ".|::")) parent = parent->astParent(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 89e99299a..005e1addd 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1579,6 +1579,13 @@ private: ASSERT_EQUALS(9, value.intvalue); ASSERT_EQUALS(ValueFlow::Value::ValueKind::Possible, value.valueKind); + code = "void f() {\n" + " int x = 0;\n" + " if (y) { dostuff(x); }\n" + " if (!x) {}\n" + "}\n"; + ASSERT(isNotKnownValues(code, "!")); + code = "void f() {\n" " int x = 0;\n" " for (int i = 0; i < 10; i++) {\n"