Skip to content

Commit bbcffce

Browse files
committed
Fixed #9062 (False positive "condition is always true")
1 parent e11dcc6 commit bbcffce

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
15121512
if (Token::simpleMatch(tok, "asm ("))
15131513
return Result(Result::Type::BAILOUT);
15141514

1515-
if (mWhat == What::ValueFlow && Token::Match(tok, "while|for (")) {
1515+
if (mWhat == What::ValueFlow && (Token::Match(tok, "while|for (") || Token::simpleMatch(tok, "do {"))) {
15161516
// TODO: only bailout if expr is reassigned in loop
15171517
return Result(Result::Type::BAILOUT);
15181518
}

test/testvalueflow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,16 @@ class TestValueFlow : public TestFixture {
25852585
values = tokenValues(code, ">");
25862586
ASSERT_EQUALS(true, values.empty());
25872587

2588+
code = "void foo() {\n"
2589+
" struct ISO_PVD_s pvd;\n"
2590+
" pvd.descr_type = 0xff;\n"
2591+
" do {\n"
2592+
" if (pvd.descr_type == 0xff) {}\n"
2593+
" dostuff(&pvd);\n"
2594+
" } while (condition)\n"
2595+
"}";
2596+
values = tokenValues(code, "==");
2597+
ASSERT_EQUALS(true, values.empty());
25882598
}
25892599

25902600
void valueFlowSwitchVariable() {

0 commit comments

Comments
 (0)