cgo: process DWARF info even when debug data is used for value

Always process the DWARF info, even when the const value is determined
using the debug data block. This ensures that the injected enum is
removed and future loads of the same constant do not trigger
inconsistent definitions.

Add tests for issues 2470 and 4054.
Fixes #4054.

R=golang-dev, fullung, dave, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6501101
This commit is contained in:
Joel Sing 2012-09-20 13:20:33 +10:00
parent 81a9cc31c4
commit 9536480edc
5 changed files with 62 additions and 4 deletions

View file

@ -616,10 +616,7 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
n.FuncType = conv.FuncType(f, pos)
} else {
n.Type = conv.Type(types[i], pos)
// Prefer debug data over DWARF debug output, if we have it.
if n.Kind == "const" && i < len(enumVal) {
n.Const = fmt.Sprintf("%#x", enumVal[i])
} else if enums[i] != 0 && n.Type.EnumValues != nil {
if enums[i] != 0 && n.Type.EnumValues != nil {
k := fmt.Sprintf("__cgo_enum__%d", i)
n.Kind = "const"
n.Const = fmt.Sprintf("%#x", n.Type.EnumValues[k])
@ -627,6 +624,10 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
// equally in future loads of the same constant.
delete(n.Type.EnumValues, k)
}
// Prefer debug data over DWARF debug output, if we have it.
if n.Kind == "const" && i < len(enumVal) {
n.Const = fmt.Sprintf("%#x", enumVal[i])
}
}
}