Additional tests for KT-10243

This commit is contained in:
Mikhail Glukhikh
2015-12-01 20:53:39 +03:00
parent b9ce9f8576
commit ea3a65d0b8
14 changed files with 310 additions and 3 deletions
@@ -465,6 +465,7 @@ public class PseudocodeImpl implements Pseudocode {
return result;
}
// TODO: extract common part from repeatWhole and repeatPart
private void repeatWhole(PseudocodeImpl originalPseudocode) {
Map<Label, Label> originalToCopy = Maps.newLinkedHashMap();
Multimap<Instruction, Label> originalLabelsForInstruction = HashMultimap.create();
@@ -0,0 +1,96 @@
== x ==
var x: Int
---------------------
L0:
1 <START> INIT: in: {} out: {}
v(var x: Int) INIT: in: {} out: {x=D}
L1:
<END> INIT: in: {x=D} out: {x=D}
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {x=D} out: {x=D} USE: in: {} out: {}
=====================
== foo ==
fun foo(f: Boolean) {
try {
if (f) {
x = 0
}
}
finally {
fun bar() {}
}
}
---------------------
L0:
1 <START> INIT: in: {} out: {}
v(f: Boolean) INIT: in: {} out: {f=D}
magic[FAKE_INITIALIZER](f: Boolean) -> <v0> INIT: in: {f=D} out: {f=D}
w(f|<v0>) INIT: in: {f=D} out: {f=ID}
2 mark({ try { if (f) { x = 0 } } finally { fun bar() {} } }) INIT: in: {f=ID} out: {f=ID}
mark(try { if (f) { x = 0 } } finally { fun bar() {} })
jmp?(L2)
3 mark({ if (f) { x = 0 } })
mark(if (f) { x = 0 }) USE: in: {f=READ, x=ONLY_WRITTEN_NEVER_READ} out: {f=READ, x=ONLY_WRITTEN_NEVER_READ}
r(f) -> <v1> USE: in: {x=ONLY_WRITTEN_NEVER_READ} out: {f=READ, x=ONLY_WRITTEN_NEVER_READ}
jf(L3|<v1>)
4 mark({ x = 0 })
r(0) -> <v2> USE: in: {x=ONLY_WRITTEN_NEVER_READ} out: {x=ONLY_WRITTEN_NEVER_READ}
w(x|<v2>) INIT: in: {f=ID} out: {f=ID, x=I} USE: in: {} out: {x=ONLY_WRITTEN_NEVER_READ}
3 jmp(L4) INIT: in: {f=ID, x=I} out: {f=ID, x=I}
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)
L2 [onExceptionToFinallyBlock]:
L6 [start finally]:
3 mark({ fun bar() {} }) INIT: in: {f=ID} out: {f=ID}
jmp?(L7)
d(fun bar() {})
L7 [after local declaration]:
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}
jmp?(L12)
d(fun bar() {})
L12 [copy of L7, after local declaration]:
2 merge(try { if (f) { x = 0 } } finally { fun bar() {} }|<v4>) -> <v5>
L1:
1 <END>
error:
<ERROR> INIT: in: {f=ID} out: {f=ID}
sink:
<SINK> INIT: in: {f=ID, x=I} out: {f=ID, x=I} USE: in: {} out: {}
=====================
== bar ==
fun bar() {}
---------------------
L8:
4 <START> INIT: in: {f=ID} out: {f=ID}
5 mark({})
read (Unit)
L9:
4 <END>
error:
<ERROR> INIT: in: {} out: {}
sink:
<SINK> INIT: in: {f=ID} out: {f=ID} USE: in: {} out: {}
=====================
== bar ==
fun bar() {}
---------------------
L2 [copy of L8, null]:
4 <START> INIT: in: {f=ID, x=I} out: {f=ID, x=I}
5 mark({})
read (Unit)
L3 [copy of L9, null]:
4 <END>
L0 [copy of error, null]:
<ERROR> INIT: in: {} out: {}
L1 [copy of sink, null]:
<SINK> INIT: in: {f=ID, x=I} out: {f=ID, x=I} USE: in: {} out: {}
=====================
+11
View File
@@ -0,0 +1,11 @@
var x: Int
fun foo(f: Boolean) {
try {
if (f) {
x = 0
}
}
finally {
fun bar() {}
}
}
+34
View File
@@ -0,0 +1,34 @@
== x ==
var x: Int
---------------------
=====================
== foo ==
fun foo(f: Boolean) {
try {
if (f) {
x = 0
}
}
finally {
fun bar() {}
}
}
---------------------
<v0>: Boolean NEW: magic[FAKE_INITIALIZER](f: Boolean) -> <v0>
f <v1>: Boolean NEW: r(f) -> <v1>
0 <v2>: Int NEW: r(0) -> <v2>
x = 0 !<v3>: *
{ x = 0 } !<v3>: * COPY
if (f) { x = 0 } <v4>: * NEW: merge(if (f) { x = 0 }|!<v3>) -> <v4>
{ if (f) { x = 0 } } <v4>: * COPY
try { if (f) { x = 0 } } finally { fun bar() {} } <v5>: * NEW: merge(try { if (f) { x = 0 } } finally { fun bar() {} }|<v4>) -> <v5>
{ try { if (f) { x = 0 } } finally { fun bar() {} } } <v5>: * COPY
=====================
== bar ==
fun bar() {}
---------------------
=====================
== bar ==
fun bar() {}
---------------------
=====================
@@ -0,0 +1,78 @@
== foo ==
fun foo(): Int {
var i = 0
try {
i = 1
}
finally {
fun bar() {}
return i
}
}
---------------------
L0:
1 <START>
2 mark({ var i = 0 try { i = 1 } finally { fun bar() {} return i } })
v(var i = 0)
r(0) -> <v0>
w(i|<v0>)
mark(try { i = 1 } finally { fun bar() {} return i })
jmp?(L2) NEXT:[mark({ fun bar() {} return i }), mark({ i = 1 })]
3 mark({ i = 1 })
r(1) -> <v1>
w(i|<v1>)
2 jmp(L3) NEXT:[mark({ fun bar() {} return i })]
L2 [onExceptionToFinallyBlock]:
L4 [start finally]:
3 mark({ fun bar() {} return i }) PREV:[jmp?(L2)]
jmp?(L5) NEXT:[r(i) -> <v3>, d(fun bar() {})]
d(fun bar() {}) NEXT:[<SINK>]
L5 [after local declaration]:
r(i) -> <v3> PREV:[jmp?(L5)]
ret(*|<v3>) L1 NEXT:[<END>]
L8 [finish finally]:
- 2 jmp(error) NEXT:[<ERROR>] PREV:[]
L3 [skipFinallyToErrorBlock]:
L9 [copy of L2, onExceptionToFinallyBlock]:
3 mark({ fun bar() {} return i }) PREV:[jmp(L3)]
jmp?(L10) NEXT:[r(i) -> <v3>, d(fun bar() {})]
d(fun bar() {}) NEXT:[<SINK>]
L10 [copy of L5, after local declaration]:
r(i) -> <v3> PREV:[jmp?(L10)]
ret(*|<v3>) L1 NEXT:[<END>]
- 2 merge(try { i = 1 } finally { fun bar() {} return i }|!<v2>) -> <v5> PREV:[]
L1:
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v3>) L1, ret(*|<v3>) L1]
error:
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>, d(fun bar() {}), d(fun bar() {})]
=====================
== bar ==
fun bar() {}
---------------------
L6:
4 <START>
5 mark({})
read (Unit)
L7:
4 <END> NEXT:[<SINK>]
error:
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>]
=====================
== bar ==
fun bar() {}
---------------------
L2 [copy of L6, null]:
4 <START>
5 mark({})
read (Unit)
L3 [copy of L7, null]:
4 <END> NEXT:[<SINK>]
L0 [copy of error, null]:
<ERROR> PREV:[]
L1 [copy of sink, null]:
<SINK> PREV:[<ERROR>, <END>]
=====================
@@ -0,0 +1,10 @@
fun foo(): Int {
var i = 0
try {
i = 1
}
finally {
fun bar() {}
return i
}
}
@@ -0,0 +1,30 @@
== foo ==
fun foo(): Int {
var i = 0
try {
i = 1
}
finally {
fun bar() {}
return i
}
}
---------------------
0 <v0>: Int NEW: r(0) -> <v0>
1 <v1>: Int NEW: r(1) -> <v1>
i = 1 !<v2>: *
{ i = 1 } !<v2>: * COPY
i <v3>: Int NEW: r(i) -> <v3>
return i !<v4>: *
{ fun bar() {} return i } !<v4>: * COPY
try { i = 1 } finally { fun bar() {} return i } <v5>: * NEW: merge(try { i = 1 } finally { fun bar() {} return i }|!<v2>) -> <v5>
{ var i = 0 try { i = 1 } finally { fun bar() {} return i } } <v5>: * COPY
=====================
== bar ==
fun bar() {}
---------------------
=====================
== bar ==
fun bar() {}
---------------------
=====================
@@ -0,0 +1,11 @@
<!MUST_BE_INITIALIZED!>var x: Int<!>
fun foo(f: Boolean) {
try {
if (f) {
x = 0
}
}
finally {
fun bar() {}
}
}
@@ -0,0 +1,4 @@
package
public var x: kotlin.Int
public fun foo(/*0*/ f: kotlin.Boolean): kotlin.Unit
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.cfg;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.text.StringUtil;
import kotlin.jvm.functions.Function3;
@@ -53,7 +55,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
File file = new File(fileName);
KtFile jetFile = KotlinTestUtils.loadJetFile(getProject(), file);
Map<KtElement, Pseudocode> data = new LinkedHashMap<KtElement, Pseudocode>();
SetMultimap<KtElement, Pseudocode> data = LinkedHashMultimap.create();
AnalysisResult analysisResult = KotlinTestUtils.analyzeFile(jetFile, getEnvironment());
List<KtDeclaration> declarations = jetFile.getDeclarations();
BindingContext bindingContext = analysisResult.getBindingContext();
@@ -83,7 +85,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
}
}
private static void addDeclaration(Map<KtElement, Pseudocode> data, BindingContext bindingContext, KtDeclaration declaration) {
private static void addDeclaration(SetMultimap<KtElement, Pseudocode> data, BindingContext bindingContext, KtDeclaration declaration) {
Pseudocode pseudocode = PseudocodeUtil.generatePseudocode(declaration, bindingContext);
data.put(declaration, pseudocode);
for (LocalFunctionDeclarationInstruction instruction : pseudocode.getLocalDeclarations()) {
@@ -92,7 +94,7 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
}
}
private void processCFData(File file, Map<KtElement, Pseudocode> data, BindingContext bindingContext) throws IOException {
private void processCFData(File file, SetMultimap<KtElement, Pseudocode> data, BindingContext bindingContext) throws IOException {
Collection<Pseudocode> pseudocodes = data.values();
StringBuilder instructionDump = new StringBuilder();
@@ -214,6 +214,12 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
doTest(fileName);
}
@TestMetadata("localFunctionInFinally.kt")
public void testLocalFunctionInFinally() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/localFunctionInFinally.kt");
doTest(fileName);
}
@TestMetadata("OnlyWhileInFunctionBody.kt")
public void testOnlyWhileInFunctionBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/OnlyWhileInFunctionBody.kt");
@@ -88,6 +88,12 @@ public class DataFlowTestGenerated extends AbstractDataFlowTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg-variables/bugs"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("kt10243.kt")
public void testKt10243() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/bugs/kt10243.kt");
doTest(fileName);
}
@TestMetadata("referenceToPropertyInitializer.kt")
public void testReferenceToPropertyInitializer() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.kt");
@@ -216,6 +216,12 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
doTest(fileName);
}
@TestMetadata("localFunctionInFinally.kt")
public void testLocalFunctionInFinally() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/localFunctionInFinally.kt");
doTest(fileName);
}
@TestMetadata("OnlyWhileInFunctionBody.kt")
public void testOnlyWhileInFunctionBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/OnlyWhileInFunctionBody.kt");
@@ -810,6 +816,12 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg-variables/bugs"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("kt10243.kt")
public void testKt10243() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/bugs/kt10243.kt");
doTest(fileName);
}
@TestMetadata("referenceToPropertyInitializer.kt")
public void testReferenceToPropertyInitializer() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg-variables/bugs/referenceToPropertyInitializer.kt");
@@ -12558,6 +12558,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt10243a.kt")
public void testKt10243a() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt10243a.kt");
doTest(fileName);
}
@TestMetadata("kt127.kt")
public void testKt127() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt127.kt");