cmd/compile: avoid unnecessary interface conversion in bloop

Fixes #76482

Change-Id: I076568d8ae92ad6c9e0a5797cfe5bbfb615f63d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/725180
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Cuong Manh Le 2025-11-28 17:19:42 +07:00 committed by Gopher Robot
parent de456450e7
commit 2ac1f9cbc3
2 changed files with 10 additions and 10 deletions

View file

@ -74,7 +74,7 @@ func getNameFromNode(n ir.Node) *ir.Name {
} }
// keepAliveAt returns a statement that is either curNode, or a // keepAliveAt returns a statement that is either curNode, or a
// block containing curNode followed by a call to runtime.keepAlive for each // block containing curNode followed by a call to runtime.KeepAlive for each
// node in ns. These calls ensure that nodes in ns will be live until // node in ns. These calls ensure that nodes in ns will be live until
// after curNode's execution. // after curNode's execution.
func keepAliveAt(ns []ir.Node, curNode ir.Node) ir.Node { func keepAliveAt(ns []ir.Node, curNode ir.Node) ir.Node {
@ -94,7 +94,7 @@ func keepAliveAt(ns []ir.Node, curNode ir.Node) ir.Node {
if n.Sym().IsBlank() { if n.Sym().IsBlank() {
continue continue
} }
arg := ir.NewConvExpr(pos, ir.OCONV, types.Types[types.TINTER], n) arg := ir.NewConvExpr(pos, ir.OCONV, types.Types[types.TUNSAFEPTR], typecheck.NodAddr(n))
if !n.Type().IsInterface() { if !n.Type().IsInterface() {
srcRType0 := reflectdata.TypePtrAt(pos, n.Type()) srcRType0 := reflectdata.TypePtrAt(pos, n.Type())
arg.TypeWord = srcRType0 arg.TypeWord = srcRType0

View file

@ -31,23 +31,23 @@ func test(b *testing.B, localsink, cond int) { // ERROR ".*"
} }
somethingptr := &something somethingptr := &something
for b.Loop() { // ERROR "inlining call to testing\.\(\*B\)\.Loop" for b.Loop() { // ERROR "inlining call to testing\.\(\*B\)\.Loop"
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive" ".* does not escape" caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
caninlineNoRet(1) // ERROR "inlining call to caninlineNoRet" "function arg will be kept alive" ".* does not escape" caninlineNoRet(1) // ERROR "inlining call to caninlineNoRet" "function arg will be kept alive"
caninlineVariadic(1) // ERROR "inlining call to caninlineVariadic" "function arg will be kept alive" ".* does not escape" caninlineVariadic(1) // ERROR "inlining call to caninlineVariadic" "function arg will be kept alive" ".* does not escape"
caninlineVariadic(localsink) // ERROR "inlining call to caninlineVariadic" "localsink will be kept alive" ".* does not escape" caninlineVariadic(localsink) // ERROR "inlining call to caninlineVariadic" "localsink will be kept alive" ".* does not escape"
localsink = caninline(1) // ERROR "inlining call to caninline" "localsink will be kept alive" ".* does not escape" localsink = caninline(1) // ERROR "inlining call to caninline" "localsink will be kept alive"
localsink += 5 // ERROR "localsink will be kept alive" ".* does not escape" localsink += 5 // ERROR "localsink will be kept alive"
localsink, cond = 1, 2 // ERROR "localsink will be kept alive" "cond will be kept alive" ".* does not escape" localsink, cond = 1, 2 // ERROR "localsink will be kept alive" "cond will be kept alive"
*somethingptr = 1 // ERROR "dereference will be kept alive" *somethingptr = 1 // ERROR "dereference will be kept alive"
if cond > 0 { if cond > 0 {
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive" ".* does not escape" caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
} }
switch cond { switch cond {
case 2: case 2:
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive" ".* does not escape" caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
} }
{ {
caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive" ".* does not escape" caninline(1) // ERROR "inlining call to caninline" "function result will be kept alive"
} }
} }
} }