]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: ensure size is computed for shape types
authorKeith Randall <khr@golang.org>
Thu, 3 Feb 2022 17:44:21 +0000 (09:44 -0800)
committerKeith Randall <khr@golang.org>
Thu, 3 Feb 2022 18:23:55 +0000 (18:23 +0000)
Fixes #50993

Change-Id: I5f1bf5a8375c3da3203083b11de26962523ccb36
Reviewed-on: https://go-review.googlesource.com/c/go/+/382874
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
Trust: Dan Scales <danscales@google.com>

src/cmd/compile/internal/typecheck/subr.go
test/typeparam/issue50993.go [new file with mode: 0644]

index 93812ebda5c941c601c1b99e96e859c967b851cb..9892471142086a62975ccac5de570c7c6eca652d 100644 (file)
@@ -1480,6 +1480,7 @@ func Shapify(t *types.Type, index int, tparam *types.Type) *types.Type {
        s.SetUnderlying(u)
        s.SetIsShape(true)
        s.SetHasShape(true)
+       types.CalcSize(s)
        name.SetType(s)
        name.SetTypecheck(1)
        submap[u] = s
diff --git a/test/typeparam/issue50993.go b/test/typeparam/issue50993.go
new file mode 100644 (file)
index 0000000..4d459fd
--- /dev/null
@@ -0,0 +1,35 @@
+// compile -d=checkptr
+
+// Copyright 2022 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 (
+       "sync/atomic"
+       "unsafe"
+)
+
+type Node[T any] struct {
+       Next *Node[T]
+       // Prev  *Node[T]
+}
+
+func LoadPointer[T any](addr **T) (val *T) {
+       return (*T)(
+               atomic.LoadPointer(
+                       (*unsafe.Pointer)(unsafe.Pointer(addr)),
+               ))
+}
+
+func (q *Node[T]) Pop() {
+       var tail, head *Node[T]
+       if head == LoadPointer(&tail) {
+       }
+}
+
+func main() {
+       ch := Node[uint64]{}
+       ch.Pop()
+}