mirror of
https://github.com/golang/go
synced 2024-11-22 18:34:51 -07:00
c4db811e44
User code is unlikely to be correct, but don't crash the compiler when the offset of a pointer in an object is not a multiple of the pointer size. Fixes #61187 Change-Id: Ie56bfcb38556c5dd6f702ae4ec1d4534c6acd420 Reviewed-on: https://go-review.googlesource.com/c/go/+/508555 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
23 lines
458 B
Go
23 lines
458 B
Go
// compile
|
|
|
|
// Copyright 2023 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"
|
|
"reflect"
|
|
"unsafe"
|
|
)
|
|
|
|
var slice = []byte{'H', 'e', 'l', 'l', 'o', ','}
|
|
|
|
func main() {
|
|
ptr := uintptr(unsafe.Pointer(&slice)) + 100
|
|
header := (*reflect.SliceHeader)(unsafe.Pointer(ptr))
|
|
header.Data += 1
|
|
fmt.Printf("%d %d\n", cap(slice), header.Cap)
|
|
}
|