File tree 2 files changed +36
-1
lines changed
src/cmd/compile/internal/walk 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -621,6 +621,12 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool {
621
621
// not a special composite literal assignment
622
622
return false
623
623
}
624
+ if x .Addrtaken () {
625
+ // If x is address-taken, the RHS may (implicitly) uses LHS.
626
+ // Not safe to do a special composite literal assignment
627
+ // (which may expand to multiple assignments).
628
+ return false
629
+ }
624
630
625
631
switch n .Y .Op () {
626
632
default :
@@ -629,7 +635,7 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool {
629
635
630
636
case ir .OSTRUCTLIT , ir .OARRAYLIT , ir .OSLICELIT , ir .OMAPLIT :
631
637
if ir .Any (n .Y , func (y ir.Node ) bool { return ir .Uses (y , x ) }) {
632
- // not a special composite literal assignment
638
+ // not safe to do a special composite literal assignment if RHS uses LHS.
633
639
return false
634
640
}
635
641
anylit (n .Y , n .X , init )
Original file line number Diff line number Diff line change
1
+ // run
2
+
3
+ // Copyright 2022 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
+ // Issue 52953: miscompilation for composite literal assignment
8
+ // when LHS is address-taken.
9
+
10
+ package main
11
+
12
+ type T struct {
13
+ Field1 bool
14
+ }
15
+
16
+ func main () {
17
+ var ret T
18
+ ret .Field1 = true
19
+ var v * bool = & ret .Field1
20
+ ret = T {Field1 : * v }
21
+ check (ret .Field1 )
22
+ }
23
+
24
+ //go:noinline
25
+ func check (b bool ) {
26
+ if ! b {
27
+ panic ("FAIL" )
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments