public function testBranchedSimpleIf() { // if (a) { a = 0; } else { b = 0; } c = b; $a = new Variable('a'); $b = new Variable('b'); $c = new Variable('c'); $inst1 = new BranchInstruction($a); $inst2 = ArithmeticInstruction::newAssignNumberToVariableInstruction($a, 0); $inst3 = ArithmeticInstruction::newAssignNumberToVariableInstruction($b, 0); $inst4 = ArithmeticInstruction::newAssignVariableToVariableInstruction($c, $b); $cfg = new ControlFlowGraph($inst1); $cfg->connectIfNotConnected($inst1, GraphEdge::TYPE_ON_TRUE, $inst2); $cfg->connectIfNotConnected($inst1, GraphEdge::TYPE_ON_FALSE, $inst3); $cfg->connectIfNotConnected($inst2, GraphEdge::TYPE_UNCOND, $inst4); $cfg->connectIfNotConnected($inst3, GraphEdge::TYPE_UNCOND, $inst4); $n1 = $cfg->getNode($inst1); $n2 = $cfg->getNode($inst2); $n3 = $cfg->getNode($inst3); $n4 = $cfg->getNode($inst4); $constProp = new BranchedDummyConstPropagation($cfg); $constProp->analyze(); // We cannot conclude anything from if(a). $this->verifyInHas($n1, $a, null); $this->verifyInHas($n1, $b, null); $this->verifyInHas($n1, $c, null); // Nothing is known on the true branch. $this->verifyInHas($n2, $a, null); $this->verifyInHas($n2, $b, null); $this->verifyInHas($n2, $c, null); // Verify that we have a = 0 on the false branch. $this->verifyInHas($n3, $a, 0); $this->verifyInHas($n3, $b, null); $this->verifyInHas($n3, $c, null); // After the merge we should still have a = 0. $this->verifyInHas($n4, $a, 0); }