@@ -406,46 +406,27 @@ public void visitCtIf(CtIf ifElement) {
406406 Predicate expRefs = getExpressionRefinements (exp );
407407
408408 String pathVarName = String .format (Formats .FRESH , context .getCounter ());
409- RefinedVariable freshRV ;
410-
411- // When the condition's predicate uses Keys.WILDCARD as a stand-in for its boolean value (e.g. _ == true -->
412- // state(this) or _ == k), the fresh path variable IS that value — assert it true in the then branch and false
413- // in the else, since negating the whole predicate is unsound for implications and equality forms.
414- boolean valueIsCondition = false ;
415- Predicate thenRefs ;
416- Predicate elseRefs ;
417- if (isUninformativeCondition (expRefs , exp )) {
418- // No refinement means the condition is unknown, not true: model it as a fresh
419- // boolean so the SMT solver may pick either truth value for each branch.
420- expRefs = Predicate .createVar (pathVarName );
421- thenRefs = expRefs ;
422- elseRefs = expRefs .negate ();
423- freshRV = context .addInstanceToContext (pathVarName , factory .Type ().BOOLEAN_PRIMITIVE , new Predicate (), exp );
424- } else {
425- valueIsCondition = expRefs .getVariableNames ().contains (Keys .WILDCARD );
426- expRefs = expRefs .substituteVariable (Keys .WILDCARD , pathVarName );
427- Predicate lastExpRefs = substituteAllVariablesForLastInstance (expRefs );
428- expRefs = Predicate .createConjunction (expRefs , lastExpRefs );
429-
430- // TODO Change in future
431- if (expRefs .getVariableNames ().contains ("null" )) {
432- expRefs = new Predicate ();
433- valueIsCondition = false ;
434- }
435-
436- thenRefs = expRefs ;
437- elseRefs = expRefs .negate ();
438- if (valueIsCondition ) {
439- Predicate freshIsTrue = Predicate .createEquals (Predicate .createVar (pathVarName ),
440- Predicate .createLit ("true" , Types .BOOLEAN ));
441- Predicate freshIsFalse = Predicate .createEquals (Predicate .createVar (pathVarName ),
442- Predicate .createLit ("false" , Types .BOOLEAN ));
443- thenRefs = Predicate .createConjunction (expRefs , freshIsTrue );
444- elseRefs = Predicate .createConjunction (expRefs , freshIsFalse );
445- }
446-
447- freshRV = context .addInstanceToContext (pathVarName , factory .Type ().BOOLEAN_PRIMITIVE , thenRefs , exp );
409+ // A value refinement constrains the result of evaluating the expression; it is not
410+ // itself the truth value selecting the branch. Calls without a wildcard likewise
411+ // provide no information about their boolean result.
412+ boolean valueIsCondition = expRefs .getVariableNames ().contains (Keys .WILDCARD ) || exp instanceof CtInvocation <?>
413+ || isUninformativeCondition (expRefs , exp );
414+ expRefs = expRefs .substituteVariable (Keys .WILDCARD , pathVarName );
415+ Predicate lastExpRefs = substituteAllVariablesForLastInstance (expRefs );
416+ expRefs = Predicate .createConjunction (expRefs , lastExpRefs );
417+
418+ // TODO Change in future
419+ if (expRefs .getVariableNames ().contains ("null" )) {
420+ expRefs = new Predicate ();
421+ valueIsCondition = true ;
448422 }
423+
424+ Predicate branchGuard = valueIsCondition ? Predicate .createVar (pathVarName ) : expRefs ;
425+ Predicate thenRefs = valueIsCondition ? Predicate .createConjunction (expRefs , branchGuard ) : branchGuard ;
426+ Predicate elseRefs = valueIsCondition ? Predicate .createConjunction (expRefs , branchGuard .negate ())
427+ : branchGuard .negate ();
428+ RefinedVariable freshRV = context .addInstanceToContext (pathVarName , factory .Type ().BOOLEAN_PRIMITIVE , thenRefs ,
429+ exp );
449430 vcChecker .addPathVariable (freshRV );
450431
451432 context .variablesNewIfCombination ();
@@ -488,7 +469,7 @@ public void visitCtIf(CtIf ifElement) {
488469 context .newRefinementToVariableInContext (pathVarName , thenCompletes ? thenRefs : elseRefs );
489470 }
490471 context .exitContext ();
491- context .variablesCombineFromIf (expRefs );
472+ context .variablesCombineFromIf (branchGuard );
492473 context .variablesFinishIfCombination ();
493474 }
494475
0 commit comments