]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: in -godefs mode, don't change constant to type
authorIan Lance Taylor <iant@golang.org>
Thu, 11 Jun 2020 19:01:52 +0000 (12:01 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 11 Jun 2020 21:53:45 +0000 (21:53 +0000)
Fixes #39534

Change-Id: Icbc1745935dd7098c09e2d35c61cd5bfbaa31c63
Reviewed-on: https://go-review.googlesource.com/c/go/+/237558
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
misc/cgo/testgodefs/testdata/issue39534.go [new file with mode: 0644]
misc/cgo/testgodefs/testgodefs_test.go
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/testgodefs/testdata/issue39534.go b/misc/cgo/testgodefs/testdata/issue39534.go
new file mode 100644 (file)
index 0000000..9899ba1
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2020 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.
+//
+// +build ignore
+
+package main
+
+// enum { ENUMVAL = 0x1 };
+import "C"
+
+const ENUMVAL = C.ENUMVAL
index 178fff3fbc1faf9659cc548ee1dab770e382a131..e4085f9ca80df6a500f1bcf705eb306de5f77469 100644 (file)
@@ -24,6 +24,7 @@ var filePrefixes = []string{
        "issue37479",
        "issue37621",
        "issue38649",
+       "issue39534",
 }
 
 func TestGoDefs(t *testing.T) {
index d903a7afb569e3cbabc770a93cbf43856826d587..a59534ebd0aee083a17665df0c2ac8f25df70f6f 100644 (file)
@@ -1354,7 +1354,7 @@ func (p *Package) rewriteRef(f *File) {
 
                if *godefs {
                        // Substitute definition for mangled type name.
-                       if r.Name.Type != nil {
+                       if r.Name.Type != nil && r.Name.Kind == "type" {
                                expr = r.Name.Type.Go
                        }
                        if id, ok := expr.(*ast.Ident); ok {