aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cgo
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-04-13 17:47:47 -0700
committerIan Lance Taylor <iant@golang.org>2020-04-14 18:59:37 +0000
commit33ff63da4ec9cd456cab65b034b80a2fde4ebdea (patch)
treed1b730bbe58d90a700bb93cade0ba99bfe7c24cf /src/cmd/cgo
parentcdaf8b6469b3b17ce296199ed31dca2c0816bcc6 (diff)
downloadgo-33ff63da4ec9cd456cab65b034b80a2fde4ebdea.tar.gz
go-33ff63da4ec9cd456cab65b034b80a2fde4ebdea.zip
cmd/cgo: use consistent tag for a particular struct
For #31891 Fixes #38408 Change-Id: Ie7498c2cab728ae798e66e7168425e16b063520e Reviewed-on: https://go-review.googlesource.com/c/go/+/228102 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r--src/cmd/cgo/gcc.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 668a246b5f..e01ea081d9 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -2060,6 +2060,10 @@ var goIdent = make(map[string]*ast.Ident)
// that may contain a pointer. This is used for cgo pointer checking.
var unionWithPointer = make(map[ast.Expr]bool)
+// anonymousStructTag provides a consistent tag for an anonymous struct.
+// The same dwarf.StructType pointer will always get the same tag.
+var anonymousStructTag = make(map[*dwarf.StructType]string)
+
func (c *typeConv) Init(ptrSize, intSize int64) {
c.ptrSize = ptrSize
c.intSize = intSize
@@ -2408,8 +2412,12 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
break
}
if tag == "" {
- tag = "__" + strconv.Itoa(tagGen)
- tagGen++
+ tag = anonymousStructTag[dt]
+ if tag == "" {
+ tag = "__" + strconv.Itoa(tagGen)
+ tagGen++
+ anonymousStructTag[dt] = tag
+ }
} else if t.C.Empty() {
t.C.Set(dt.Kind + " " + tag)
}