Skip to content

Commit 1d6c886

Browse files
author
Your Name
committed
Merge from fork
1 parent d3f0365 commit 1d6c886

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/forwardanalyzer.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,10 @@ namespace {
682682
// here via the 'then' branch, so the value established there is still
683683
// definite - keep it known instead of lowering to possible.
684684
bool elseEscape = false;
685-
bool unknownEscape = false;
686-
if (!inLoop && !inElse && hasElse)
685+
if (!inLoop && !inElse && hasElse) {
686+
bool unknownEscape = false;
687687
elseEscape = isEscapeScope(tok->linkAt(2), unknownEscape);
688+
}
688689
if (!condTok->hasKnownIntValue() || inLoop) {
689690
if (!elseEscape && !analyzer->lowerToPossible())
690691
return Break(Analyzer::Terminate::Bail);
@@ -793,6 +794,9 @@ namespace {
793794
// The branch is traversed below, so don't record its boundary state here.
794795
ft.analyzer->assume(condTok, true, Analyzer::Assume::Pending);
795796
Progress pThen = ft.updateBranch(thenBranch, depth - 1);
797+
// Merge the fork's actions so a modification in the then-branch bubbles up
798+
// to the enclosing branch's isModified().
799+
actions |= thenBranch.action;
796800

797801
// Commit the condition as false on the main path only when the then-branch
798802
// is dead. The else block, if any, is traversed separately (Pending); with

test/testcondition.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4911,6 +4911,17 @@ class TestCondition : public TestFixture {
49114911
ASSERT_EQUALS("[test.cpp:3:10]: (style) Condition 'b()' is always false [knownConditionTrueFalse]\n"
49124912
"[test.cpp:4:9]: (style) Condition '!b()' is always true [knownConditionTrueFalse]\n",
49134913
errout_str());
4914+
4915+
check("int g();\n" // a value modified inside a nested branch must be lowered to possible
4916+
"void f(int outer, int inner) {\n"
4917+
" int bits = 0;\n"
4918+
" if (outer) {\n"
4919+
" if (inner == 1)\n"
4920+
" bits = g();\n"
4921+
" }\n"
4922+
" if (bits > 0) {}\n"
4923+
"}\n");
4924+
ASSERT_EQUALS("", errout_str());
49144925
}
49154926

49164927
void alwaysTrueSymbolic()

0 commit comments

Comments
 (0)