]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: remove -O options when generating compiler errors
authorIan Lance Taylor <iant@golang.org>
Thu, 19 May 2016 01:42:25 +0000 (18:42 -0700)
committerRuss Cox <rsc@golang.org>
Fri, 27 May 2016 01:40:30 +0000 (01:40 +0000)
The cgo tool generates compiler errors to find out what kind of name it
is using.  Turning on optimization can confuse that process by producing
new unexpected messages.

Fixes #14669.

Change-Id: Idc8e35fd259711ecc9638566b691c11d17140325
Reviewed-on: https://go-review.googlesource.com/23231
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
misc/cgo/errors/issue14669.go [new file with mode: 0644]
misc/cgo/errors/test.bash
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/errors/issue14669.go b/misc/cgo/errors/issue14669.go
new file mode 100644 (file)
index 0000000..04d2bcb
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2016 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.
+
+// Issue 14669: test that fails when build with CGO_CFLAGS selecting
+// optimization.
+
+package p
+
+/*
+const int E = 1;
+
+typedef struct s {
+       int       c;
+} s;
+*/
+import "C"
+
+func F() {
+       _ = C.s{
+               c: C.E,
+       }
+}
index cd358a10f815e0fe13c9c8be143a4f07ee334c7f..643d03820502850015a3081aec4f7cc6db3e9433 100755 (executable)
@@ -45,6 +45,13 @@ expect issue13129.go C.ushort
 check issue13423.go
 expect issue13635.go C.uchar C.schar C.ushort C.uint C.ulong C.longlong C.ulonglong C.complexfloat C.complexdouble
 
+if ! go build issue14669.go; then
+       exit 1
+fi
+if ! CGO_CFLAGS="-O" go build issue14669.go; then
+       exit 1
+fi
+
 if ! go run ptr.go; then
        exit 1
 fi
index 97ef824c9342a727a15b4d799e00cf832e5d6e6b..451798244f6db2a48fd0793a74622faa96b85d92 100644 (file)
@@ -1243,12 +1243,20 @@ func (p *Package) gccErrors(stdin []byte) string {
        // TODO(rsc): require failure
        args := p.gccCmd()
 
+       // Optimization options can confuse the error messages; remove them.
+       nargs := make([]string, 0, len(args))
+       for _, arg := range args {
+               if !strings.HasPrefix(arg, "-O") {
+                       nargs = append(nargs, arg)
+               }
+       }
+
        if *debugGcc {
-               fmt.Fprintf(os.Stderr, "$ %s <<EOF\n", strings.Join(args, " "))
+               fmt.Fprintf(os.Stderr, "$ %s <<EOF\n", strings.Join(nargs, " "))
                os.Stderr.Write(stdin)
                fmt.Fprint(os.Stderr, "EOF\n")
        }
-       stdout, stderr, _ := run(stdin, args)
+       stdout, stderr, _ := run(stdin, nargs)
        if *debugGcc {
                os.Stderr.Write(stdout)
                os.Stderr.Write(stderr)