mirror of
https://github.com/golang/go
synced 2024-11-19 01:44:40 -07:00
cmd/compile: un-hide closure func in init function
Same as CL 492135, but for init function. Fixes #62277 Change-Id: If5ff9bc2ce2a73193b1f7ee5f7f14045d1354f56 Reviewed-on: https://go-review.googlesource.com/c/go/+/522956 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
59abd0e88b
commit
079c0441d5
@ -1159,6 +1159,12 @@ func TestIssue47873(t *testing.T) {
|
|||||||
goCmd(t, "run", "-linkshared", "./issue47837/main")
|
goCmd(t, "run", "-linkshared", "./issue47837/main")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue62277(t *testing.T) {
|
||||||
|
globalSkip(t)
|
||||||
|
goCmd(t, "install", "-buildmode=shared", "-linkshared", "./issue62277/p")
|
||||||
|
goCmd(t, "test", "-linkshared", "./issue62277")
|
||||||
|
}
|
||||||
|
|
||||||
// Test that we can build std in shared mode.
|
// Test that we can build std in shared mode.
|
||||||
func TestStd(t *testing.T) {
|
func TestStd(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
|
16
src/cmd/cgo/internal/testshared/testdata/issue62277/issue62277_test.go
vendored
Normal file
16
src/cmd/cgo/internal/testshared/testdata/issue62277/issue62277_test.go
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2023 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package issue62277_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"testshared/issue62277/p"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIssue62277(t *testing.T) {
|
||||||
|
t.Log(p.S)
|
||||||
|
t.Log(p.T)
|
||||||
|
}
|
17
src/cmd/cgo/internal/testshared/testdata/issue62277/p/p.go
vendored
Normal file
17
src/cmd/cgo/internal/testshared/testdata/issue62277/p/p.go
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2023 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package p
|
||||||
|
|
||||||
|
var S = func() []string {
|
||||||
|
return []string{"LD_LIBRARY_PATH"}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var T []string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
T = func() []string {
|
||||||
|
return []string{"LD_LIBRARY_PATH"}
|
||||||
|
}()
|
||||||
|
}
|
@ -3109,6 +3109,11 @@ func (r *reader) funcLit() ir.Node {
|
|||||||
|
|
||||||
r.addBody(fn, nil)
|
r.addBody(fn, nil)
|
||||||
|
|
||||||
|
// un-hide closures belong to init function.
|
||||||
|
if (r.curfn.IsPackageInit() || strings.HasPrefix(r.curfn.Sym().Name, "init.")) && ir.IsTrivialClosure(fn.OClosure) {
|
||||||
|
fn.SetIsHiddenClosure(false)
|
||||||
|
}
|
||||||
|
|
||||||
return fn.OClosure
|
return fn.OClosure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user