From da0e8c4517178f545ee78b11e3d91e1daa7ce07a Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 3 Jun 2025 21:35:20 +0700 Subject: cmd/compile: relax reshaping condition CL 641955 changes the Unified IR reader to not doing shapify when reading reshaping expression. However, this condition only matters with pointer type shaping, which will lose the original type, causes the reshaping ends up with a completely different type. This CL relaxes the condition, always allow non-pointer types shaping. Updates #71184 Fixes #73947 Change-Id: Ib0bafd8932c52d99266f311b6cbfc75c00383f9b Reviewed-on: https://go-review.googlesource.com/c/go/+/678335 Reviewed-by: Keith Randall Auto-Submit: Cuong Manh Le Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee --- src/cmd/compile/internal/noder/reader.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/cmd/compile/internal/noder/reader.go') diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 2c3f7161a8..38b0bc1d8a 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -1014,7 +1014,25 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx index, implicits, explicits // arguments. for i, targ := range dict.targs { basic := r.Bool() - if dict.shaped && !pr.reshaping { + isPointerShape := basic && targ.IsPtr() && !targ.Elem().NotInHeap() + // We should not do shapify during the reshaping process, see #71184. + // However, this only matters for shapify a pointer type, which will + // lose the original underlying type. + // + // Example with a pointer type: + // + // - First, shapifying *[]T -> *uint8 + // - During the reshaping process, *uint8 is shapified to *go.shape.uint8 + // - This ends up with a different type with the original *[]T + // + // For a non-pointer type: + // + // - int -> go.shape.int + // - go.shape.int -> go.shape.int + // + // We always end up with the identical type. + canShapify := !pr.reshaping || !isPointerShape + if dict.shaped && canShapify { dict.targs[i] = shapify(targ, basic) } } -- cgit v1.3-5-g9baa