File tree 2 files changed +10
-4
lines changed
2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -3910,7 +3910,7 @@ func isRuneCount(n *Node) bool {
3910
3910
}
3911
3911
3912
3912
func walkCheckPtrAlignment (n * Node , init * Nodes ) * Node {
3913
- if n .Type .Elem ().Alignment () == 1 {
3913
+ if n .Type .Elem ().Alignment () == 1 && n . Type . Elem (). Size () == 1 {
3914
3914
return n
3915
3915
}
3916
3916
Original file line number Diff line number Diff line change @@ -7,14 +7,20 @@ package runtime
7
7
import "unsafe"
8
8
9
9
type ptrAlign struct {
10
- ptr unsafe.Pointer
11
- align uintptr
10
+ ptr unsafe.Pointer
11
+ elem * _type
12
12
}
13
13
14
14
func checkptrAlignment (p unsafe.Pointer , elem * _type ) {
15
+ // Check that (*T)(p) is appropriately aligned.
15
16
// TODO(mdempsky): What about fieldAlign?
16
17
if uintptr (p )& (uintptr (elem .align )- 1 ) != 0 {
17
- panic (ptrAlign {p , uintptr (elem .align )})
18
+ panic (ptrAlign {p , elem })
19
+ }
20
+
21
+ // Check that (*T)(p) doesn't straddle multiple heap objects.
22
+ if elem .size != 1 && checkptrBase (p ) != checkptrBase (add (p , elem .size - 1 )) {
23
+ panic (ptrAlign {p , elem })
18
24
}
19
25
}
20
26
You can’t perform that action at this time.
0 commit comments