]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make sure field offset is aligned for structure splitting
authorDavid Chase <drchase@google.com>
Mon, 26 Oct 2020 23:06:39 +0000 (19:06 -0400)
committerDavid Chase <drchase@google.com>
Wed, 28 Oct 2020 01:22:47 +0000 (01:22 +0000)
Always use the aligned form -- the old code sometimes could
at least nominally use a misaligned field in an SSA-able struct,
even if not actually.

Fixes #42181.

Change-Id: Ibdce0985f9349da70921a37423054b85ee4200d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/265277
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: David Chase <drchase@google.com>

src/cmd/compile/internal/gc/ssa.go

index 44883379245afe7d28fbd5d9830c3c1a95a055a0..fb9d3e811a3b92699376f5212de8cd1c3cb375f2 100644 (file)
@@ -6978,15 +6978,10 @@ func (e *ssafn) SplitInt64(name ssa.LocalSlot) (ssa.LocalSlot, ssa.LocalSlot) {
 
 func (e *ssafn) SplitStruct(name ssa.LocalSlot, i int) ssa.LocalSlot {
        st := name.Type
-       ft := st.FieldType(i)
-       var offset int64
-       for f := 0; f < i; f++ {
-               offset += st.FieldType(f).Size()
-       }
        // Note: the _ field may appear several times.  But
        // have no fear, identically-named but distinct Autos are
        // ok, albeit maybe confusing for a debugger.
-       return e.SplitSlot(&name, "."+st.FieldName(i), offset, ft)
+       return e.SplitSlot(&name, "."+st.FieldName(i), st.FieldOff(i), st.FieldType(i))
 }
 
 func (e *ssafn) SplitArray(name ssa.LocalSlot) ssa.LocalSlot {