Files
kotlin-fork/compiler/testData/cfg-variables/bugs/varInitializationInIfInCycle.instructions
T
Denis Zharkov 02b40326cc Fix incorrect coroutines codegen behavior
If all the suspension calls in a suspend function were "hidden"
under the for-convention (iterator/next/hasNext) calls,
control-flow didn't find them, thus supposing that there is no
suspension points and there is no need to generate a coroutine state machine

The solution is to add relevant calls to CFG

 #KT-15824 Fixed
2017-01-25 13:54:01 +03:00

87 lines
6.3 KiB
Plaintext
Vendored

== foo ==
fun foo(numbers: Collection<Int>) {
for (i in numbers) {
val b: Boolean
if (1 < 2) {
b = false
}
else {
b = true
}
use(b)
continue
}
}
---------------------
L0:
1 <START> INIT: in: {} out: {}
v(numbers: Collection<Int>) INIT: in: {} out: {numbers=D}
magic[FAKE_INITIALIZER](numbers: Collection<Int>) -> <v0> INIT: in: {numbers=D} out: {numbers=D}
w(numbers|<v0>) INIT: in: {numbers=D} out: {numbers=ID}
2 mark({ for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue } }) INIT: in: {numbers=ID} out: {numbers=ID} USE: in: {numbers=READ} out: {numbers=READ}
3 r(numbers) -> <v1> USE: in: {} out: {numbers=READ}
mark(numbers)
call(numbers, iterator|<v1>) -> <v2>
v(i) INIT: in: {numbers=ID} out: {i=D, numbers=ID}
L2 [loop entry point]:
L6 [condition entry point]:
mark(numbers) INIT: in: {i=I?D, numbers=ID} out: {i=I?D, numbers=ID}
call(numbers, hasNext) -> <v3>
jmp?(L3)
mark(numbers)
call(numbers, next) -> <v4>
magic[LOOP_RANGE_ITERATION](numbers|<v4>) -> <v5>
w(i|<v5>) INIT: in: {i=I?D, numbers=ID} out: {i=ID, numbers=ID}
mark(for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue }) INIT: in: {i=ID, numbers=ID} out: {i=ID, numbers=ID} USE: in: {} out: {}
L4 [body entry point]:
4 mark({ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue })
v(val b: Boolean) INIT: in: {i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
mark(if (1 < 2) { b = false } else { b = true }) INIT: in: {b=D, i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
r(1) -> <v6>
r(2) -> <v7>
mark(1 < 2)
call(1 < 2, compareTo|<v6>, <v7>) -> <v8>
jf(L7|<v8>)
5 mark({ b = false })
r(false) -> <v9> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
w(b|<v9>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
4 jmp(L8) INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=READ}
L7 [else branch]:
5 mark({ b = true }) INIT: in: {b=D, i=ID, numbers=ID} out: {b=D, i=ID, numbers=ID}
r(true) -> <v11> USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ}
w(b|<v11>) INIT: in: {b=D, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ}
L8 ['if' expression result]:
4 merge(if (1 < 2) { b = false } else { b = true }|!<v10>, !<v12>) -> <v13> INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} USE: in: {b=READ} out: {b=READ}
r(b) -> <v14> USE: in: {} out: {b=READ}
mark(use(b))
call(use(b), use|<v14>) -> <v15>
jmp(L6) USE: in: {} out: {}
- 3 jmp(L2)
L3 [loop exit point]:
L5 [body exit point]:
read (Unit) INIT: in: {i=I?D, numbers=ID} out: {i=I?D, numbers=ID}
L1:
1 <END> INIT: in: {numbers=ID} out: {numbers=ID}
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {numbers=I?} out: {numbers=I?} USE: in: {} out: {}
=====================
== use ==
fun use(vararg a: Any?) = a
---------------------
L0:
1 <START> INIT: in: {} out: {}
v(vararg a: Any?) INIT: in: {} out: {a=D}
magic[FAKE_INITIALIZER](vararg a: Any?) -> <v0> INIT: in: {a=D} out: {a=D}
w(a|<v0>) INIT: in: {a=D} out: {a=ID} USE: in: {a=READ} out: {a=READ}
r(a) -> <v1> INIT: in: {a=ID} out: {a=ID} USE: in: {} out: {a=READ}
ret(*|<v1>) L1
L1:
<END>
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {a=I?} out: {a=I?} USE: in: {} out: {}
=====================