@@ -600,11 +600,23 @@ func walkMakeSlice(n *ir.MakeExpr, init *ir.Nodes) ir.Node {
600
600
lenCap .Body .Append (mkcall ("panicmakeslicecap" , nil , & lenCap .Body ))
601
601
nif .Body .Append (lenCap )
602
602
603
- t := types .NewArray (t .Elem (), K ) // [K]E
604
- arr := typecheck .TempAt (base .Pos , ir .CurFunc , t ) // var arr [K]E
605
- nif .Body .Append (ir .NewAssignStmt (base .Pos , arr , nil )) // arr = {} (zero it)
606
- s := ir .NewSliceExpr (base .Pos , ir .OSLICE , arr , nil , len , cap ) // arr[:len:cap]
607
- nif .Body .Append (ir .NewAssignStmt (base .Pos , slice , s )) // slice = arr[:len:cap]
603
+ t := types .NewArray (t .Elem (), K ) // [K]E
604
+ // Wrap in a struct containing a [0]uintptr field to force
605
+ // pointer alignment. Some user code expects higher alignment
606
+ // than what is guaranteed by the element type, because that's
607
+ // the behavior they observed of mallocgc, and then relied upon.
608
+ // See issue 73199.
609
+ field := typecheck .Lookup ("arr" )
610
+ t = types .NewStruct ([]* types.Field {
611
+ {Sym : types .BlankSym , Type : types .NewArray (types .Types [types .TUINTPTR ], 0 )},
612
+ {Sym : field , Type : t },
613
+ })
614
+ t .SetNoalg (true )
615
+ store := typecheck .TempAt (base .Pos , ir .CurFunc , t ) // var store struct{_ uintptr[0]; arr [K]E}
616
+ nif .Body .Append (ir .NewAssignStmt (base .Pos , store , nil )) // store = {} (zero it)
617
+ arr := ir .NewSelectorExpr (base .Pos , ir .ODOT , store , field ) // arr = store.arr
618
+ s := ir .NewSliceExpr (base .Pos , ir .OSLICE , arr , nil , len , cap ) // store.arr[:len:cap]
619
+ nif .Body .Append (ir .NewAssignStmt (base .Pos , slice , s )) // slice = store.arr[:len:cap]
608
620
609
621
appendWalkStmt (init , typecheck .Stmt (nif ))
610
622
0 commit comments