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)
}
if (!enterInitState.mayBeInitialized() || !enterInitState.isDeclared) {
val isInitialized = enterInitState.mayBeInitialized()
val variableDeclarationInfo = VariableControlFlowState.create(isInitialized, true)
val variableDeclarationInfo = VariableControlFlowState.create(enterInitState.initState, isDeclared = true)
exitInstructionData.put(variable, variableDeclarationInfo)
}
}
@@ -11,7 +11,7 @@ L0:
v(cond1: Boolean) INIT: in: {} out: {cond1=D}
magic[FAKE_INITIALIZER](cond1: Boolean) -> <v0> INIT: in: {cond1=D} out: {cond1=D}
w(cond1|<v0>) INIT: in: {cond1=D} out: {cond1=ID}
2 mark({ do { if (cond1) continue val cond2 = false } while (cond2) }) INIT: in: {cond1=ID} out: {cond1=ID} USE: in: {cond1=READ} out: {cond1=READ}
2 mark({ do { if (cond1) continue val cond2 = false } while (cond2) }) INIT: in: {cond1=ID} out: {cond1=ID} USE: in: {cond1=READ} out: {cond1=READ}
3 mark(do { if (cond1) continue val cond2 = false } while (cond2))
L2 [loop entry point]:
L4 [body entry point]:
@@ -19,19 +19,19 @@ L4 [body entry point]:
mark(if (cond1) continue)
r(cond1) -> <v1>
jf(L7|<v1>)
jmp(L6) USE: in: {cond1=READ, cond2=READ} out: {cond1=READ, cond2=READ}
jmp(L6) USE: in: {cond1=READ, cond2=READ} out: {cond1=READ, cond2=READ}
- jmp(L8)
L7 [else branch]:
read (Unit) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?}
L8 ['if' expression result]:
merge(if (cond1) continue|!<v2>) -> <v3>
v(val cond2 = false) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=ID}
r(false) -> <v4> INIT: in: {cond1=ID, cond2=ID} out: {cond1=ID, cond2=ID}
w(cond2|<v4>)
v(val cond2 = false) INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?D}
r(false) -> <v4> INIT: in: {cond1=ID, cond2=I?D} out: {cond1=ID, cond2=I?D}
w(cond2|<v4>) INIT: in: {cond1=ID, cond2=I?D} out: {cond1=ID, cond2=ID}
L5 [body exit point]:
L6 [condition entry point]:
r(cond2) -> <v5> INIT: in: {cond1=ID, cond2=I?} out: {cond1=ID, cond2=I?}
jt(L2|<v5>) USE: in: {cond1=READ, cond2=READ} out: {cond1=READ, cond2=READ}
jt(L2|<v5>) USE: in: {cond1=READ, cond2=READ} out: {cond1=READ, cond2=READ}
L3 [loop exit point]:
read (Unit)
L1:
@@ -39,5 +39,5 @@ L1:
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {cond1=I?} out: {cond1=I?} USE: in: {} out: {}
<SINK> INIT: in: {cond1=I?} out: {cond1=I?} USE: in: {} out: {}
=====================
@@ -11,21 +11,21 @@ L0:
1 <START> INIT: in: {} out: {}
2 mark({ "before" do { var a = 2 } while (a > 0) "after" })
mark("before")
r("before") -> <v0> USE: in: {} out: {}
r("before") -> <v0> USE: in: {} out: {}
3 mark(do { var a = 2 } while (a > 0))
L2 [loop entry point]:
L4 [body entry point]:
mark({ var a = 2 }) INIT: in: {a=I?} out: {a=I?}
v(var a = 2) INIT: in: {a=I?} out: {a=ID}
r(2) -> <v1> INIT: in: {a=ID} out: {a=ID}
w(a|<v1>)
v(var a = 2) INIT: in: {a=I?} out: {a=I?D}
r(2) -> <v1> INIT: in: {a=I?D} out: {a=I?D}
w(a|<v1>) INIT: in: {a=I?D} out: {a=ID}
L5 [body exit point]:
L6 [condition entry point]:
r(a) -> <v2>
r(a) -> <v2> INIT: in: {a=ID} out: {a=ID}
r(0) -> <v3>
mark(a > 0)
call(a > 0, compareTo|<v2>, <v3>) -> <v4>
jt(L2|<v4>) USE: in: {a=READ} out: {a=READ}
jt(L2|<v4>) USE: in: {a=READ} out: {a=READ}
L3 [loop exit point]:
read (Unit)
2 mark("after") INIT: in: {} out: {}
@@ -35,5 +35,5 @@ L1:
error:
<ERROR>
sink:
<SINK> USE: in: {} out: {}
<SINK> USE: in: {} out: {}
=====================