Fix CFG for return instructions

This commit is contained in:
Owen Mansel-Chan
2026-05-29 13:34:22 +01:00
parent 4d90354b8a
commit e8f38b2870
2 changed files with 3 additions and 8 deletions

View File

@@ -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)
)

View File

@@ -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) }