Skip to content

Commit e8f38b2

Browse files
committed
Fix CFG for return instructions
1 parent 4d90354 commit e8f38b2

2 files changed

Lines changed: 3 additions & 8 deletions

File tree

go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ module GoCfg {
432432
or
433433
n instanceof Go::IncDecStmt and tag = "incdec-rhs"
434434
or
435-
// Return node
436-
n instanceof Go::ReturnStmt and tag = "return"
437-
or
438435
// Result write nodes in return statements
439436
exists(int i, Go::ReturnStmt ret |
440437
n = ret and
@@ -950,7 +947,7 @@ module GoCfg {
950947
n2.isAdditional(ret, tag2)
951948
)
952949
or
953-
// Last return epilogue → In(ret) (the return itself)
950+
// Last return epilogue → return node
954951
n1.isAdditional(ret, getLastReturnEpilogueTag(ret)) and
955952
n2.isIn(ret)
956953
)

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ module IR {
893893
class ReturnInstruction extends Instruction {
894894
ReturnStmt ret;
895895

896-
ReturnInstruction() { this.isAdditional(ret, "return") }
896+
ReturnInstruction() { this.isIn(ret) }
897897

898898
/** Gets the corresponding `ReturnStmt`. */
899899
ReturnStmt getReturnStmt() { result = ret }
@@ -938,9 +938,7 @@ module IR {
938938
exists(retStmt.getAnExpr())
939939
}
940940

941-
private ReturnInstruction getReturnInstruction() {
942-
result.(ReturnInstruction).isAdditional(retStmt, "return")
943-
}
941+
private ReturnInstruction getReturnInstruction() { result.getReturnStmt() = retStmt }
944942

945943
override Instruction getRhs() { result = this.getReturnInstruction().getResult(idx) }
946944

0 commit comments

Comments
 (0)