]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: un-hide closure func in init function
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 25 Aug 2023 08:08:05 +0000 (15:08 +0700)
committerGopher Robot <gobot@golang.org>
Sat, 26 Aug 2023 01:54:41 +0000 (01:54 +0000)
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>

src/cmd/cgo/internal/testshared/shared_test.go
src/cmd/cgo/internal/testshared/testdata/issue62277/issue62277_test.go [new file with mode: 0644]
src/cmd/cgo/internal/testshared/testdata/issue62277/p/p.go [new file with mode: 0644]
src/cmd/compile/internal/noder/reader.go

index 2eab33f9191b7c3f60661fb229d44d5d805f9270..814b9994f824abaa76c25dab477e15f0cedd6504 100644 (file)
@@ -1159,6 +1159,12 @@ func TestIssue47873(t *testing.T) {
        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.
 func TestStd(t *testing.T) {
        if testing.Short() {
diff --git a/src/cmd/cgo/internal/testshared/testdata/issue62277/issue62277_test.go b/src/cmd/cgo/internal/testshared/testdata/issue62277/issue62277_test.go
new file mode 100644 (file)
index 0000000..89a0601
--- /dev/null
@@ -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)
+}
diff --git a/src/cmd/cgo/internal/testshared/testdata/issue62277/p/p.go b/src/cmd/cgo/internal/testshared/testdata/issue62277/p/p.go
new file mode 100644 (file)
index 0000000..97bde0c
--- /dev/null
@@ -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"}
+       }()
+}
index 01f001f1997e1e6417c1a57eadbc170d0400c90f..374d9225b9cb7adcab103ccd428b8071b6d76467 100644 (file)
@@ -3109,6 +3109,11 @@ func (r *reader) funcLit() ir.Node {
 
        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
 }