From e34385bbcfb7a166c8d9d95197fbdbbcfb106562 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 5 Mar 2014 17:28:07 +0400 Subject: [PATCH] added tests to DataFlowTest to be able to compare difference in the next commit --- .../basic/varInitializationInIf.instructions | 42 +++++++++++ .../basic/varInitializationInIf.kt | 10 +++ .../varInitializationInIfInCycle.instructions | 74 +++++++++++++++++++ .../basic/varInitializationInIfInCycle.kt | 15 ++++ .../jet/cfg/DataFlowTestGenerated.java | 10 +++ 5 files changed, 151 insertions(+) create mode 100644 compiler/testData/cfg-variables/basic/varInitializationInIf.instructions create mode 100644 compiler/testData/cfg-variables/basic/varInitializationInIf.kt create mode 100644 compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.instructions create mode 100644 compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.kt diff --git a/compiler/testData/cfg-variables/basic/varInitializationInIf.instructions b/compiler/testData/cfg-variables/basic/varInitializationInIf.instructions new file mode 100644 index 00000000000..3d0d82db2a7 --- /dev/null +++ b/compiler/testData/cfg-variables/basic/varInitializationInIf.instructions @@ -0,0 +1,42 @@ +== foo == +fun foo() { + val b: Boolean + if (1 < 2) { + b = false + } + else { + b = true + } + use(b) +} +--------------------- +L0: + 1 INIT: in: {} out: {} USE: in: {} out: {} + 2 mark({ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) }) + v(val b: Boolean) INIT: in: {} out: {b=D} + mark(if (1 < 2) { b = false } else { b = true }) INIT: in: {b=D} out: {b=D} + mark(1 < 2) + r(1) + r(2) + call(<, compareTo) + jf(L2) + 3 mark({ b = false }) + r(false) USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ} + w(b) INIT: in: {b=D} out: {b=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ} + 2 jmp(L3) INIT: in: {b=ID} out: {b=ID} USE: in: {b=READ} out: {b=READ} +L2: + 3 mark({ b = true }) INIT: in: {b=D} out: {b=D} + r(true) USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ} + w(b) INIT: in: {b=D} out: {b=ID} USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ} +L3: + 2 mark(use(b)) INIT: in: {b=ID} out: {b=ID} + error(use, No resolved call) USE: in: {b=READ} out: {b=READ} + r(b) USE: in: {} out: {b=READ} + error(use, No resolved call) +L1: + 1 INIT: in: {} out: {} +error: + +sink: + USE: in: {} out: {} +===================== diff --git a/compiler/testData/cfg-variables/basic/varInitializationInIf.kt b/compiler/testData/cfg-variables/basic/varInitializationInIf.kt new file mode 100644 index 00000000000..104866f104c --- /dev/null +++ b/compiler/testData/cfg-variables/basic/varInitializationInIf.kt @@ -0,0 +1,10 @@ +fun foo() { + val b: Boolean + if (1 < 2) { + b = false + } + else { + b = true + } + use(b) +} \ No newline at end of file diff --git a/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.instructions b/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.instructions new file mode 100644 index 00000000000..8e155925d3a --- /dev/null +++ b/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.instructions @@ -0,0 +1,74 @@ +== foo == +fun foo(numbers: Collection) { + for (i in numbers) { + val b: Boolean + if (1 < 2) { + b = false + } + else { + b = true + } + use(b) + continue + } +} +--------------------- +L0: + 1 INIT: in: {} out: {} + v(numbers: Collection) INIT: in: {} out: {numbers=D} + w(numbers) 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} + 3 mark(for (i in numbers) { val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue }) USE: in: {numbers=READ} out: {numbers=READ} + r(numbers) USE: in: {} out: {numbers=READ} + v(i) INIT: in: {numbers=ID} out: {i=D, numbers=ID} + w(i) INIT: in: {i=D, numbers=ID} out: {i=ID, numbers=ID} +L3: + jmp?(L2) INIT: in: {i=ID, numbers=ID} out: {i=ID, numbers=ID} USE: in: {} out: {} +L4 [loop entry point]: +L5 [body entry point]: + 4 mark({ val b: Boolean if (1 < 2) { b = false } else { b = true } use(b) continue }) INIT: in: {b=ID, i=ID, numbers=ID} out: {b=ID, i=ID, numbers=ID} + v(val b: Boolean) + mark(if (1 < 2) { b = false } else { b = true }) + mark(1 < 2) + r(1) + r(2) + call(<, compareTo) + jf(L6) + 5 mark({ b = false }) + r(false) USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ} + w(b) USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ} + 4 jmp(L7) USE: in: {b=READ} out: {b=READ} +L6: + 5 mark({ b = true }) + r(true) USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ} + w(b) USE: in: {b=READ} out: {b=WRITTEN_AFTER_READ} +L7: + 4 mark(use(b)) USE: in: {b=READ} out: {b=READ} + r(b) USE: in: {b=WRITTEN_AFTER_READ} out: {b=READ} + call(use, use) + jmp(L4 [loop entry point]) USE: in: {b=WRITTEN_AFTER_READ} out: {b=WRITTEN_AFTER_READ} +- 3 jmp?(L4 [loop entry point]) +L2: + read (Unit) INIT: in: {i=ID, numbers=ID} out: {i=ID, numbers=ID} +L1: + 1 INIT: in: {numbers=ID} out: {numbers=ID} +error: + INIT: in: {} out: {} +sink: + INIT: in: {numbers=ID} out: {numbers=ID} USE: in: {} out: {} +===================== +== use == +fun use(vararg a: Any?) = a +--------------------- +L0: + 1 INIT: in: {} out: {} + v(vararg a: Any?) INIT: in: {} out: {a=D} + w(a) INIT: in: {a=D} out: {a=ID} USE: in: {a=READ} out: {a=READ} + r(a) INIT: in: {a=ID} out: {a=ID} USE: in: {} out: {a=READ} +L1: + +error: + INIT: in: {} out: {} +sink: + INIT: in: {a=ID} out: {a=ID} USE: in: {} out: {} +===================== diff --git a/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.kt b/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.kt new file mode 100644 index 00000000000..bb151e3e0e2 --- /dev/null +++ b/compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.kt @@ -0,0 +1,15 @@ +fun foo(numbers: Collection) { + for (i in numbers) { + val b: Boolean + if (1 < 2) { + b = false + } + else { + b = true + } + use(b) + continue + } +} + +fun use(vararg a: Any?) = a \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/cfg/DataFlowTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/DataFlowTestGenerated.java index 51eef61cc4a..47b66d18485 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/DataFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/DataFlowTestGenerated.java @@ -58,6 +58,16 @@ public class DataFlowTestGenerated extends AbstractDataFlowTest { doTest("compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.kt"); } + @TestMetadata("varInitializationInIf.kt") + public void testVarInitializationInIf() throws Exception { + doTest("compiler/testData/cfg-variables/basic/varInitializationInIf.kt"); + } + + @TestMetadata("varInitializationInIfInCycle.kt") + public void testVarInitializationInIfInCycle() throws Exception { + doTest("compiler/testData/cfg-variables/basic/varInitializationInIfInCycle.kt"); + } + @TestMetadata("VariablesInitialization.kt") public void testVariablesInitialization() throws Exception { doTest("compiler/testData/cfg-variables/basic/VariablesInitialization.kt");