[go] cmd/compile: avoid rewriting switch case expressions in b.Loop

1 view
Skip to first unread message

Chencheng Jiang (Gerrit)

unread,
Aug 9, 2026, 5:04:55 PM (13 hours ago) Aug 9
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Chencheng Jiang has uploaded the change for review

Commit message

cmd/compile: avoid rewriting switch case expressions in b.Loop

CaseClause.List contains expressions, but the bloop pass treats it as a
list of statements. When a case expression is a function call, the pass
replaces it with a block containing an assignment and a KeepAlive call.
Escape analysis then panics because the block has no expression type.

Only preserve statements in the case body. Case expressions are already
used by the switch and do not need additional keep-alive instrumentation.

Add a regression test for a function call used as a case expression.

Fixes #80801
Change-Id: Id8c1e83ab54339885445fd7a45348410ad4631cb

Change diff

diff --git a/src/cmd/compile/internal/bloop/bloop.go b/src/cmd/compile/internal/bloop/bloop.go
index d5f001a..abb6838 100644
--- a/src/cmd/compile/internal/bloop/bloop.go
+++ b/src/cmd/compile/internal/bloop/bloop.go
@@ -325,7 +325,6 @@
case *ir.BlockStmt:
preserveStmts(e.curFn, n.List)
case *ir.CaseClause:
- preserveStmts(e.curFn, n.List)
preserveStmts(e.curFn, n.Body)
case *ir.CommClause:
preserveStmts(e.curFn, n.Body)
diff --git a/test/bloop.go b/test/bloop.go
index d718425..c53a17e 100644
--- a/test/bloop.go
+++ b/test/bloop.go
@@ -56,6 +56,10 @@
case 2:
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
}
+ // Case expressions are not statements and should not be rewritten by the bloop pass.
+ switch cond {
+ case caninline(2): // ERROR "inlining call to caninline"
+ }
{
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
}

Change information

Files:
  • M src/cmd/compile/internal/bloop/bloop.go
  • M test/bloop.go
Change size: XS
Delta: 2 files changed, 4 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id8c1e83ab54339885445fd7a45348410ad4631cb
Gerrit-Change-Number: 812580
Gerrit-PatchSet: 1
Gerrit-Owner: Chencheng Jiang <dorb...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Youlin Feng (Gerrit)

unread,
12:32 AM (5 hours ago) 12:32 AM
to Chencheng Jiang, goph...@pubsubhelper.golang.org, Robert Griesemer, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Chencheng Jiang and Keith Randall

Youlin Feng voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Chencheng Jiang
  • Keith Randall
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Id8c1e83ab54339885445fd7a45348410ad4631cb
Gerrit-Change-Number: 812580
Gerrit-PatchSet: 1
Gerrit-Owner: Chencheng Jiang <dorb...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-Reviewer: Youlin Feng <fengy...@live.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: Chencheng Jiang <dorb...@gmail.com>
Gerrit-Comment-Date: Mon, 10 Aug 2026 04:32:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages