From e8f38b2870965bacfff3d5339e5e5b410d40b960 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Fri, 29 May 2026 13:34:22 +0100 Subject: [PATCH] Fix CFG for return instructions --- go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll | 5 +---- go/ql/lib/semmle/go/controlflow/IR.qll | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll index b5c95dc93e8..a5c98645dff 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll @@ -432,9 +432,6 @@ module GoCfg { or n instanceof Go::IncDecStmt and tag = "incdec-rhs" or - // Return node - n instanceof Go::ReturnStmt and tag = "return" - or // Result write nodes in return statements exists(int i, Go::ReturnStmt ret | n = ret and @@ -950,7 +947,7 @@ module GoCfg { n2.isAdditional(ret, tag2) ) or - // Last return epilogue → In(ret) (the return itself) + // Last return epilogue → return node n1.isAdditional(ret, getLastReturnEpilogueTag(ret)) and n2.isIn(ret) ) diff --git a/go/ql/lib/semmle/go/controlflow/IR.qll b/go/ql/lib/semmle/go/controlflow/IR.qll index 22300f3688b..86df852f7a5 100644 --- a/go/ql/lib/semmle/go/controlflow/IR.qll +++ b/go/ql/lib/semmle/go/controlflow/IR.qll @@ -893,7 +893,7 @@ module IR { class ReturnInstruction extends Instruction { ReturnStmt ret; - ReturnInstruction() { this.isAdditional(ret, "return") } + ReturnInstruction() { this.isIn(ret) } /** Gets the corresponding `ReturnStmt`. */ ReturnStmt getReturnStmt() { result = ret } @@ -938,9 +938,7 @@ module IR { exists(retStmt.getAnExpr()) } - private ReturnInstruction getReturnInstruction() { - result.(ReturnInstruction).isAdditional(retStmt, "return") - } + private ReturnInstruction getReturnInstruction() { result.getReturnStmt() = retStmt } override Instruction getRhs() { result = this.getReturnInstruction().getResult(idx) }