Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: pointers to notinheap types need their own shape
They should not share a shape with regular pointers. We could coalesce multiple pointer-to-not-in-heap types, but doesn't seem worth it - just make them fully stenciled. Fixes #51733 Change-Id: Ie8158177226fbc46a798e71c51897a82f15153df Reviewed-on: https://go-review.googlesource.com/c/go/+/393895 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// run | ||
|
||
// 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 ( | ||
"log" | ||
"unsafe" | ||
) | ||
|
||
//go:notinheap | ||
type S struct{} | ||
|
||
func main() { | ||
p := (*S)(unsafe.Pointer(uintptr(0x8000))) | ||
var v any = p | ||
p2 := v.(*S) | ||
if p != p2 { | ||
log.Fatalf("%p != %p", unsafe.Pointer(p), unsafe.Pointer(p2)) | ||
} | ||
p2 = typeAssert[*S](v) | ||
if p != p2 { | ||
log.Fatalf("%p != %p from typeAssert", unsafe.Pointer(p), unsafe.Pointer(p2)) | ||
} | ||
} | ||
|
||
func typeAssert[T any](v any) T { | ||
return v.(T) | ||
} |