Skip to content

Commit 6ae03e6

Browse files
committed
Rust: Add case for ParenExpr in CFG
1 parent 7e8da94 commit 6ae03e6

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import codeql.controlflow.Cfg
55
private import SuccessorType as ST
66
private import Scope as Scope
77

8-
module CfgInput implements InputSig<Location> {
8+
private module CfgInput implements InputSig<Location> {
99
private import rust as Rust
1010
private import Completion as C
1111
private import Splitting as S
@@ -387,6 +387,10 @@ class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr
387387

388388
class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { }
389389

390+
class ParenExprTree extends StandardPostOrderTree, ParenExpr {
391+
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
392+
}
393+
390394
// This covers all patterns as they all extend `Pat`
391395
class PatExprTree extends LeafTree instanceof Pat { }
392396

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,49 @@
149149
| test.rs:79:28:81:9 | BlockExpr | test.rs:79:9:81:9 | IfExpr | |
150150
| test.rs:80:13:80:13 | PathExpr | test.rs:79:28:81:9 | BlockExpr | |
151151
| test.rs:82:9:82:9 | LiteralExpr | test.rs:78:43:83:5 | BlockExpr | |
152+
| test.rs:85:5:91:5 | enter test_nested_if | test.rs:86:16:86:16 | PathExpr | |
153+
| test.rs:85:5:91:5 | exit test_nested_if (normal) | test.rs:85:5:91:5 | exit test_nested_if | |
154+
| test.rs:85:38:91:5 | BlockExpr | test.rs:85:5:91:5 | exit test_nested_if (normal) | |
155+
| test.rs:86:9:90:9 | IfExpr | test.rs:85:38:91:5 | BlockExpr | |
156+
| test.rs:86:12:86:48 | ParenExpr | test.rs:87:13:87:13 | LiteralExpr | true |
157+
| test.rs:86:12:86:48 | ParenExpr | test.rs:89:13:89:13 | LiteralExpr | false |
158+
| test.rs:86:13:86:47 | IfExpr | test.rs:86:12:86:48 | ParenExpr | |
159+
| test.rs:86:16:86:16 | PathExpr | test.rs:86:20:86:20 | LiteralExpr | |
160+
| test.rs:86:16:86:20 | BinaryExpr | test.rs:86:24:86:24 | PathExpr | true |
161+
| test.rs:86:16:86:20 | BinaryExpr | test.rs:86:41:86:41 | PathExpr | false |
162+
| test.rs:86:20:86:20 | LiteralExpr | test.rs:86:16:86:20 | BinaryExpr | |
163+
| test.rs:86:22:86:32 | BlockExpr | test.rs:86:13:86:47 | IfExpr | |
164+
| test.rs:86:24:86:24 | PathExpr | test.rs:86:29:86:30 | LiteralExpr | |
165+
| test.rs:86:24:86:30 | BinaryExpr | test.rs:86:22:86:32 | BlockExpr | |
166+
| test.rs:86:28:86:30 | PrefixExpr | test.rs:86:24:86:30 | BinaryExpr | |
167+
| test.rs:86:29:86:30 | LiteralExpr | test.rs:86:28:86:30 | PrefixExpr | |
168+
| test.rs:86:39:86:47 | BlockExpr | test.rs:86:13:86:47 | IfExpr | |
169+
| test.rs:86:41:86:41 | PathExpr | test.rs:86:45:86:46 | LiteralExpr | |
170+
| test.rs:86:41:86:46 | BinaryExpr | test.rs:86:39:86:47 | BlockExpr | |
171+
| test.rs:86:45:86:46 | LiteralExpr | test.rs:86:41:86:46 | BinaryExpr | |
172+
| test.rs:86:50:88:9 | BlockExpr | test.rs:86:9:90:9 | IfExpr | |
173+
| test.rs:87:13:87:13 | LiteralExpr | test.rs:86:50:88:9 | BlockExpr | |
174+
| test.rs:88:16:90:9 | BlockExpr | test.rs:86:9:90:9 | IfExpr | |
175+
| test.rs:89:13:89:13 | LiteralExpr | test.rs:88:16:90:9 | BlockExpr | |
176+
| test.rs:93:5:99:5 | enter test_nested_if_match | test.rs:94:19:94:19 | PathExpr | |
177+
| test.rs:93:5:99:5 | exit test_nested_if_match (normal) | test.rs:93:5:99:5 | exit test_nested_if_match | |
178+
| test.rs:93:44:99:5 | BlockExpr | test.rs:93:5:99:5 | exit test_nested_if_match (normal) | |
179+
| test.rs:94:9:98:9 | IfExpr | test.rs:93:44:99:5 | BlockExpr | |
180+
| test.rs:94:12:94:46 | ParenExpr | test.rs:95:13:95:13 | LiteralExpr | true |
181+
| test.rs:94:12:94:46 | ParenExpr | test.rs:97:13:97:13 | LiteralExpr | false |
182+
| test.rs:94:13:94:45 | MatchExpr | test.rs:94:12:94:46 | ParenExpr | |
183+
| test.rs:94:19:94:19 | PathExpr | test.rs:94:23:94:23 | LiteralPat | |
184+
| test.rs:94:23:94:23 | LiteralPat | test.rs:94:13:94:45 | MatchExpr | no-match |
185+
| test.rs:94:23:94:23 | LiteralPat | test.rs:94:28:94:31 | LiteralExpr | match |
186+
| test.rs:94:23:94:23 | LiteralPat | test.rs:94:34:94:34 | WildcardPat | no-match |
187+
| test.rs:94:28:94:31 | LiteralExpr | test.rs:94:13:94:45 | MatchExpr | |
188+
| test.rs:94:34:94:34 | WildcardPat | test.rs:94:13:94:45 | MatchExpr | no-match |
189+
| test.rs:94:34:94:34 | WildcardPat | test.rs:94:39:94:43 | LiteralExpr | match |
190+
| test.rs:94:39:94:43 | LiteralExpr | test.rs:94:13:94:45 | MatchExpr | |
191+
| test.rs:94:48:96:9 | BlockExpr | test.rs:94:9:98:9 | IfExpr | |
192+
| test.rs:95:13:95:13 | LiteralExpr | test.rs:94:48:96:9 | BlockExpr | |
193+
| test.rs:96:16:98:9 | BlockExpr | test.rs:94:9:98:9 | IfExpr | |
194+
| test.rs:97:13:97:13 | LiteralExpr | test.rs:96:16:98:9 | BlockExpr | |
152195
| test.rs:105:5:108:5 | enter test_and_operator | test.rs:106:9:106:28 | LetStmt | |
153196
| test.rs:105:5:108:5 | exit test_and_operator (normal) | test.rs:105:5:108:5 | exit test_and_operator | |
154197
| test.rs:105:61:108:5 | BlockExpr | test.rs:105:5:108:5 | exit test_and_operator (normal) | |
@@ -181,8 +224,15 @@
181224
| test.rs:116:9:116:36 | LetStmt | test.rs:116:17:116:35 | BinaryExpr | |
182225
| test.rs:116:13:116:13 | IdentPat | test.rs:117:9:117:9 | PathExpr | match, no-match |
183226
| test.rs:116:17:116:17 | PathExpr | test.rs:116:13:116:13 | IdentPat | true |
227+
| test.rs:116:17:116:17 | PathExpr | test.rs:116:23:116:23 | PathExpr | false |
184228
| test.rs:116:17:116:30 | BinaryExpr | test.rs:116:17:116:17 | PathExpr | |
185229
| test.rs:116:17:116:35 | BinaryExpr | test.rs:116:17:116:30 | BinaryExpr | |
230+
| test.rs:116:22:116:30 | ParenExpr | test.rs:116:13:116:13 | IdentPat | true |
231+
| test.rs:116:22:116:30 | ParenExpr | test.rs:116:35:116:35 | PathExpr | false |
232+
| test.rs:116:23:116:23 | PathExpr | test.rs:116:28:116:29 | LiteralExpr | |
233+
| test.rs:116:23:116:29 | BinaryExpr | test.rs:116:22:116:30 | ParenExpr | |
234+
| test.rs:116:28:116:29 | LiteralExpr | test.rs:116:23:116:29 | BinaryExpr | |
235+
| test.rs:116:35:116:35 | PathExpr | test.rs:116:13:116:13 | IdentPat | |
186236
| test.rs:117:9:117:9 | PathExpr | test.rs:115:61:118:5 | BlockExpr | |
187237
| test.rs:122:1:128:1 | enter test_match | test.rs:123:11:123:21 | PathExpr | |
188238
| test.rs:122:1:128:1 | exit test_match (normal) | test.rs:122:1:128:1 | exit test_match | |

shared/controlflow/codeql/controlflow/Cfg.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,14 @@ module Make<LocationSig Location, InputSig<Location> Input> {
12731273
string getOrderDisambiguation() { result = "" }
12741274
}
12751275

1276-
import TestOutput<RelevantNode>
1277-
import Mermaid
1276+
private module Output = TestOutput<RelevantNode>;
1277+
1278+
import Output::Mermaid
1279+
1280+
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
1281+
attr = "semmle.label" and
1282+
Output::edges(pred, succ, val)
1283+
}
12781284
}
12791285

12801286
/** Provides a set of consistency queries. */

0 commit comments

Comments
 (0)