From 60348da1b5b7a43db6613c99325bfe69c8df21f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Jan 2014 11:30:34 +0100 Subject: [PATCH] value flow: fixed fp for rhs in && and || expressions --- lib/valueflow.cpp | 7 +++++-- test/testvalueflow.cpp | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 532a8cdfc..c6f338620 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -116,11 +116,14 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog // skip if variable is conditionally used in ?: expression. const Token *parent = tok2->astParent(); - while (parent && !Token::Match(parent, "[?:]")) + while (parent && !Token::Match(parent, "%oror%|&&?|:")) parent = parent->astParent(); if (parent) { if (settings->debugwarnings) - bailout(tokenlist, errorLogger, tok2, "no simplification of " + tok2->str() + " within ?: expression"); + bailout(tokenlist, + errorLogger, + tok2, + "no simplification of " + tok2->str() + " within " + (Token::Match(parent,"[?:]") ? "?:" : parent->str()) + " expression"); continue; } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 9f3564679..45507a306 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -104,6 +104,15 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 3U, 123)); + // guarding by && + bailout("void f(int x) {\n" + " if (!x || \n" // <- x can be 0 + " a/x) {}\n" // <- x can't be 0 + " if (x==0) {}\n" + "}"); + TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 2U, 0)); + ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); + // bailout: ?: bailout("void f(int x) {\n" " y = ((x<0) ? x : ((x==2)?3:4));\n"