FIR CFG: add edges from try/catch to finally

This commit is contained in:
Jinseong Jeon
2020-10-07 00:19:29 -07:00
committed by Dmitriy Novozhilov
parent ea2f773e54
commit 43852ad7ab
4 changed files with 28 additions and 16 deletions
@@ -283,25 +283,25 @@ digraph propertiesAndInitBlocks_kt {
} }
subgraph cluster_29 { subgraph cluster_29 {
color=blue color=blue
91 [label="Enter finally"]; 91 [label="Catch enter"];
subgraph cluster_30 { subgraph cluster_30 {
color=blue color=blue
92 [label="Enter block"]; 92 [label="Enter block"];
93 [label="Const: Int(0)"]; 93 [label="Const: Int(2)"];
94 [label="Exit block"]; 94 [label="Exit block"];
} }
95 [label="Exit finally"]; 95 [label="Catch exit"];
} }
subgraph cluster_31 { subgraph cluster_31 {
color=blue color=blue
96 [label="Catch enter"]; 96 [label="Enter finally"];
subgraph cluster_32 { subgraph cluster_32 {
color=blue color=blue
97 [label="Enter block"]; 97 [label="Enter block"];
98 [label="Const: Int(2)"]; 98 [label="Const: Int(0)"];
99 [label="Exit block"]; 99 [label="Exit block"];
} }
100 [label="Catch exit"]; 100 [label="Exit finally"];
} }
101 [label="Try expression exit"]; 101 [label="Try expression exit"];
} }
@@ -309,17 +309,17 @@ digraph propertiesAndInitBlocks_kt {
} }
84 -> {85}; 84 -> {85};
85 -> {86}; 85 -> {86};
86 -> {102 96 91 87}; 86 -> {102 91 96 87};
87 -> {88}; 87 -> {88};
88 -> {89}; 88 -> {89};
89 -> {90}; 89 -> {90};
90 -> {101}; 90 -> {96};
91 -> {92}; 91 -> {102 92};
92 -> {93}; 92 -> {93};
93 -> {94}; 93 -> {94};
94 -> {95}; 94 -> {95};
95 -> {101}; 95 -> {96};
96 -> {102 97}; 96 -> {97};
97 -> {98}; 97 -> {98};
98 -> {99}; 98 -> {99};
99 -> {100}; 99 -> {100};
@@ -110,7 +110,7 @@ finally {
18 -> {19}; 18 -> {19};
19 -> {20}; 19 -> {20};
20 -> {21}; 20 -> {21};
21 -> {26}; 21 -> {22};
22 -> {23}; 22 -> {23};
23 -> {24}; 23 -> {24};
24 -> {25}; 24 -> {25};
@@ -198,7 +198,7 @@ finally {
43 -> {44}; 43 -> {44};
44 -> {45}; 44 -> {45};
45 -> {46}; 45 -> {46};
46 -> {51}; 46 -> {47};
47 -> {48}; 47 -> {48};
48 -> {49}; 48 -> {49};
49 -> {50}; 49 -> {50};
@@ -804,7 +804,13 @@ class ControlFlowGraphBuilder {
levelCounter-- levelCounter--
val node = createTryMainBlockExitNode(tryExpression) val node = createTryMainBlockExitNode(tryExpression)
popAndAddEdge(node) popAndAddEdge(node)
addEdge(node, tryExitNodes.top()) val finallyEnterNode = finallyEnterNodes.topOrNull()
// NB: Check the level to avoid adding an edge to the finally block at an upper level.
if (finallyEnterNode != null && finallyEnterNode.level == levelCounter + 1) {
addEdge(node, finallyEnterNode)
} else {
addEdge(node, tryExitNodes.top())
}
return node return node
} }
@@ -816,7 +822,13 @@ class ControlFlowGraphBuilder {
levelCounter-- levelCounter--
return createCatchClauseExitNode(catch).also { return createCatchClauseExitNode(catch).also {
popAndAddEdge(it) popAndAddEdge(it)
addEdge(it, tryExitNodes.top(), propagateDeadness = false) val finallyEnterNode = finallyEnterNodes.topOrNull()
// NB: Check the level to avoid adding an edge to the finally block at an upper level.
if (finallyEnterNode != null && finallyEnterNode.level == levelCounter + 1) {
addEdge(it, finallyEnterNode, propagateDeadness = false)
} else {
addEdge(it, tryExitNodes.top(), propagateDeadness = false)
}
} }
} }
@@ -45,7 +45,7 @@ fun outerFinallyInitializes() {
} }
// Properly initialized // Properly initialized
<!UNINITIALIZED_VARIABLE!>x<!>.inc() x.inc()
} }
fun innerFinallyInitializes() { fun innerFinallyInitializes() {