mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: disable inappropriate warnings when the gcc struct is empty
package main
//#cgo CFLAGS: -Wall
//void test() {}
import "C"
func main() {
C.test()
}
This code will cause gcc issuing warnings about unused variable.
This commit use offset of the second return value of
Packages.structType to detect whether the gcc struct is empty,
and if it's directly invoke the C function instead of writing an
unused code.
LGTM=dave, minux
R=golang-codereviews, iant, minux, dave
CC=golang-codereviews
https://golang.org/cl/109640045
This commit is contained in:
parent
ec5d7ba95c
commit
086df1dc77
2 changed files with 22 additions and 2 deletions
|
|
@ -517,7 +517,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
|||
return
|
||||
}
|
||||
|
||||
ctype, _ := p.structType(n)
|
||||
ctype, offset := p.structType(n)
|
||||
|
||||
// Gcc wrapper unpacks the C argument struct
|
||||
// and calls the actual C function.
|
||||
|
|
@ -530,7 +530,9 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
|||
// We're trying to write a gcc struct that matches 6c/8c/5c'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 *a = v;\n", ctype, p.packedAttribute())
|
||||
if offset != 0 {
|
||||
fmt.Fprintf(fgcc, "\t%s %v *a = v;\n", ctype, p.packedAttribute())
|
||||
}
|
||||
fmt.Fprintf(fgcc, "\t")
|
||||
if t := n.FuncType.Result; t != nil {
|
||||
fmt.Fprintf(fgcc, "a->r = ")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue