[FIR] Fix cfg crash with multiple postponed arguments

This commit is contained in:
simon.ogorodnik
2020-05-13 16:43:43 +03:00
parent 5b63dad1c3
commit 86683e94fc
5 changed files with 162 additions and 1 deletions
@@ -0,0 +1,115 @@
digraph complexPostponedCfg_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter class FirBase" style="filled" fillcolor=red];
1 [label="Exit class FirBase" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter class FirFunctionCall" style="filled" fillcolor=red];
3 [label="Exit class FirFunctionCall" style="filled" fillcolor=red];
}
2 -> {3} [color=green];
subgraph cluster_2 {
color=red
4 [label="Enter function foo" style="filled" fillcolor=red];
6 [label="Access variable R|<local>/statements|"];
7 [label="Function call: R|<local>/statements|.R|kotlin/collections/last|<R|FirBase|>()"];
8 [label="Type operator: (R|<local>/statements|.R|kotlin/collections/last|<R|FirBase|>() as R|FirFunctionCall|)"];
9 [label="Postponed enter to lambda"];
subgraph cluster_3 {
color=blue
19 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
21 [label="Postponed enter to lambda"];
subgraph cluster_4 {
color=blue
24 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
26 [label="Access variable this@R|special/anonymous|"];
27 [label="Function call: this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(...)"];
28 [label="Access variable R|<local>/arguments|"];
29 [label="Function call: R|<local>/arguments|.R|kotlin/collections/last|<R|FirBase|>()"];
30 [label="Type operator: (R|<local>/arguments|.R|kotlin/collections/last|<R|FirBase|>() as R|FirFunctionCall|)"];
31 [label="Postponed enter to lambda"];
subgraph cluster_5 {
color=blue
35 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
37 [label="Access variable this@R|special/anonymous|"];
38 [label="Function call: this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(...)"];
39 [label="Access variable R|<local>/explicitReceiver|"];
40 [label="Type operator: (R|<local>/explicitReceiver| as R|FirFunctionCall|)"];
41 [label="Function call: this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(...)"];
36 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
34 [label="Call arguments union" style="filled" fillcolor=yellow];
32 [label="Postponed exit from lambda"];
33 [label="Function call: R|kotlin/with|<R|FirFunctionCall|, R|kotlin/Boolean|>(...)"];
25 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
22 [label="Postponed exit from lambda"];
23 [label="Function call: R|kotlin/collections/buildList|<R|kotlin/Any?|>(...)"];
20 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
12 [label="Call arguments union" style="filled" fillcolor=yellow];
10 [label="Postponed exit from lambda"];
11 [label="Function call: R|kotlin/with|<R|FirFunctionCall|, R|kotlin/Nothing|>(...)"];
13 [label="Stub" style="filled" fillcolor=gray];
14 [label="Variable declaration: lval firstCalls: R|kotlin/Nothing|" style="filled" fillcolor=gray];
15 [label="Access variable R|<local>/firstCalls|" style="filled" fillcolor=gray];
16 [label="Stub" style="filled" fillcolor=gray];
17 [label="Jump: ^foo R|<local>/firstCalls|" style="filled" fillcolor=gray];
18 [label="Stub" style="filled" fillcolor=gray];
5 [label="Exit function foo" style="filled" fillcolor=red];
}
4 -> {6};
6 -> {7};
7 -> {8};
8 -> {9};
9 -> {19};
9 -> {10} [color=red];
10 -> {11} [color=green];
11 -> {5};
11 -> {13} [style=dotted];
12 -> {11};
13 -> {14} [style=dotted];
14 -> {15} [style=dotted];
15 -> {5 16} [style=dotted];
16 -> {17} [style=dotted];
17 -> {5 18} [style=dotted];
18 -> {5} [style=dotted];
19 -> {21};
20 -> {10} [color=green];
20 -> {12} [color=red];
21 -> {24};
21 -> {22} [color=red];
22 -> {23};
23 -> {20};
24 -> {26};
25 -> {22} [color=green];
25 -> {12} [color=red];
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {35};
31 -> {32} [color=red];
32 -> {33} [color=green];
33 -> {25};
34 -> {33} [color=red];
35 -> {37};
36 -> {32} [color=green];
36 -> {34} [color=red];
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {36};
}
@@ -0,0 +1,20 @@
// !DUMP_CFG
interface FirBase
interface FirFunctionCall : FirBase
fun foo(statements: List<FirBase>, arguments: List<FirBase>, explicitReceiver: FirBase): List<FirFunctionCall> {
val firstCalls = with(statements.last() as FirFunctionCall) setCall@{
buildList {
add(this@setCall)
with(arguments.last() as FirFunctionCall) plusCall@{
add(this@plusCall)
add(explicitReceiver as FirFunctionCall)
}
}
}
return firstCalls
}
@@ -0,0 +1,20 @@
FILE: complexPostponedCfg.kt
public abstract interface FirBase : R|kotlin/Any| {
}
public abstract interface FirFunctionCall : R|FirBase| {
}
public final fun foo(statements: R|kotlin/collections/List<FirBase>|, arguments: R|kotlin/collections/List<FirBase>|, explicitReceiver: R|FirBase|): R|kotlin/collections/List<FirFunctionCall>| {
lval firstCalls: R|kotlin/Nothing| = R|kotlin/with|<R|FirFunctionCall|, R|kotlin/Nothing|>((R|<local>/statements|.R|kotlin/collections/last|<R|FirBase|>() as R|FirFunctionCall|), <L> = setCall@fun R|FirFunctionCall|.<anonymous>(): R|kotlin/Nothing| <kind=EXACTLY_ONCE> {
^ R|kotlin/collections/buildList|<R|kotlin/Any?|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/Any?>|.<anonymous>(): R|kotlin/Unit| <kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(this@R|special/anonymous|)
^ R|kotlin/with|<R|FirFunctionCall|, R|kotlin/Boolean|>((R|<local>/arguments|.R|kotlin/collections/last|<R|FirBase|>() as R|FirFunctionCall|), <L> = plusCall@fun R|FirFunctionCall|.<anonymous>(): R|kotlin/Boolean| <kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(this@R|special/anonymous|)
^ this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|((R|<local>/explicitReceiver| as R|FirFunctionCall|))
}
)
}
)
}
)
^foo R|<local>/firstCalls|
}
@@ -68,6 +68,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/companionLoad.kt");
}
@TestMetadata("complexPostponedCfg.kt")
public void testComplexPostponedCfg() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.kt");
}
@TestMetadata("components.kt")
public void testComponents() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/components.kt");
@@ -758,11 +758,12 @@ class ControlFlowGraphBuilder {
var hasPostponedLambdas = false
val iterator = exitsFromCompletedPostponedAnonymousFunctions.iterator()
val lastPostponedLambdaExitNode = lastNode
while (iterator.hasNext()) {
val exitNode = iterator.next()
if (node.level >= exitNode.level) continue
hasPostponedLambdas = true
if (exitNode == lastNode) {
if (exitNode == lastPostponedLambdaExitNode) {
addEdge(lastNodes.pop(), node, preferredKind = EdgeKind.Cfg)
kind = EdgeKind.Dfg
hasDirectPreviousNode = true