File tree Expand file tree Collapse file tree 4 files changed +42
-5
lines changed Expand file tree Collapse file tree 4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -86,12 +86,15 @@ type AuxCall struct {
86
86
abiInfo * abi.ABIParamResultInfo // TODO remove fields above redundant with this information.
87
87
}
88
88
89
- // ResultForOffset returns the index of the result at a particular offset among the results
89
+ // ResultForOffsetAndType returns the index of a t-typed result at *A* particular offset among the results.
90
+ // An arbitrary number of zero-width-typed results may reside at the same offset with a single not-zero-width
91
+ // typed result, but the ones with the same type are all indistinguishable so it doesn't matter "which one"
92
+ // is obtained.
90
93
// This does not include the mem result for the call opcode.
91
- func (a * AuxCall ) ResultForOffset (offset int64 ) int64 {
94
+ func (a * AuxCall ) ResultForOffsetAndType (offset int64 , t * types. Type ) int64 {
92
95
which := int64 (- 1 )
93
96
for i := int64 (0 ); i < a .NResults (); i ++ { // note aux NResults does not include mem result.
94
- if a .OffsetOfResult (i ) == offset {
97
+ if a .OffsetOfResult (i ) == offset && a . TypeOfResult ( i ) == t {
95
98
which = i
96
99
break
97
100
}
Original file line number Diff line number Diff line change @@ -2909,7 +2909,7 @@ func (s *state) expr(n ir.Node) *ssa.Value {
2909
2909
addr := s .constOffPtrSP (types .NewPtr (n .Type ()), n .Offset )
2910
2910
return s .rawLoad (n .Type (), addr )
2911
2911
}
2912
- which := s .prevCall .Aux .(* ssa.AuxCall ).ResultForOffset (n .Offset )
2912
+ which := s .prevCall .Aux .(* ssa.AuxCall ).ResultForOffsetAndType (n .Offset , n . Type () )
2913
2913
if which == - 1 {
2914
2914
// Do the old thing // TODO: Panic instead.
2915
2915
addr := s .constOffPtrSP (types .NewPtr (n .Type ()), n .Offset )
@@ -5119,7 +5119,7 @@ func (s *state) addr(n ir.Node) *ssa.Value {
5119
5119
if s .prevCall == nil || s .prevCall .Op != ssa .OpStaticLECall && s .prevCall .Op != ssa .OpInterLECall && s .prevCall .Op != ssa .OpClosureLECall {
5120
5120
return s .constOffPtrSP (t , n .Offset )
5121
5121
}
5122
- which := s .prevCall .Aux .(* ssa.AuxCall ).ResultForOffset (n .Offset )
5122
+ which := s .prevCall .Aux .(* ssa.AuxCall ).ResultForOffsetAndType (n .Offset , n . Type () )
5123
5123
if which == - 1 {
5124
5124
// Do the old thing // TODO: Panic instead.
5125
5125
return s .constOffPtrSP (t , n .Offset )
Original file line number Diff line number Diff line change
1
+ // run
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 main
8
+
9
+ import "fmt"
10
+
11
+ type Z struct {
12
+ }
13
+
14
+ type NZ struct {
15
+ x , y int
16
+ }
17
+
18
+ //go:noinline
19
+ func f (x ,y int ) (Z ,NZ ,Z ) {
20
+ var z Z
21
+ return z ,NZ {x ,y },z
22
+ }
23
+
24
+ //go:noinline
25
+ func g () (Z ,NZ ,Z ) {
26
+ a ,b ,c := f (3 ,4 )
27
+ return c ,b ,a
28
+ }
29
+
30
+ func main () {
31
+ _ ,b ,_ := g ()
32
+ fmt .Println (b .x + b .y )
33
+ }
Original file line number Diff line number Diff line change
1
+ 7
You can’t perform that action at this time.
0 commit comments