CFA: additional jumps to catch / finally generated in the end of try / before exits from try #KT-5469 Fixed
Also #KT-13612 Fixed (cherry picked from commit 7c188b3)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
43954699a7
commit
f8039249c6
@@ -43,10 +43,11 @@ L3 [else branch]:
|
||||
read (Unit) INIT: in: {f=ID} out: {f=ID}
|
||||
L4 ['if' expression result]:
|
||||
merge(if (f) { x = 0 }|!<v3>) -> <v4> INIT: in: {f=ID, x=I} out: {f=ID, x=I}
|
||||
2 jmp(L5)
|
||||
2 jmp?(L2)
|
||||
jmp(L5)
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
L6 [start finally]:
|
||||
3 mark({ fun bar() {} }) INIT: in: {f=ID} out: {f=ID}
|
||||
3 mark({ fun bar() {} })
|
||||
jmp?(L7)
|
||||
d(fun bar() {})
|
||||
L7 [after local declaration]:
|
||||
@@ -54,7 +55,7 @@ L10 [finish finally]:
|
||||
2 jmp(error)
|
||||
L5 [skipFinallyToErrorBlock]:
|
||||
L11 [copy of L2, onExceptionToFinallyBlock]:
|
||||
3 mark({ fun bar() {} }) INIT: in: {f=ID, x=I} out: {f=ID, x=I}
|
||||
3 mark({ fun bar() {} })
|
||||
jmp?(L12)
|
||||
d(fun bar() {})
|
||||
L12 [copy of L7, after local declaration]:
|
||||
@@ -62,15 +63,15 @@ L12 [copy of L7, after local declaration]:
|
||||
L1:
|
||||
1 <END>
|
||||
error:
|
||||
<ERROR> INIT: in: {f=ID} out: {f=ID}
|
||||
<ERROR>
|
||||
sink:
|
||||
<SINK> INIT: in: {f=ID, x=I} out: {f=ID, x=I} USE: in: {} out: {}
|
||||
<SINK> USE: in: {} out: {}
|
||||
=====================
|
||||
== bar ==
|
||||
fun bar() {}
|
||||
---------------------
|
||||
L8:
|
||||
4 <START> INIT: in: {f=ID} out: {f=ID}
|
||||
4 <START> INIT: in: {f=ID, x=I} out: {f=ID, x=I}
|
||||
5 mark({})
|
||||
read (Unit)
|
||||
L9:
|
||||
@@ -78,7 +79,7 @@ L9:
|
||||
error:
|
||||
<ERROR> INIT: in: {} out: {}
|
||||
sink:
|
||||
<SINK> INIT: in: {f=ID} out: {f=ID} USE: in: {} out: {}
|
||||
<SINK> INIT: in: {f=ID, x=I} out: {f=ID, x=I} USE: in: {} out: {}
|
||||
=====================
|
||||
== bar ==
|
||||
fun bar() {}
|
||||
|
||||
@@ -32,6 +32,7 @@ L0:
|
||||
r(false) -> <v0>
|
||||
jf(L3|<v0>)
|
||||
4 mark({ return "fail" })
|
||||
jmp?(L2)
|
||||
mark("fail")
|
||||
r("fail") -> <v1>
|
||||
L4 [start finally]:
|
||||
@@ -60,12 +61,15 @@ L3 [else branch]:
|
||||
mark("test")
|
||||
r("test") -> <v6> USE: in: {foo=WRITTEN_AFTER_READ} out: {foo=WRITTEN_AFTER_READ}
|
||||
w(foo|<v6>) USE: in: {foo=READ} out: {foo=WRITTEN_AFTER_READ}
|
||||
6 jmp(L11)
|
||||
6 jmp?(L9)
|
||||
jmp?(L10)
|
||||
jmp(L11)
|
||||
L9 [onException]:
|
||||
7 v(e: Exception) INIT: in: {foo=ID} out: {e=D, foo=ID}
|
||||
magic[FAKE_INITIALIZER](e: Exception) -> <v8> INIT: in: {e=D, foo=ID} out: {e=D, foo=ID}
|
||||
w(e|<v8>) INIT: in: {e=D, foo=ID} out: {e=ID, foo=ID}
|
||||
8 mark({ return "fail" }) INIT: in: {e=ID, foo=ID} out: {e=ID, foo=ID}
|
||||
jmp?(L2)
|
||||
mark("fail")
|
||||
r("fail") -> <v9>
|
||||
L12 [start finally]:
|
||||
@@ -99,6 +103,7 @@ L8 [else branch]:
|
||||
read (Unit)
|
||||
L15 ['if' expression result]:
|
||||
merge(if (false) { var foo: String? = null try { foo = "test" } catch (e: Exception) { return "fail" } finally { println(foo) // Variable 'foo' must be initialized } }|<v14>) -> <v15>
|
||||
jmp?(L2)
|
||||
mark("fail")
|
||||
r("fail") -> <v16>
|
||||
mark({})
|
||||
@@ -111,7 +116,8 @@ L16 ['if' expression result]:
|
||||
merge(if (false) { if (false) { var foo: String? = null try { foo = "test" } catch (e: Exception) { return "fail" } finally { println(foo) // Variable 'foo' must be initialized } } return "fail" }|!<v17>) -> <v18>
|
||||
L6 ['if' expression result]:
|
||||
3 merge(if (false) { return "fail" } else { if (false) { if (false) { var foo: String? = null try { foo = "test" } catch (e: Exception) { return "fail" } finally { println(foo) // Variable 'foo' must be initialized } } return "fail" } }|!<v2>, <v18>) -> <v19>
|
||||
2 jmp(L17)
|
||||
2 jmp?(L2)
|
||||
jmp(L17)
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
5 mark({})
|
||||
read (Unit)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
== f ==
|
||||
fun f() {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
throw RuntimeException()
|
||||
} catch (e: Throwable) {
|
||||
println(foo)
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
L0:
|
||||
1 <START> INIT: in: {} out: {} USE: in: {} out: {}
|
||||
2 mark({ var foo = 1 try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) } })
|
||||
v(var foo = 1) INIT: in: {} out: {foo=D}
|
||||
r(1) -> <v0> INIT: in: {foo=D} out: {foo=D}
|
||||
w(foo|<v0>) INIT: in: {foo=D} out: {foo=ID}
|
||||
mark(try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) }) INIT: in: {foo=ID} out: {foo=ID}
|
||||
jmp?(L2) USE: in: {foo=READ} out: {foo=READ}
|
||||
3 mark({ foo = 2 throw RuntimeException() })
|
||||
r(2) -> <v1> USE: in: {foo=WRITTEN_AFTER_READ} out: {foo=WRITTEN_AFTER_READ}
|
||||
w(foo|<v1>) USE: in: {foo=READ} out: {foo=WRITTEN_AFTER_READ}
|
||||
mark(throw RuntimeException())
|
||||
jmp?(L2) USE: in: {foo=READ} out: {foo=READ}
|
||||
mark(RuntimeException())
|
||||
call(RuntimeException(), <init>) -> <v2>
|
||||
throw (throw RuntimeException()|<v2>) USE: in: {} out: {}
|
||||
- 2 jmp?(L2)
|
||||
- jmp(L3)
|
||||
L2 [onException]:
|
||||
3 v(e: Throwable) INIT: in: {foo=ID} out: {e=D, foo=ID}
|
||||
magic[FAKE_INITIALIZER](e: Throwable) -> <v4> INIT: in: {e=D, foo=ID} out: {e=D, foo=ID}
|
||||
w(e|<v4>) INIT: in: {e=D, foo=ID} out: {e=ID, foo=ID}
|
||||
4 mark({ println(foo) }) INIT: in: {e=ID, foo=ID} out: {e=ID, foo=ID} USE: in: {foo=READ} out: {foo=READ}
|
||||
r(foo) -> <v5> USE: in: {} out: {foo=READ}
|
||||
mark(println(foo))
|
||||
magic[UNRESOLVED_CALL](println(foo)|<v5>, !<v6>) -> <v7>
|
||||
3 jmp(L3)
|
||||
L3 [afterCatches]:
|
||||
2 merge(try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) }|!<v3>, <v7>) -> <v8> INIT: in: {foo=ID} out: {foo=ID}
|
||||
L1:
|
||||
1 <END> INIT: in: {} out: {}
|
||||
error:
|
||||
<ERROR>
|
||||
sink:
|
||||
<SINK> USE: in: {} out: {}
|
||||
=====================
|
||||
@@ -0,0 +1,9 @@
|
||||
fun f() {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
throw RuntimeException()
|
||||
} catch (e: Throwable) {
|
||||
println(foo)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
== f ==
|
||||
fun f() {
|
||||
var foo = 1
|
||||
try {
|
||||
foo = 2
|
||||
throw RuntimeException()
|
||||
} catch (e: Throwable) {
|
||||
println(foo)
|
||||
}
|
||||
}
|
||||
---------------------
|
||||
<v4>: {<: Throwable} NEW: magic[FAKE_INITIALIZER](e: Throwable) -> <v4>
|
||||
1 <v0>: Int NEW: r(1) -> <v0>
|
||||
2 <v1>: Int NEW: r(2) -> <v1>
|
||||
RuntimeException() <v2>: {<: Throwable} NEW: call(RuntimeException(), <init>) -> <v2>
|
||||
throw RuntimeException() !<v3>: *
|
||||
{ foo = 2 throw RuntimeException() } !<v3>: * COPY
|
||||
println !<v6>: *
|
||||
foo <v5>: * NEW: r(foo) -> <v5>
|
||||
println(foo) <v7>: * NEW: magic[UNRESOLVED_CALL](println(foo)|<v5>, !<v6>) -> <v7>
|
||||
{ println(foo) } <v7>: * COPY
|
||||
try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) } <v8>: * NEW: merge(try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) }|!<v3>, <v7>) -> <v8>
|
||||
{ var foo = 1 try { foo = 2 throw RuntimeException() } catch (e: Throwable) { println(foo) } } <v8>: * COPY
|
||||
=====================
|
||||
+12
-11
@@ -11,7 +11,7 @@ fun test5() {
|
||||
}
|
||||
---------------------
|
||||
L0:
|
||||
1 <START> INIT: in: {} out: {} USE: in: {} out: {}
|
||||
1 <START> INIT: in: {} out: {} USE: in: {} out: {}
|
||||
2 mark({ var a: Int try { a = 3 } finally { a = 5 } a.hashCode() })
|
||||
v(var a: Int) INIT: in: {} out: {a=D}
|
||||
mark(try { a = 3 } finally { a = 5 }) INIT: in: {a=D} out: {a=D}
|
||||
@@ -19,22 +19,23 @@ L0:
|
||||
3 mark({ a = 3 })
|
||||
r(3) -> <v0>
|
||||
w(a|<v0>) INIT: in: {a=D} out: {a=ID}
|
||||
2 jmp(L3) INIT: in: {a=ID} out: {a=ID} USE: in: {a=WRITTEN_AFTER_READ} out: {a=WRITTEN_AFTER_READ}
|
||||
2 jmp?(L2) INIT: in: {a=ID} out: {a=ID}
|
||||
jmp(L3) USE: in: {a=WRITTEN_AFTER_READ} out: {a=WRITTEN_AFTER_READ}
|
||||
L2 [onExceptionToFinallyBlock]:
|
||||
L4 [start finally]:
|
||||
3 mark({ a = 5 }) INIT: in: {a=D} out: {a=D}
|
||||
r(5) -> <v2> USE: in: {a=ONLY_WRITTEN_NEVER_READ} out: {a=ONLY_WRITTEN_NEVER_READ}
|
||||
w(a|<v2>) INIT: in: {a=D} out: {a=ID} USE: in: {} out: {a=ONLY_WRITTEN_NEVER_READ}
|
||||
3 mark({ a = 5 }) INIT: in: {a=I?D} out: {a=I?D}
|
||||
r(5) -> <v2> USE: in: {a=ONLY_WRITTEN_NEVER_READ} out: {a=ONLY_WRITTEN_NEVER_READ}
|
||||
w(a|<v2>) INIT: in: {a=I?D} out: {a=ID} USE: in: {} out: {a=ONLY_WRITTEN_NEVER_READ}
|
||||
L5 [finish finally]:
|
||||
2 jmp(error) INIT: in: {a=ID} out: {a=ID} USE: in: {} out: {}
|
||||
2 jmp(error) INIT: in: {a=ID} out: {a=ID} USE: in: {} out: {}
|
||||
L3 [skipFinallyToErrorBlock]:
|
||||
L6 [copy of L2, onExceptionToFinallyBlock]:
|
||||
3 mark({ a = 5 })
|
||||
r(5) -> <v2> USE: in: {a=WRITTEN_AFTER_READ} out: {a=WRITTEN_AFTER_READ}
|
||||
w(a|<v2>) USE: in: {a=READ} out: {a=WRITTEN_AFTER_READ}
|
||||
r(5) -> <v2> USE: in: {a=WRITTEN_AFTER_READ} out: {a=WRITTEN_AFTER_READ}
|
||||
w(a|<v2>) USE: in: {a=READ} out: {a=WRITTEN_AFTER_READ}
|
||||
2 merge(try { a = 3 } finally { a = 5 }|!<v1>) -> <v4>
|
||||
mark(a.hashCode()) USE: in: {a=READ} out: {a=READ}
|
||||
r(a) -> <v5> USE: in: {} out: {a=READ}
|
||||
mark(a.hashCode()) USE: in: {a=READ} out: {a=READ}
|
||||
r(a) -> <v5> USE: in: {} out: {a=READ}
|
||||
mark(hashCode())
|
||||
call(hashCode(), hashCode|<v5>) -> <v6>
|
||||
L1:
|
||||
@@ -42,5 +43,5 @@ L1:
|
||||
error:
|
||||
<ERROR>
|
||||
sink:
|
||||
<SINK> USE: in: {} out: {}
|
||||
<SINK> USE: in: {} out: {}
|
||||
=====================
|
||||
|
||||
@@ -24,7 +24,9 @@ L0:
|
||||
3 mark({ foo() })
|
||||
mark(foo())
|
||||
call(foo(), foo) -> <v1>
|
||||
2 jmp(L4) USE: in: {} out: {}
|
||||
2 jmp?(L2)
|
||||
jmp?(L3)
|
||||
jmp(L4) USE: in: {} out: {}
|
||||
L2 [onException]:
|
||||
3 v(e: Exception) INIT: in: {} out: {e=D}
|
||||
magic[FAKE_INITIALIZER](e: Exception) -> <v2> INIT: in: {e=D} out: {e=D}
|
||||
@@ -59,4 +61,4 @@ error:
|
||||
<ERROR>
|
||||
sink:
|
||||
<SINK> USE: in: {} out: {}
|
||||
=====================
|
||||
=====================
|
||||
|
||||
Reference in New Issue
Block a user