]> Cypherpunks repositories - gostls13.git/commitdiff
undo CL 109640045 / f97fb06525e5
authorShenghou Ma <minux@golang.org>
Fri, 18 Jul 2014 06:59:54 +0000 (02:59 -0400)
committerShenghou Ma <minux@golang.org>
Fri, 18 Jul 2014 06:59:54 +0000 (02:59 -0400)
Breaks build for FreeBSD. Probably clang related?

««« original CL description
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

»»»

TBR=dfc
R=dave
CC=golang-codereviews
https://golang.org/cl/114990044

misc/cgo/test/empty.go [deleted file]
src/cmd/cgo/out.go

diff --git a/misc/cgo/test/empty.go b/misc/cgo/test/empty.go
deleted file mode 100644 (file)
index daa7485..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2014 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 cgotest
-
-/*
-#cgo CFLAGS: -Werror=unused-variable
-void funcWithoutAnyParams() {}
-*/
-import "C"
-
-// Only test whether this can be compiled, unused
-// variable (e.g. empty gcc strut) could cause
-// warning/error under stricter CFLAGS.
-func testEmptyGccStruct() {
-       C.funcWithoutAnyParams()
-}
index a5fffd05687428c5eedf6e3078ebed0d723d599c..c6c27c4dbff314de81f9d036ad0d69a2804e73e3 100644 (file)
@@ -517,7 +517,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
                return
        }
 
-       ctype, offset := p.structType(n)
+       ctype, _ := p.structType(n)
 
        // Gcc wrapper unpacks the C argument struct
        // and calls the actual C function.
@@ -530,9 +530,7 @@ 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.
-       if offset != 0 {
-               fmt.Fprintf(fgcc, "\t%s %v *a = v;\n", ctype, p.packedAttribute())
-       }
+       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 = ")