Skip to content

Commit c90a480

Browse files
committed
Single node for function, import, type decls
Represent function, import, and type declarations with the same single-node shape as the legacy CFG.
1 parent 0e5220c commit c90a480

3 files changed

Lines changed: 119 additions & 325 deletions

File tree

‎go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ module CfgImpl {
121121
AstNode getChild(AstNode n, int index) {
122122
(
123123
not n instanceof Go::FuncDef and
124+
not n instanceof Go::ImportDecl and
125+
not n instanceof Go::TypeDecl and
124126
not skipCfg(n) and
125127
result = n.getChild(index)
126128
or
@@ -496,8 +498,6 @@ module CfgImpl {
496498
n instanceof Go::SelectStmt
497499
or
498500
n instanceof Go::SendStmt
499-
or
500-
n instanceof Go::FuncDecl
501501
}
502502

503503
predicate additionalNode(Ast::AstNode n, string tag, NormalSuccessor t) {

‎go/ql/lib/semmle/go/controlflow/IR.qll‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ module IR {
9393
// "before"/"after" leaf node for its declaration), which hosts the
9494
// initialization write (see `InitParameterInstruction`).
9595
this.isBefore(any(FuncDef fd).getParameter(_).getDeclaration())
96+
or
97+
// Function declarations are represented by their merged leaf node.
98+
this.isBefore(any(FuncDecl fd))
9699
}
97100

98101
/** Holds if this instruction reads the value of variable or constant `v`. */
@@ -847,7 +850,7 @@ module IR {
847850
class DeclareFunctionInstruction extends Instruction {
848851
FuncDecl fd;
849852

850-
DeclareFunctionInstruction() { this.isIn(fd) }
853+
DeclareFunctionInstruction() { this.isBefore(fd) }
851854

852855
override Type getResultType() { result = fd.getType() }
853856
}

0 commit comments

Comments
 (0)