From: Dan Scales Date: Wed, 1 Sep 2021 02:06:46 +0000 (-0700) Subject: cmd/compile: fix missing case for shape double-check function X-Git-Tag: go1.18beta1~1537 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2dd7b770defc869edfcf610b9471fc4f580c3eb2;p=gostls13.git cmd/compile: fix missing case for shape double-check function Missing case types.TUNSAFEPTR in parameterizedBy(). Also realized there was the same missing case in the type substituter (*Tsubster).Typ(). Fixes #48103 Change-Id: If71f1a6ef80932f0e2120d4c18b39a30189fd8fe Reviewed-on: https://go-review.googlesource.com/c/go/+/346669 Reviewed-by: Keith Randall Trust: Dan Scales --- diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index cf3894e096..1717317925 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1917,7 +1917,7 @@ func parameterizedBy1(t *types.Type, params []*types.Type, visited map[*types.Ty case types.TINT, types.TINT8, types.TINT16, types.TINT32, types.TINT64, types.TUINT, types.TUINT8, types.TUINT16, types.TUINT32, types.TUINT64, - types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128: + types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128, types.TUNSAFEPTR: return true case types.TUNION: diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index 3ec2cc5d56..541e1907c0 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -1189,7 +1189,7 @@ func (ts *Tsubster) typ1(t *types.Type) *types.Type { } case types.TINT, types.TINT8, types.TINT16, types.TINT32, types.TINT64, types.TUINT, types.TUINT8, types.TUINT16, types.TUINT32, types.TUINT64, - types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128: + types.TUINTPTR, types.TBOOL, types.TSTRING, types.TFLOAT32, types.TFLOAT64, types.TCOMPLEX64, types.TCOMPLEX128, types.TUNSAFEPTR: newt = t.Underlying() case types.TUNION: nt := t.NumTerms() diff --git a/test/typeparam/issue48013.go b/test/typeparam/issue48013.go new file mode 100644 index 0000000000..179d9f44e9 --- /dev/null +++ b/test/typeparam/issue48013.go @@ -0,0 +1,39 @@ +// run -gcflags=-G=3 + +// Copyright 2021 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. + +package main + +import ( + "fmt" + "unsafe" +) + +type S[T any] struct { + val T +} + +// Test type substitution where base type is unsafe.Pointer +type U[T any] unsafe.Pointer + +func test[T any]() T { + var q U[T] + var v struct { + // Test derived type that contains an unsafe.Pointer + p unsafe.Pointer + val T + } + _ = q + return v.val +} + +func main() { + want := 0 + got := test[int]() + if got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } + +}