From: Ian Lance Taylor Date: Thu, 11 Jun 2020 19:01:52 +0000 (-0700) Subject: cmd/cgo: in -godefs mode, don't change constant to type X-Git-Tag: go1.15rc1~115 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a5a9a06d7183a6faf70b3d1231273af247503c19;p=gostls13.git cmd/cgo: in -godefs mode, don't change constant to type Fixes #39534 Change-Id: Icbc1745935dd7098c09e2d35c61cd5bfbaa31c63 Reviewed-on: https://go-review.googlesource.com/c/go/+/237558 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- diff --git a/misc/cgo/testgodefs/testdata/issue39534.go b/misc/cgo/testgodefs/testdata/issue39534.go new file mode 100644 index 0000000000..9899ba1673 --- /dev/null +++ b/misc/cgo/testgodefs/testdata/issue39534.go @@ -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 diff --git a/misc/cgo/testgodefs/testgodefs_test.go b/misc/cgo/testgodefs/testgodefs_test.go index 178fff3fbc..e4085f9ca8 100644 --- a/misc/cgo/testgodefs/testgodefs_test.go +++ b/misc/cgo/testgodefs/testgodefs_test.go @@ -24,6 +24,7 @@ var filePrefixes = []string{ "issue37479", "issue37621", "issue38649", + "issue39534", } func TestGoDefs(t *testing.T) { diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index d903a7afb5..a59534ebd0 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -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 {