Skip to content

Commit f249fa2

Browse files
committed
cmd/compile: only update source type when processing struct/array
CL 360057 fixed missing update source type in storeArgOrLoad. However, we should only update the type when processing struct/array. If we update the type right before calling storeArgOrLoad, we may generate a value with invalid type, e.g, OpStructSelect with non-struct type. Fixes #49378 Change-Id: Ib7e10f72f818880f550aae5c9f653db463ce29b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/361594 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent a0d661a commit f249fa2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,11 +954,11 @@ func (x *expandState) storeArgOrLoad(pos src.XPos, b *Block, source, mem *Value,
954954
elt := t.Elem()
955955
if source.Type != t && t.NumElem() == 1 && elt.Size() == t.Size() && t.Size() == x.regSize {
956956
t = removeTrivialWrapperTypes(t)
957-
source.Type = t
958957
// it could be a leaf type, but the "leaf" could be complex64 (for example)
959958
return x.storeArgOrLoad(pos, b, source, mem, t, storeOffset, loadRegOffset, storeRc)
960959
}
961960
eltRO := x.regWidth(elt)
961+
source.Type = t
962962
for i := int64(0); i < t.NumElem(); i++ {
963963
sel := source.Block.NewValue1I(pos, OpArraySelect, elt, i, source)
964964
mem = x.storeArgOrLoad(pos, b, sel, mem, elt, storeOffset+i*elt.Size(), loadRegOffset, storeRc.at(t, 0))
@@ -988,11 +988,11 @@ func (x *expandState) storeArgOrLoad(pos src.XPos, b *Block, source, mem *Value,
988988
// v139 is later stored as an intVal == struct{val *big.Int} which naively requires the fields of
989989
// of a *uint8, which does not succeed.
990990
t = removeTrivialWrapperTypes(t)
991-
source.Type = t
992991
// it could be a leaf type, but the "leaf" could be complex64 (for example)
993992
return x.storeArgOrLoad(pos, b, source, mem, t, storeOffset, loadRegOffset, storeRc)
994993
}
995994

995+
source.Type = t
996996
for i := 0; i < t.NumFields(); i++ {
997997
fld := t.Field(i)
998998
sel := source.Block.NewValue1I(pos, OpStructSelect, fld.Type, int64(i), source)

test/fixedbugs/issue49378.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// compile
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
func f(i int) {
10+
var s1 struct {
11+
s struct{ s struct{ i int } }
12+
}
13+
var s2, s3 struct {
14+
a struct{ i int }
15+
b int
16+
}
17+
func() {
18+
i = 1 + 2*i + s3.a.i + func() int {
19+
s2.a, s2.b = s3.a, s3.b
20+
return 0
21+
}() + func(*int) int {
22+
return s1.s.s.i
23+
}(new(int))
24+
}()
25+
}

0 commit comments

Comments
 (0)