CFA minor: retain initialization state while analyzing variable declaration

(cherry picked from commit c89f4db)
This commit is contained in:
Mikhail Glukhikh
2016-09-29 13:16:23 +03:00
committed by Mikhail Glukhikh
parent 436b0ec873
commit f95dcad179
3 changed files with 15 additions and 16 deletions
@@ -138,8 +138,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
enterInitState = getDefaultValueForInitializers(variable, instruction, blockScopeVariableInfo) enterInitState = getDefaultValueForInitializers(variable, instruction, blockScopeVariableInfo)
} }
if (!enterInitState.mayBeInitialized() || !enterInitState.isDeclared) { if (!enterInitState.mayBeInitialized() || !enterInitState.isDeclared) {
val isInitialized = enterInitState.mayBeInitialized() val variableDeclarationInfo = VariableControlFlowState.create(enterInitState.initState, isDeclared = true)
val variableDeclarationInfo = VariableControlFlowState.create(isInitialized, true)
exitInstructionData.put(variable, variableDeclarationInfo) exitInstructionData.put(variable, variableDeclarationInfo)
} }
} }
@@ -25,9 +25,9 @@ L7 [else branch]:
read (Unit) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?} read (Unit) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?}
L8 ['if' expression result]: L8 ['if' expression result]:
merge(if (cond1) continue|!<v2>) -> <v3> merge(if (cond1) continue|!<v2>) -> <v3>
v(val cond2 = false) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=ID} v(val cond2 = false) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?D}
r(false) -> <v4> INIT: in: {cond1=ID, cond2=ID} out: {cond1=ID, cond2=ID} r(false) -> <v4> INIT: in: {cond1=ID, cond2=I?D} out: {cond1=ID, cond2=I?D}
w(cond2|<v4>) w(cond2|<v4>) INIT: in: {cond1=ID, cond2=I?D} out: {cond1=ID, cond2=ID}
L5 [body exit point]: L5 [body exit point]:
L6 [condition entry point]: L6 [condition entry point]:
r(cond2) -> <v5> INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?} r(cond2) -> <v5> INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?}
@@ -16,12 +16,12 @@ L0:
L2 [loop entry point]: L2 [loop entry point]:
L4 [body entry point]: L4 [body entry point]:
mark({ var a = 2 }) INIT: in: {a=I?} out: {a=I?} mark({ var a = 2 }) INIT: in: {a=I?} out: {a=I?}
v(var a = 2) INIT: in: {a=I?} out: {a=ID} v(var a = 2) INIT: in: {a=I?} out: {a=I?D}
r(2) -> <v1> INIT: in: {a=ID} out: {a=ID} r(2) -> <v1> INIT: in: {a=I?D} out: {a=I?D}
w(a|<v1>) w(a|<v1>) INIT: in: {a=I?D} out: {a=ID}
L5 [body exit point]: L5 [body exit point]:
L6 [condition entry point]: L6 [condition entry point]:
r(a) -> <v2> r(a) -> <v2> INIT: in: {a=ID} out: {a=ID}
r(0) -> <v3> r(0) -> <v3>
mark(a > 0) mark(a > 0)
call(a > 0, compareTo|<v2>, <v3>) -> <v4> call(a > 0, compareTo|<v2>, <v3>) -> <v4>