mirror of
https://github.com/golang/go.git
synced 2025-12-28 06:34:04 +00:00
cmd/cgo: don't emit C local if it is not used
Fixes #76861 Change-Id: Icc8452e48ed736e8240f8afea18637c33b8e3ef8 Reviewed-on: https://go-review.googlesource.com/c/go/+/730600 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Joe Richey <joerichey@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
65b71c11d4
commit
8c28ab936a
12
src/cmd/cgo/internal/test/issue76861.go
Normal file
12
src/cmd/cgo/internal/test/issue76861.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2025 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.
|
||||
|
||||
//go:build cgo
|
||||
|
||||
package cgotest
|
||||
|
||||
// Issue 43639: No runtime test needed, make sure package
|
||||
// cmd/cgo/internal/test/issue76861 compiles without error.
|
||||
|
||||
import _ "cmd/cgo/internal/test/issue76861"
|
||||
13
src/cmd/cgo/internal/test/issue76861/a.go
Normal file
13
src/cmd/cgo/internal/test/issue76861/a.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2025 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 issue76861
|
||||
|
||||
// #cgo CFLAGS: -Wall -Werror
|
||||
// void issue76861(void) {}
|
||||
import "C"
|
||||
|
||||
func Issue76861() {
|
||||
C.issue76861()
|
||||
}
|
||||
@ -783,13 +783,13 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||
// We're trying to write a gcc struct that matches gc's layout.
|
||||
// Use packed attribute to force no padding in this struct in case
|
||||
// gcc has different packing requirements.
|
||||
fmt.Fprintf(fgcc, "\t%s %v *_cgo_a = v;\n", ctype, p.packedAttribute())
|
||||
if n.FuncType.Result != nil {
|
||||
tr := n.FuncType.Result
|
||||
if (n.Kind != "macro" && len(n.FuncType.Params) > 0) || tr != nil {
|
||||
fmt.Fprintf(fgcc, "\t%s %v *_cgo_a = v;\n", ctype, p.packedAttribute())
|
||||
}
|
||||
if tr != nil {
|
||||
// Save the stack top for use below.
|
||||
fmt.Fprintf(fgcc, "\tchar *_cgo_stktop = _cgo_topofstack();\n")
|
||||
}
|
||||
tr := n.FuncType.Result
|
||||
if tr != nil {
|
||||
fmt.Fprintf(fgcc, "\t__typeof__(_cgo_a->r) _cgo_r;\n")
|
||||
}
|
||||
fmt.Fprintf(fgcc, "\t_cgo_tsan_acquire();\n")
|
||||
@ -819,7 +819,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||
fmt.Fprintf(fgcc, "\t_cgo_errno = errno;\n")
|
||||
}
|
||||
fmt.Fprintf(fgcc, "\t_cgo_tsan_release();\n")
|
||||
if n.FuncType.Result != nil {
|
||||
if tr != nil {
|
||||
// The cgo call may have caused a stack copy (via a callback).
|
||||
// Adjust the return value pointer appropriately.
|
||||
fmt.Fprintf(fgcc, "\t_cgo_a = (void*)((char*)_cgo_a + (_cgo_topofstack() - _cgo_stktop));\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user