mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: don't ICE on unaligned offsets for pointer writes
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>
This commit is contained in:
parent
5c15498609
commit
c4db811e44
@ -53,7 +53,10 @@ func mightContainHeapPointer(ptr *Value, size int64, mem *Value, zeroes map[ID]Z
|
|||||||
}
|
}
|
||||||
|
|
||||||
ptrSize := ptr.Block.Func.Config.PtrSize
|
ptrSize := ptr.Block.Func.Config.PtrSize
|
||||||
if off%ptrSize != 0 || size%ptrSize != 0 {
|
if off%ptrSize != 0 {
|
||||||
|
return true // see issue 61187
|
||||||
|
}
|
||||||
|
if size%ptrSize != 0 {
|
||||||
ptr.Fatalf("unaligned pointer write")
|
ptr.Fatalf("unaligned pointer write")
|
||||||
}
|
}
|
||||||
if off < 0 || off+size > 64*ptrSize {
|
if off < 0 || off+size > 64*ptrSize {
|
||||||
@ -130,7 +133,7 @@ func needWBdst(ptr, mem *Value, zeroes map[ID]ZeroRegion) bool {
|
|||||||
}
|
}
|
||||||
ptrSize := ptr.Block.Func.Config.PtrSize
|
ptrSize := ptr.Block.Func.Config.PtrSize
|
||||||
if off%ptrSize != 0 {
|
if off%ptrSize != 0 {
|
||||||
ptr.Fatalf("unaligned pointer write")
|
return true // see issue 61187
|
||||||
}
|
}
|
||||||
if off < 0 || off >= 64*ptrSize {
|
if off < 0 || off >= 64*ptrSize {
|
||||||
// write goes off end of tracked offsets
|
// write goes off end of tracked offsets
|
||||||
|
22
test/fixedbugs/issue61187.go
Normal file
22
test/fixedbugs/issue61187.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user