From 6427117a352802661552379cd8c200a3563eb195 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Sun, 7 Mar 2021 00:15:31 -0800 Subject: [PATCH] FIR CFG: correct edge label from a node that returns Nothing If it's not within a try/catch/finally, that should be an uncaught exception path. ^KT-45327 Fixed --- .../testData/resolve/cfg/initBlock.dot | 2 +- .../testData/resolve/cfg/jumps.dot | 2 +- .../resolve/cfg/lambdaReturningObject.dot | 2 +- .../resolve/cfg/propertiesAndInitBlocks.dot | 8 ++++---- .../resolve/cfg/returnValuesFromLambda.dot | 3 ++- .../booleans/jumpFromRhsOfOperator.dot | 16 ++++++++-------- .../resolve/smartcasts/safeCalls/safeCalls.dot | 3 ++- .../resolve/smartcasts/smartCastInInit.dot | 2 +- .../resolve/smartcasts/smartcastToNothing.dot | 10 ++++++---- .../resolve/dfa/cfg/ControlFlowGraphBuilder.kt | 11 +++++++---- .../testsWithStdLib/exitProcess.fir.kt | 14 -------------- .../diagnostics/testsWithStdLib/exitProcess.kt | 1 + 12 files changed, 34 insertions(+), 40 deletions(-) delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/exitProcess.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot index 4bf2b71657b..ee2c51db490 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot @@ -84,7 +84,7 @@ digraph initBlock_kt { 20 -> {21}; 21 -> {22}; 22 -> {23}; - 23 -> {28}; + 23 -> {28} [label=onUncaughtException]; 23 -> {24} [style=dotted]; 24 -> {25} [style=dotted]; 25 -> {26} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/jumps.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/jumps.dot index eaa243f263c..a341c6384b3 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/jumps.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/jumps.dot @@ -72,7 +72,7 @@ digraph jumps_kt { 15 -> {16}; 16 -> {17}; 17 -> {18}; - 18 -> {29}; + 18 -> {29} [label=onUncaughtException]; 18 -> {19} [style=dotted]; 19 -> {20} [style=dotted]; 20 -> {21} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot index 91aaf50e616..48013f56aa8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot @@ -63,7 +63,7 @@ digraph lambdaReturningObject_kt { } 13 -> {14}; 14 -> {15}; - 15 -> {20}; + 15 -> {20} [label=onUncaughtException]; 15 -> {16} [style=dotted]; 16 -> {17} [style=dotted]; 17 -> {20 18} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot index 3cce0048a67..3fdae526eb5 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot @@ -107,7 +107,7 @@ digraph propertiesAndInitBlocks_kt { 41 -> {42}; 42 -> {43}; 43 -> {44}; - 44 -> {47}; + 44 -> {47} [label=onUncaughtException]; 44 -> {45} [style=dotted]; 45 -> {46} [style=dotted]; 46 -> {47} [style=dotted]; @@ -138,7 +138,7 @@ digraph propertiesAndInitBlocks_kt { 51 -> {52}; 52 -> {53}; 53 -> {54}; - 54 -> {58}; + 54 -> {58} [label=onUncaughtException]; 54 -> {55} [style=dotted]; 55 -> {56} [style=dotted]; 56 -> {57} [style=dotted]; @@ -199,7 +199,7 @@ digraph propertiesAndInitBlocks_kt { 70 -> {71}; 71 -> {72}; 72 -> {73}; - 73 -> {76}; + 73 -> {76} [label=onUncaughtException]; 73 -> {74} [style=dotted]; 74 -> {75} [style=dotted]; 75 -> {76} [style=dotted]; @@ -246,7 +246,7 @@ digraph propertiesAndInitBlocks_kt { 28 -> {48 34} [color=green]; 28 -> {48 34} [style=dashed]; 29 -> {30}; - 30 -> {81}; + 30 -> {81} [label=onUncaughtException]; 30 -> {31} [style=dotted]; 31 -> {32} [style=dotted]; 32 -> {33} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot index 8a7bf68bdbf..398d20ba9db 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot @@ -204,7 +204,8 @@ digraph returnValuesFromLambda_kt { 57 -> {65} [style=dashed]; 58 -> {60} [style=dotted]; 59 -> {60} [style=dotted]; - 60 -> {64 61} [style=dotted]; + 60 -> {61} [style=dotted]; + 60 -> {64} [style=dotted] [label=onUncaughtException]; 61 -> {62} [style=dotted]; 62 -> {63} [style=dotted]; 63 -> {64} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans/jumpFromRhsOfOperator.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans/jumpFromRhsOfOperator.dot index 2bbb0e62ef3..ad72544a661 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans/jumpFromRhsOfOperator.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/booleans/jumpFromRhsOfOperator.dot @@ -51,7 +51,7 @@ digraph jumpFromRhsOfOperator_kt { 10 -> {15 11}; 11 -> {12}; 12 -> {13}; - 13 -> {19}; + 13 -> {19} [label=onUncaughtException]; 13 -> {14} [style=dotted]; 14 -> {15} [style=dotted]; 15 -> {16}; @@ -93,7 +93,7 @@ digraph jumpFromRhsOfOperator_kt { 26 -> {31 27}; 27 -> {28}; 28 -> {29}; - 29 -> {35}; + 29 -> {35} [label=onUncaughtException]; 29 -> {30} [style=dotted]; 30 -> {31} [style=dotted]; 31 -> {32}; @@ -157,7 +157,7 @@ digraph jumpFromRhsOfOperator_kt { 44 -> {49 45}; 45 -> {46}; 46 -> {47}; - 47 -> {62}; + 47 -> {62} [label=onUncaughtException]; 47 -> {48} [style=dotted]; 48 -> {49} [style=dotted]; 49 -> {50}; @@ -230,7 +230,7 @@ digraph jumpFromRhsOfOperator_kt { 71 -> {76 72}; 72 -> {73}; 73 -> {74}; - 74 -> {89}; + 74 -> {89} [label=onUncaughtException]; 74 -> {75} [style=dotted]; 75 -> {76} [style=dotted]; 76 -> {77}; @@ -281,7 +281,7 @@ digraph jumpFromRhsOfOperator_kt { 96 -> {101 97}; 97 -> {98}; 98 -> {99}; - 99 -> {105}; + 99 -> {105} [label=onUncaughtException]; 99 -> {100} [style=dotted]; 100 -> {101} [style=dotted]; 101 -> {102}; @@ -323,7 +323,7 @@ digraph jumpFromRhsOfOperator_kt { 112 -> {117 113}; 113 -> {114}; 114 -> {115}; - 115 -> {121}; + 115 -> {121} [label=onUncaughtException]; 115 -> {116} [style=dotted]; 116 -> {117} [style=dotted]; 117 -> {118}; @@ -387,7 +387,7 @@ digraph jumpFromRhsOfOperator_kt { 130 -> {135 131}; 131 -> {132}; 132 -> {133}; - 133 -> {148}; + 133 -> {148} [label=onUncaughtException]; 133 -> {134} [style=dotted]; 134 -> {135} [style=dotted]; 135 -> {136}; @@ -460,7 +460,7 @@ digraph jumpFromRhsOfOperator_kt { 157 -> {162 158}; 158 -> {159}; 159 -> {160}; - 160 -> {175}; + 160 -> {175} [label=onUncaughtException]; 160 -> {161} [style=dotted]; 161 -> {162} [style=dotted]; 162 -> {163}; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot index f72046cfd61..8d27fad946d 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot @@ -286,7 +286,8 @@ digraph safeCalls_kt { 92 -> {107} [style=dashed]; 93 -> {95} [style=dotted]; 94 -> {95} [style=dotted]; - 95 -> {106 96} [style=dotted]; + 95 -> {96} [style=dotted]; + 95 -> {106} [style=dotted] [label=onUncaughtException]; 96 -> {97} [style=dotted]; 97 -> {98 102}; 98 -> {99}; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot index e8cc2cb5027..8426e250ced 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot @@ -40,7 +40,7 @@ digraph smartCastInInit_kt { } 6 -> {7}; 7 -> {8}; - 8 -> {13}; + 8 -> {13} [label=onUncaughtException]; 8 -> {9} [style=dotted]; 9 -> {10} [style=dotted]; 10 -> {13 11} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot index b99487dfc0d..a27549dd671 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot @@ -21,7 +21,7 @@ digraph smartcastToNothing_kt { 0 -> {1}; 1 -> {2}; 2 -> {3}; - 3 -> {8}; + 3 -> {8} [label=onUncaughtException]; 3 -> {4} [style=dotted]; 4 -> {5} [style=dotted]; 5 -> {8 6} [style=dotted]; @@ -273,16 +273,18 @@ digraph smartcastToNothing_kt { 67 -> {68}; 68 -> {69}; 69 -> {70}; - 70 -> {101}; + 70 -> {101} [label=onUncaughtException]; 70 -> {71} [style=dotted]; 71 -> {72} [style=dotted]; 72 -> {73} [style=dotted]; - 73 -> {101 74} [style=dotted]; + 73 -> {74} [style=dotted]; + 73 -> {101} [style=dotted] [label=onUncaughtException]; 74 -> {75} [style=dotted]; 75 -> {76} [style=dotted]; 76 -> {77} [style=dotted]; 77 -> {78} [style=dotted]; - 78 -> {101 79} [style=dotted]; + 78 -> {79} [style=dotted]; + 78 -> {101} [style=dotted] [label=onUncaughtException]; 79 -> {80} [style=dotted]; 80 -> {81} [style=dotted]; 81 -> {83 82} [style=dotted]; diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index 57a6ce22eb3..fd354370ae7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -1249,14 +1249,17 @@ class ControlFlowGraphBuilder { private fun addNodeThatReturnsNothing(node: CFGNode<*>, preferredKind: EdgeKind = EdgeKind.Forward) { val exitNode: CFGNode<*> = exitTargetsForTry.top() - addNodeWithJump(node, exitNode, preferredKind) + // If an expression, which returns Nothing, isn't inside a try/catch/finally, that is an uncaught exception path. + val label = if (tryExitNodes.isEmpty) UncaughtExceptionPath else NormalPath + addNodeWithJump(node, exitNode, preferredKind, label = label) } private fun addNodeWithJump( node: CFGNode<*>, targetNode: CFGNode<*>?, preferredKind: EdgeKind = EdgeKind.Forward, - isBack: Boolean = false + isBack: Boolean = false, + label: EdgeLabel = NormalPath, ) { popAndAddEdge(node, preferredKind) if (targetNode != null) { @@ -1265,10 +1268,10 @@ class ControlFlowGraphBuilder { // `continue` to the loop header addBackEdge(node, targetNode, label = LoopBackPath) } else { - addBackEdge(node, targetNode) + addBackEdge(node, targetNode, label = label) } } else { - addEdge(node, targetNode, propagateDeadness = false) + addEdge(node, targetNode, propagateDeadness = false, label = label) } } val stub = createStubNode() diff --git a/compiler/testData/diagnostics/testsWithStdLib/exitProcess.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/exitProcess.fir.kt deleted file mode 100644 index b3359c0135a..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/exitProcess.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -import java.io.File -import kotlin.system.exitProcess - -object Main { - private val KOTLIN_HOME: File - - init { - val home = System.getProperty("kotlin.home") - if (home == null) { - exitProcess(1) - } - KOTLIN_HOME = File(home) - } -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/exitProcess.kt b/compiler/testData/diagnostics/testsWithStdLib/exitProcess.kt index 65688ab47ca..e103caf148d 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/exitProcess.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/exitProcess.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL import java.io.File import kotlin.system.exitProcess -- GitLab