From 633bac633c9d97e89b2024901fa58217c947e5ef Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Mon, 4 Nov 2024 10:34:08 +0100 Subject: [PATCH] Rust: CFG classes are in expression module iff they correspond to expressions --- .../internal/ControlFlowGraphImpl.qll | 74 +++++++++---------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll index 4e10fbddbf76..72a8098eb106 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll @@ -93,27 +93,8 @@ class ParamTree extends StandardPostOrderTree, Param { override AstNode getChildNode(int i) { i = 0 and result = this.getPat() } } -class FormatArgsExprTree extends StandardPostOrderTree, FormatArgsExpr { - override AstNode getChildNode(int i) { - i = -1 and result = this.getTemplate() - or - result = this.getArg(i).getExpr() - or - result = - any(FormatTemplateVariableAccess v, Format f, int index, int kind | - f = this.getFormat(index) and - ( - v.getArgument() = f.getArgumentRef() and kind = 0 - or - v.getArgument() = f.getWidthArgument() and kind = 1 - or - v.getArgument() = f.getPrecisionArgument() and kind = 2 - ) and - i = this.getNumberOfArgs() + index * 3 + kind - | - v - ) - } +class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt { + override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() } } class FormatTemplateVariableAccessTree extends LeafTree, FormatTemplateVariableAccess { } @@ -219,22 +200,6 @@ class NameTree extends LeafTree, Name { } class NameRefTree extends LeafTree, NameRef { } -class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { } - -class ParenExprTree extends ControlFlowTree, ParenExpr { - private ControlFlowTree expr; - - ParenExprTree() { expr = super.getExpr() } - - override predicate propagatesAbnormal(AstNode child) { expr.propagatesAbnormal(child) } - - override predicate first(AstNode first) { expr.first(first) } - - override predicate last(AstNode last, Completion c) { expr.last(last, c) } - - override predicate succ(AstNode pred, AstNode succ, Completion c) { none() } -} - class TypeRefTree extends LeafTree instanceof TypeRef { } /** @@ -360,10 +325,6 @@ module ExprTrees { } } - class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt { - override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() } - } - class FieldExprTree extends StandardPostOrderTree instanceof FieldExpr { override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() } } @@ -409,6 +370,21 @@ module ExprTrees { i = -1 and result = this.getTemplate() or result = this.getArg(i).getExpr() + or + result = + any(FormatTemplateVariableAccess v, Format f, int index, int kind | + f = this.getFormat(index) and + ( + v.getArgument() = f.getArgumentRef() and kind = 0 + or + v.getArgument() = f.getWidthArgument() and kind = 1 + or + v.getArgument() = f.getPrecisionArgument() and kind = 2 + ) and + i = this.getNumberOfArgs() + index * 3 + kind + | + v + ) } } @@ -566,6 +542,22 @@ module ExprTrees { } } + class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { } + + class ParenExprTree extends ControlFlowTree, ParenExpr { + private ControlFlowTree expr; + + ParenExprTree() { expr = super.getExpr() } + + override predicate propagatesAbnormal(AstNode child) { expr.propagatesAbnormal(child) } + + override predicate first(AstNode first) { expr.first(first) } + + override predicate last(AstNode last, Completion c) { expr.last(last, c) } + + override predicate succ(AstNode pred, AstNode succ, Completion c) { none() } + } + class PathExprTree extends LeafTree instanceof PathExpr { } class PrefixExprTree extends StandardPostOrderTree instanceof PrefixExpr {