- Notifications
You must be signed in to change notification settings - Fork1.7k
Java: Add AnnotatedExitNodes to the CFG.#19885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -82,6 +82,7 @@ module; | ||
*/ | ||
import java | ||
private import codeql.util.Boolean | ||
private import Completion | ||
private import controlflow.internal.Preconditions | ||
private import controlflow.internal.SwitchCases | ||
@@ -102,6 +103,7 @@ module ControlFlow { | ||
private newtype TNode = | ||
TExprNode(Expr e) { hasControlFlow(e) } or | ||
TStmtNode(Stmt s) or | ||
TAnnotatedExitNode(Callable c, Boolean normal) { exists(c.getBody()) } or | ||
TExitNode(Callable c) { exists(c.getBody()) } or | ||
TAssertThrowNode(AssertStmt s) | ||
@@ -191,6 +193,38 @@ module ControlFlow { | ||
override Location getLocation() { result = s.getLocation() } | ||
} | ||
/** A control flow node indicating the normal or exceptional termination of a callable. */ | ||
class AnnotatedExitNode extends Node, TAnnotatedExitNode { | ||
Callable c; | ||
boolean normal; | ||
AnnotatedExitNode() { this = TAnnotatedExitNode(c, normal) } | ||
override Callable getEnclosingCallable() { result = c } | ||
override ExprParent getAstNode() { result = c } | ||
/** Gets a textual representation of this element. */ | ||
override string toString() { | ||
normal = true and result = "Normal Exit" | ||
or | ||
normal = false and result = "Exceptional Exit" | ||
} | ||
/** Gets the source location for this element. */ | ||
override Location getLocation() { result = c.getLocation() } | ||
} | ||
/** A control flow node indicating normal termination of a callable. */ | ||
class NormalExitNode extends AnnotatedExitNode { | ||
NormalExitNode() { this = TAnnotatedExitNode(_, true) } | ||
} | ||
/** A control flow node indicating exceptional termination of a callable. */ | ||
class ExceptionalExitNode extends AnnotatedExitNode { | ||
ExceptionalExitNode() { this = TAnnotatedExitNode(_, false) } | ||
} | ||
/** A control flow node indicating the termination of a callable. */ | ||
class ExitNode extends Node, TExitNode { | ||
Callable c; | ||
@@ -1266,11 +1300,17 @@ private module ControlFlowGraphImpl { | ||
*/ | ||
cached | ||
Node succ(Node n, Completion completion) { | ||
// After executing the callable body, the final nodes are first the | ||
// annotated exit node and then the final exit node. | ||
exists(Callable c | last(c.getBody(), n, completion) | | ||
if completion instanceof ThrowCompletion | ||
then result.(ExceptionalExitNode).getEnclosingCallable() = c | ||
else result.(NormalExitNode).getEnclosingCallable() = c | ||
aschackmull marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
) | ||
or | ||
completion = NormalCompletion() and | ||
n.(AnnotatedExitNode).getEnclosingCallable() = result.(ExitNode).getEnclosingCallable() | ||
or | ||
// Logic expressions and conditional expressions execute in AST pre-order. | ||
completion = NormalCompletion() and | ||
( | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletionjava/ql/test-kotlin1/library-tests/controlflow/basic/bbStmts.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletionsjava/ql/test-kotlin1/library-tests/controlflow/basic/bbStrictDominance.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 28 additions & 15 deletionsjava/ql/test-kotlin1/library-tests/controlflow/basic/bbSuccessor.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,58 @@ | ||
| Test.kt:3:8:80:1 | Exceptional Exit | Test.kt:3:8:80:1 | Exit | | ||
| Test.kt:3:8:80:1 | { ... } | Test.kt:3:8:80:1 | Exit | | ||
| Test.kt:4:2:79:2 | Exceptional Exit | Test.kt:4:2:79:2 | Exit | | ||
| Test.kt:4:2:79:2 | Normal Exit | Test.kt:4:2:79:2 | Exit | | ||
| Test.kt:4:13:79:2 | { ... } | Test.kt:11:3:16:3 | ... -> ... | | ||
| Test.kt:4:13:79:2 | { ... } | Test.kt:11:14:14:3 | { ... } | | ||
| Test.kt:11:3:16:3 | ... -> ... | Test.kt:18:3:18:3 | <Expr>; | | ||
| Test.kt:11:14:14:3 | { ... } | Test.kt:18:3:18:3 | <Expr>; | | ||
| Test.kt:18:3:18:3 | <Expr>; | Test.kt:21:3:24:9 | ... -> ... | | ||
| Test.kt:18:3:18:3 | <Expr>; | Test.kt:22:4:22:4 | <Expr>; | | ||
| Test.kt:21:3:24:9 | ... -> ... | Test.kt:4:2:79:2 |NormalExit | | ||
| Test.kt:22:4:22:4 | <Expr>; | Test.kt:30:15:33:3 | { ... } | | ||
| Test.kt:22:4:22:4 | <Expr>; | Test.kt:35:3:35:3 | <Expr>; | | ||
| Test.kt:30:15:33:3 | { ... } | Test.kt:35:3:35:3 | <Expr>; | | ||
| Test.kt:35:3:35:3 | <Expr>; | Test.kt:38:9:38:9 | x | | ||
| Test.kt:38:9:38:9 | x | Test.kt:38:16:41:3 | { ... } | | ||
| Test.kt:38:9:38:9 | x | Test.kt:43:3:43:3 | <Expr>; | | ||
| Test.kt:38:16:41:3 | { ... } | Test.kt:38:9:38:9 | x | | ||
| Test.kt:43:3:43:3 | <Expr>; | Test.kt:4:2:79:2 | Normal Exit | | ||
| Test.kt:82:1:89:1 | Exceptional Exit | Test.kt:82:1:89:1 | Exit | | ||
| Test.kt:82:1:89:1 | Normal Exit | Test.kt:82:1:89:1 | Exit | | ||
| Test.kt:82:21:89:1 | { ... } | Test.kt:84:7:84:7 | x | | ||
| Test.kt:82:21:89:1 | { ... } | Test.kt:86:4:88:2 | catch (...) | | ||
| Test.kt:84:7:84:7 | x | Test.kt:82:1:89:1 | Normal Exit | | ||
| Test.kt:86:4:88:2 | catch (...) | Test.kt:82:1:89:1 | Normal Exit | | ||
| Test.kt:91:1:98:1 | Exceptional Exit | Test.kt:91:1:98:1 | Exit | | ||
| Test.kt:91:1:98:1 | Normal Exit | Test.kt:91:1:98:1 | Exit | | ||
| Test.kt:91:22:98:1 | { ... } | Test.kt:93:7:93:7 | x | | ||
| Test.kt:91:22:98:1 | { ... } | Test.kt:95:4:97:2 | catch (...) | | ||
| Test.kt:93:7:93:7 | x | Test.kt:91:1:98:1 | Normal Exit | | ||
| Test.kt:95:4:97:2 | catch (...) | Test.kt:91:1:98:1 | Normal Exit | | ||
| Test.kt:100:1:110:1 | Normal Exit | Test.kt:100:1:110:1 | Exit | | ||
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:22 | y | | ||
| Test.kt:100:25:110:1 | { ... } | Test.kt:105:5:109:5 | <Expr>; | | ||
| Test.kt:101:22:101:22 | y | Test.kt:101:33:103:5 | { ... } | | ||
| Test.kt:101:22:101:22 | y | Test.kt:105:5:109:5 | <Expr>; | | ||
| Test.kt:101:33:103:5 | { ... } | Test.kt:100:1:110:1 | Exit | | ||
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:105:20:107:5 | { ... } | | ||
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:107:16:109:5 | ... -> ... | | ||
| Test.kt:105:20:107:5 | { ... } | Test.kt:100:1:110:1 |NormalExit | | ||
| Test.kt:107:16:109:5 | ... -> ... | Test.kt:100:1:110:1 |NormalExit | | ||
| Test.kt:107:16:109:5 | ... -> ... | Test.kt:107:27:109:5 | { ... } | | ||
| Test.kt:107:27:109:5 | { ... } | Test.kt:100:1:110:1 | Normal Exit | | ||
| Test.kt:112:1:116:1 | Exceptional Exit | Test.kt:112:1:116:1 | Exit | | ||
| Test.kt:112:1:116:1 | Normal Exit | Test.kt:112:1:116:1 | Exit | | ||
| Test.kt:112:32:116:1 | { ... } | Test.kt:112:1:116:1 | Normal Exit | | ||
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | y | | ||
| Test.kt:113:14:113:14 | y | Test.kt:112:1:116:1 |NormalExit | | ||
| Test.kt:113:14:113:14 | y | Test.kt:113:17:115:5 | { ... } | | ||
| Test.kt:113:17:115:5 | { ... } | Test.kt:112:1:116:1 | Normal Exit | | ||
| Test.kt:118:1:124:1 | Exceptional Exit | Test.kt:118:1:124:1 | Exit | | ||
| Test.kt:118:1:124:1 | Normal Exit | Test.kt:118:1:124:1 | Exit | | ||
| Test.kt:118:37:124:1 | { ... } | Test.kt:121:9:121:9 | <Expr>; | | ||
| Test.kt:118:37:124:1 | { ... } | Test.kt:122:12:122:16 | ... -> ... | | ||
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:118:1:124:1 |NormalExit | | ||
| Test.kt:121:9:121:9 | <Expr>; | Test.kt:123:8:123:10 | { ... } | | ||
| Test.kt:122:12:122:16 | ... -> ... | Test.kt:118:1:124:1 |NormalExit | | ||
| Test.kt:123:8:123:10 | { ... } | Test.kt:118:1:124:1 |NormalExit | |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.