Skip to content

Commit

Permalink
Rust: Accept expected changes and fix other CI complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Jan 3, 2025
1 parent cd957ba commit 5c64a8c
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 19 deletions.
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ final class CallExprCfgNode extends CallExprBaseCfgNode, Nodes::CallExprCfgNode
final class FormatArgsExprCfgNode extends Nodes::FormatArgsExprCfgNode {
private FormatArgsExprChildMapping node;

FormatArgsExprCfgNode() { node = this.getAstNode() }

/** Gets the `i`th argument of this format arguments expression (0-based). */
ExprCfgNode getArgumentExpr(int i) {
any(ChildMapping mapping).hasCfgChild(node, node.getArg(i).getExpr(), this, result)
}

/** Gets a format argument of the `i`th format of this format arguments expression (0-based). */
FormatTemplateVariableAccessCfgNode getFormatTemplateVariableAccess(int i) {
exists(FormatTemplateVariableAccess v |
v.getArgument() = node.getFormat(i).getArgument() and
Expand All @@ -199,11 +203,18 @@ final class FormatArgsExprCfgNode extends Nodes::FormatArgsExprCfgNode {
}
}

/**
* A MacroCall. For example:
* ```rust
* todo!()
* ```
*/
final class MacroCallCfgNode extends Nodes::MacroCallCfgNode {
private MacroCallChildMapping node;

MacroCallCfgNode() { node = this.getAstNode() }

/** Gets the CFG node for the expansion of this macro call, if it exists. */
CfgNode getExpandedNode() {
any(ChildMapping mapping).hasCfgChild(node, node.getExpanded(), this, result)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| gen_format.rs:5:21:5:22 | {} | getParent: | gen_format.rs:5:14:5:32 | FormatArgsExpr | getIndex: | 1 | hasArgument: | no |
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | getParent: | gen_format.rs:7:14:7:47 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes |
| gen_format_args_arg.rs:5:26:5:27 | {} | getParent: | gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | getIndex: | 1 | hasArgument: | no |
| gen_format_args_expr.rs:6:19:6:20 | {} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 1 | hasArgument: | no |
| gen_format_args_expr.rs:6:26:6:29 | {:?} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 3 | hasArgument: | no |
| gen_format_args_expr.rs:7:19:7:21 | {b} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
| gen_format.rs:5:26:5:32 | FormatArgsArg | hasExpr: | yes | hasName: | no |
| gen_format_args_arg.rs:5:32:5:38 | FormatArgsArg | hasExpr: | yes | hasName: | no |
| gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg | hasExpr: | yes | hasName: | no |
| gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg | hasExpr: | yes | hasName: | no |
| gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | hasExpr: | yes | hasName: | yes |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
| gen_format.rs:5:26:5:32 | FormatArgsArg | gen_format.rs:5:26:5:32 | "world" |
| gen_format_args_arg.rs:5:32:5:38 | FormatArgsArg | gen_format_args_arg.rs:5:32:5:38 | "world" |
| gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg | gen_format_args_expr.rs:6:33:6:33 | 1 |
| gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg | gen_format_args_expr.rs:6:36:6:36 | 2 |
| gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | gen_format_args_expr.rs:7:37:7:37 | 1 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| gen_format.rs:5:14:5:32 | FormatArgsExpr | getNumberOfArgs: | 1 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 |
| gen_format.rs:7:14:7:47 | FormatArgsExpr | getNumberOfArgs: | 0 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 |
| gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | getNumberOfArgs: | 1 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 |
| gen_format_args_expr.rs:5:17:5:27 | FormatArgsExpr | getNumberOfArgs: | 0 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 0 |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getNumberOfArgs: | 2 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 2 |
| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getNumberOfArgs: | 2 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 2 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
| gen_format.rs:5:14:5:32 | FormatArgsExpr | 0 | gen_format.rs:5:26:5:32 | FormatArgsArg |
| gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | 0 | gen_format_args_arg.rs:5:32:5:38 | FormatArgsArg |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 0 | gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 1 | gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg |
| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 0 | gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| gen_format.rs:5:14:5:32 | FormatArgsExpr | 0 | gen_format.rs:5:21:5:22 | {} |
| gen_format.rs:7:14:7:47 | FormatArgsExpr | 0 | gen_format.rs:7:21:7:46 | {value:#width$.precision$} |
| gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | 0 | gen_format_args_arg.rs:5:26:5:27 | {} |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 0 | gen_format_args_expr.rs:6:19:6:20 | {} |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 1 | gen_format_args_expr.rs:6:26:6:29 | {:?} |
| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 0 | gen_format_args_expr.rs:7:19:7:21 | {b} |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
| gen_format.rs:5:14:5:32 | FormatArgsExpr | gen_format.rs:5:14:5:23 | "Hello {}\\n" |
| gen_format.rs:7:14:7:47 | FormatArgsExpr | gen_format.rs:7:14:7:47 | "Value {value:#width$.precisio... |
| gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | gen_format_args_arg.rs:5:18:5:29 | "Hello, {}!" |
| gen_format_args_expr.rs:5:17:5:27 | FormatArgsExpr | gen_format_args_expr.rs:5:18:5:26 | "no args" |
| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | gen_format_args_expr.rs:6:18:6:30 | "{} foo {:?}" |
| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | gen_format_args_expr.rs:7:18:7:32 | "{b} foo {a:?}" |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
| gen_format.rs:7:22:7:26 | value | getParent: | gen_format.rs:7:21:7:46 | {value:#width$.precision$} | hasVariable: | yes |
| gen_format.rs:7:29:7:33 | width | getParent: | gen_format.rs:7:21:7:46 | {value:#width$.precision$} | hasVariable: | yes |
| gen_format.rs:7:36:7:44 | precision | getParent: | gen_format.rs:7:21:7:46 | {value:#width$.precision$} | hasVariable: | yes |
| gen_format_args_expr.rs:7:20:7:20 | b | getParent: | gen_format_args_expr.rs:7:19:7:21 | {b} | hasVariable: | no |
| gen_format_args_expr.rs:7:28:7:28 | a | getParent: | gen_format_args_expr.rs:7:27:7:31 | {a:?} | hasVariable: | no |
| gen_format_args_expr.rs:9:20:9:20 | x | getParent: | gen_format_args_expr.rs:9:19:9:21 | {x} | hasVariable: | yes |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
| gen_format.rs:7:22:7:26 | value | gen_format.rs:7:22:7:26 | value |
| gen_format.rs:7:29:7:33 | width | gen_format.rs:7:29:7:33 | width |
| gen_format.rs:7:36:7:44 | precision | gen_format.rs:7:36:7:44 | precision |
| gen_format_args_expr.rs:9:20:9:20 | x | gen_format_args_expr.rs:9:20:9:20 | x |
| gen_format_args_expr.rs:9:25:9:25 | y | gen_format_args_expr.rs:9:25:9:25 | y |
| gen_format_argument.rs:5:22:5:26 | value | gen_format_argument.rs:5:22:5:26 | value |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
| gen_format.rs:7:22:7:26 | value |
| gen_format.rs:7:29:7:33 | width |
| gen_format.rs:7:36:7:44 | precision |
| gen_format_args_expr.rs:9:20:9:20 | x |
| gen_format_args_expr.rs:9:25:9:25 | y |
| gen_format_argument.rs:5:22:5:26 | value |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:22:7:26 | value |
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:29:7:33 | width |
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:36:7:44 | precision |
| gen_format_args_expr.rs:7:19:7:21 | {b} | gen_format_args_expr.rs:7:20:7:20 | b |
| gen_format_args_expr.rs:7:27:7:31 | {a:?} | gen_format_args_expr.rs:7:28:7:28 | a |
| gen_format_args_expr.rs:9:19:9:21 | {x} | gen_format_args_expr.rs:9:20:9:20 | x |
Expand Down
33 changes: 22 additions & 11 deletions rust/ql/test/library-tests/controlflow/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -752,15 +752,18 @@ edges
| test.rs:344:23:344:23 | a | test.rs:344:13:344:19 | Some(...) | |
| test.rs:344:32:344:54 | ...::panic_fmt | test.rs:344:39:344:53 | "Expected some" | |
| test.rs:344:32:344:54 | MacroExpr | test.rs:344:30:344:56 | { ... } | |
| test.rs:344:32:344:54 | panic!... | test.rs:344:32:344:54 | MacroExpr | |
| test.rs:344:39:344:53 | "Expected some" | test.rs:344:39:344:53 | FormatArgsExpr | |
| test.rs:344:39:344:53 | ...::const_format_args!... | test.rs:344:39:344:53 | MacroExpr | |
| test.rs:344:39:344:53 | ...::panic_2021!... | test.rs:344:39:344:53 | MacroExpr | |
| test.rs:344:39:344:53 | ...::panic_fmt(...) | test.rs:344:39:344:53 | { ... } | |
| test.rs:344:39:344:53 | ExprStmt | test.rs:344:32:344:54 | ...::panic_fmt | |
| test.rs:344:39:344:53 | FormatArgsExpr | test.rs:344:39:344:53 | MacroExpr | |
| test.rs:344:39:344:53 | MacroExpr | test.rs:344:32:344:54 | MacroExpr | |
| test.rs:344:39:344:53 | FormatArgsExpr | test.rs:344:39:344:53 | ...::const_format_args!... | |
| test.rs:344:39:344:53 | MacroExpr | test.rs:344:32:344:54 | panic!... | |
| test.rs:344:39:344:53 | MacroExpr | test.rs:344:39:344:53 | ...::panic_fmt(...) | |
| test.rs:344:39:344:53 | MacroStmts | test.rs:344:39:344:53 | ExprStmt | |
| test.rs:344:39:344:53 | MacroStmts | test.rs:344:39:344:53 | MacroStmts | |
| test.rs:344:39:344:53 | { ... } | test.rs:344:39:344:53 | MacroExpr | |
| test.rs:344:39:344:53 | { ... } | test.rs:344:39:344:53 | ...::panic_2021!... | |
| test.rs:345:9:345:9 | n | test.rs:343:46:346:5 | { ... } | |
| test.rs:348:5:354:5 | enter fn test_let_with_return | test.rs:348:29:348:29 | m | |
| test.rs:348:5:354:5 | exit fn test_let_with_return (normal) | test.rs:348:5:354:5 | exit fn test_let_with_return | |
Expand Down Expand Up @@ -835,14 +838,16 @@ edges
| test.rs:392:26:394:5 | { ... } | test.rs:392:5:394:5 | exit fn say_hello (normal) | |
| test.rs:393:9:393:33 | ...::_print | test.rs:393:18:393:32 | "hello, world!\\n" | |
| test.rs:393:9:393:33 | MacroExpr | test.rs:392:26:394:5 | { ... } | |
| test.rs:393:9:393:33 | println!... | test.rs:393:9:393:33 | MacroExpr | |
| test.rs:393:9:393:34 | ExprStmt | test.rs:393:18:393:32 | MacroStmts | |
| test.rs:393:18:393:32 | "hello, world!\\n" | test.rs:393:18:393:32 | FormatArgsExpr | |
| test.rs:393:18:393:32 | ...::_print(...) | test.rs:393:18:393:32 | { ... } | |
| test.rs:393:18:393:32 | ...::format_args_nl!... | test.rs:393:18:393:32 | MacroExpr | |
| test.rs:393:18:393:32 | ExprStmt | test.rs:393:9:393:33 | ...::_print | |
| test.rs:393:18:393:32 | FormatArgsExpr | test.rs:393:18:393:32 | MacroExpr | |
| test.rs:393:18:393:32 | FormatArgsExpr | test.rs:393:18:393:32 | ...::format_args_nl!... | |
| test.rs:393:18:393:32 | MacroExpr | test.rs:393:18:393:32 | ...::_print(...) | |
| test.rs:393:18:393:32 | MacroStmts | test.rs:393:18:393:32 | ExprStmt | |
| test.rs:393:18:393:32 | { ... } | test.rs:393:9:393:33 | MacroExpr | |
| test.rs:393:18:393:32 | { ... } | test.rs:393:9:393:33 | println!... | |
| test.rs:396:5:415:5 | enter fn async_block | test.rs:396:26:396:26 | b | |
| test.rs:396:5:415:5 | exit fn async_block (normal) | test.rs:396:5:415:5 | exit fn async_block | |
| test.rs:396:26:396:26 | b | test.rs:396:26:396:32 | ...: bool | match |
Expand All @@ -855,29 +860,33 @@ edges
| test.rs:397:26:399:9 | { ... } | test.rs:397:13:397:22 | say_godbye | |
| test.rs:398:13:398:41 | ...::_print | test.rs:398:22:398:40 | "godbye, everyone!\\n" | |
| test.rs:398:13:398:41 | MacroExpr | test.rs:397:26:399:9 | exit { ... } (normal) | |
| test.rs:398:13:398:41 | println!... | test.rs:398:13:398:41 | MacroExpr | |
| test.rs:398:13:398:42 | ExprStmt | test.rs:398:22:398:40 | MacroStmts | |
| test.rs:398:22:398:40 | "godbye, everyone!\\n" | test.rs:398:22:398:40 | FormatArgsExpr | |
| test.rs:398:22:398:40 | ...::_print(...) | test.rs:398:22:398:40 | { ... } | |
| test.rs:398:22:398:40 | ...::format_args_nl!... | test.rs:398:22:398:40 | MacroExpr | |
| test.rs:398:22:398:40 | ExprStmt | test.rs:398:13:398:41 | ...::_print | |
| test.rs:398:22:398:40 | FormatArgsExpr | test.rs:398:22:398:40 | MacroExpr | |
| test.rs:398:22:398:40 | FormatArgsExpr | test.rs:398:22:398:40 | ...::format_args_nl!... | |
| test.rs:398:22:398:40 | MacroExpr | test.rs:398:22:398:40 | ...::_print(...) | |
| test.rs:398:22:398:40 | MacroStmts | test.rs:398:22:398:40 | ExprStmt | |
| test.rs:398:22:398:40 | { ... } | test.rs:398:13:398:41 | MacroExpr | |
| test.rs:398:22:398:40 | { ... } | test.rs:398:13:398:41 | println!... | |
| test.rs:400:9:402:10 | let ... = ... | test.rs:400:31:402:9 | { ... } | |
| test.rs:400:13:400:27 | say_how_are_you | test.rs:403:9:403:28 | let ... = ... | match |
| test.rs:400:31:402:9 | enter { ... } | test.rs:401:13:401:37 | ExprStmt | |
| test.rs:400:31:402:9 | exit { ... } (normal) | test.rs:400:31:402:9 | exit { ... } | |
| test.rs:400:31:402:9 | { ... } | test.rs:400:13:400:27 | say_how_are_you | |
| test.rs:401:13:401:36 | ...::_print | test.rs:401:22:401:35 | "how are you?\\n" | |
| test.rs:401:13:401:36 | MacroExpr | test.rs:400:31:402:9 | exit { ... } (normal) | |
| test.rs:401:13:401:36 | println!... | test.rs:401:13:401:36 | MacroExpr | |
| test.rs:401:13:401:37 | ExprStmt | test.rs:401:22:401:35 | MacroStmts | |
| test.rs:401:22:401:35 | "how are you?\\n" | test.rs:401:22:401:35 | FormatArgsExpr | |
| test.rs:401:22:401:35 | ...::_print(...) | test.rs:401:22:401:35 | { ... } | |
| test.rs:401:22:401:35 | ...::format_args_nl!... | test.rs:401:22:401:35 | MacroExpr | |
| test.rs:401:22:401:35 | ExprStmt | test.rs:401:13:401:36 | ...::_print | |
| test.rs:401:22:401:35 | FormatArgsExpr | test.rs:401:22:401:35 | MacroExpr | |
| test.rs:401:22:401:35 | FormatArgsExpr | test.rs:401:22:401:35 | ...::format_args_nl!... | |
| test.rs:401:22:401:35 | MacroExpr | test.rs:401:22:401:35 | ...::_print(...) | |
| test.rs:401:22:401:35 | MacroStmts | test.rs:401:22:401:35 | ExprStmt | |
| test.rs:401:22:401:35 | { ... } | test.rs:401:13:401:36 | MacroExpr | |
| test.rs:401:22:401:35 | { ... } | test.rs:401:13:401:36 | println!... | |
| test.rs:403:9:403:28 | let ... = ... | test.rs:403:20:403:27 | { ... } | |
| test.rs:403:13:403:16 | noop | test.rs:404:9:404:26 | ExprStmt | match |
| test.rs:403:20:403:27 | { ... } | test.rs:403:13:403:16 | noop | |
Expand Down Expand Up @@ -927,19 +936,21 @@ edges
| test.rs:427:41:435:5 | { ... } | test.rs:427:5:435:5 | exit fn const_block_assert (normal) | |
| test.rs:430:9:432:9 | ExprStmt | test.rs:431:13:431:50 | ExprStmt | |
| test.rs:430:9:432:9 | { ... } | test.rs:434:9:434:10 | 42 | |
| test.rs:431:13:431:49 | ...::panic_2021!... | test.rs:431:13:431:49 | MacroExpr | |
| test.rs:431:13:431:49 | ...::panic_explicit | test.rs:431:13:431:49 | ...::panic_explicit(...) | |
| test.rs:431:13:431:49 | ...::panic_explicit(...) | test.rs:431:13:431:49 | { ... } | |
| test.rs:431:13:431:49 | ExprStmt | test.rs:431:13:431:49 | MacroStmts | |
| test.rs:431:13:431:49 | ExprStmt | test.rs:431:13:431:49 | panic_cold_explicit | |
| test.rs:431:13:431:49 | MacroExpr | test.rs:430:9:432:9 | { ... } | |
| test.rs:431:13:431:49 | MacroExpr | test.rs:431:13:431:49 | { ... } | |
| test.rs:431:13:431:49 | MacroStmts | test.rs:431:13:431:49 | fn panic_cold_explicit | |
| test.rs:431:13:431:49 | assert!... | test.rs:431:13:431:49 | MacroExpr | |
| test.rs:431:13:431:49 | enter fn panic_cold_explicit | test.rs:431:13:431:49 | ...::panic_explicit | |
| test.rs:431:13:431:49 | exit fn panic_cold_explicit (normal) | test.rs:431:13:431:49 | exit fn panic_cold_explicit | |
| test.rs:431:13:431:49 | fn panic_cold_explicit | test.rs:431:13:431:49 | ExprStmt | |
| test.rs:431:13:431:49 | panic_cold_explicit | test.rs:431:13:431:49 | panic_cold_explicit(...) | |
| test.rs:431:13:431:49 | panic_cold_explicit(...) | test.rs:431:13:431:49 | { ... } | |
| test.rs:431:13:431:49 | { ... } | test.rs:431:13:431:49 | MacroExpr | |
| test.rs:431:13:431:49 | { ... } | test.rs:431:13:431:49 | ...::panic_2021!... | |
| test.rs:431:13:431:49 | { ... } | test.rs:431:13:431:49 | exit fn panic_cold_explicit (normal) | |
| test.rs:431:13:431:49 | { ... } | test.rs:431:21:431:48 | if ... {...} | |
| test.rs:431:13:431:50 | ExprStmt | test.rs:431:21:431:48 | MacroStmts | |
Expand All @@ -951,7 +962,7 @@ edges
| test.rs:431:21:431:48 | [boolean(false)] ! ... | test.rs:431:21:431:48 | if ... {...} | false |
| test.rs:431:21:431:48 | [boolean(true)] ! ... | test.rs:431:13:431:49 | ExprStmt | true |
| test.rs:431:21:431:48 | if ... {...} | test.rs:431:21:431:48 | { ... } | |
| test.rs:431:21:431:48 | { ... } | test.rs:431:13:431:49 | MacroExpr | |
| test.rs:431:21:431:48 | { ... } | test.rs:431:13:431:49 | assert!... | |
| test.rs:431:48:431:48 | 0 | test.rs:431:21:431:48 | ... > ... | |
| test.rs:434:9:434:10 | 42 | test.rs:427:41:435:5 | { ... } | |
| test.rs:437:5:446:5 | enter fn const_block_panic | test.rs:438:9:438:30 | Const | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edges
#select
Loading

0 comments on commit 5c64a8c

Please sign in to comment.