From c49627e81b05f23f97544fc6bfae3347296b4a06 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 10 Nov 2021 15:36:25 -0500 Subject: [PATCH] cmd/compile: use canonical stringslice/ representations in abiutils A chunk of code in abiutils was synthesizing the internals of a Go string type as "struct { unsafe.Pointer, uintptr }" instead of the more canonical representation "struct { *uint8, int }" used elsewhere in the compiler. The abiutils type was being pulled into the code during late call expansion, which resulted in two different entries in the SSA named value table for the same variable piece, each with different types; this then confused DWARF location list generation. This patch changes the abiutils synthesized type to be consistent with other parts of the back end, and makes a similar change for synthesized slice types (use "struct { *uint8, int, int }"). Fixes #47354. Change-Id: If789031cdc7abaf215bc75ee6eb863defbe530be Reviewed-on: https://go-review.googlesource.com/c/go/+/362715 Trust: Than McIntosh Run-TryBot: Than McIntosh TryBot-Result: Go Bot Reviewed-by: Cherry Mui --- src/cmd/compile/internal/abi/abiutils.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/abi/abiutils.go b/src/cmd/compile/internal/abi/abiutils.go index 74c8707b29..529150a390 100644 --- a/src/cmd/compile/internal/abi/abiutils.go +++ b/src/cmd/compile/internal/abi/abiutils.go @@ -715,19 +715,20 @@ func setup() { synthOnce.Do(func() { fname := types.BuiltinPkg.Lookup nxp := src.NoXPos - unsp := types.Types[types.TUNSAFEPTR] - ui := types.Types[types.TUINTPTR] + bp := types.NewPtr(types.Types[types.TUINT8]) + it := types.Types[types.TINT] synthSlice = types.NewStruct(types.NoPkg, []*types.Field{ - types.NewField(nxp, fname("ptr"), unsp), - types.NewField(nxp, fname("len"), ui), - types.NewField(nxp, fname("cap"), ui), + types.NewField(nxp, fname("ptr"), bp), + types.NewField(nxp, fname("len"), it), + types.NewField(nxp, fname("cap"), it), }) types.CalcStructSize(synthSlice) synthString = types.NewStruct(types.NoPkg, []*types.Field{ - types.NewField(nxp, fname("data"), unsp), - types.NewField(nxp, fname("len"), ui), + types.NewField(nxp, fname("data"), bp), + types.NewField(nxp, fname("len"), it), }) types.CalcStructSize(synthString) + unsp := types.Types[types.TUNSAFEPTR] synthIface = types.NewStruct(types.NoPkg, []*types.Field{ types.NewField(nxp, fname("f1"), unsp), types.NewField(nxp, fname("f2"), unsp), -- 2.50.0