From d582d68afdbb0dd99df2029f0fa7d8fc2c6f8cc3 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 0c003ea2f3c..887641431c4 100644 --- a/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll +++ b/go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll @@ -440,9 +440,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 @@ -958,7 +955,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) }