Skip to content

Commit 2cbb07e

Browse files
author
Your Name
committed
Fix 14900: FP knownConditionTrueFalse on variable after if/else-if chain
1 parent 168777d commit 2cbb07e

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/forwardanalyzer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,13 @@ namespace {
834834
++ft.forkDepth;
835835
ft.updateRange(thenBranch.endBlock, end, depth - 1);
836836
}
837-
if (pElse == Progress::Break)
837+
if (pElse == Progress::Break) {
838+
// Only the else branch escaped; the then branch falls through, so
839+
// the scope as a whole does not always escape.
840+
if (terminate == Analyzer::Terminate::Escape && !thenBranch.isEscape())
841+
terminate = Analyzer::Terminate::None;
838842
return Break();
843+
}
839844
}
840845
}
841846
} else if (Token::simpleMatch(tok, "try {")) {

test/testcondition.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4935,6 +4935,20 @@ class TestCondition : public TestFixture {
49354935
" if (v > 0) {}\n"
49364936
"}\n");
49374937
ASSERT_EQUALS("", errout_str());
4938+
4939+
check("bool f(int x) {\n" // only the innermost else escapes - x is 0 or >1 afterwards, not known
4940+
" if (!x) {}\n"
4941+
" else if (x > 1) {}\n"
4942+
" else return false;\n"
4943+
" return x ? false : true;\n"
4944+
"}\n");
4945+
ASSERT_EQUALS("", errout_str());
4946+
4947+
check("bool f(int x) {\n" // the branch's fall-through path must clear the escape
4948+
" if (x) { if (x > 1) {} else return false; }\n"
4949+
" return x ? false : true;\n"
4950+
"}\n");
4951+
ASSERT_EQUALS("", errout_str());
49384952
}
49394953

49404954
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)