Skip to content

Commit 2308c9c

Browse files
randall77andybons
authored andcommitted
[release-branch.go1.9] cmd/compile: fix decomposition of 1-element arrays
The offending rule could move the load to a different block, which is always a bad idea. Fixes #22683 Change-Id: I973c88389b2359f734924d9f45c3fb38e166691d Reviewed-on: https://go-review.googlesource.com/77331 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent f8a2209 commit 2308c9c

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

src/cmd/compile/internal/ssa/gen/generic.rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@
819819
(Store _ (ArrayMake0) mem) -> mem
820820
(Store dst (ArrayMake1 e) mem) -> (Store {e.Type} dst e mem)
821821

822-
(ArraySelect [0] (Load ptr mem)) -> (Load ptr mem)
822+
(ArraySelect [0] x:(Load ptr mem)) -> @x.Block (Load <v.Type> ptr mem)
823823

824824
// Putting [1]{*byte} and similar into direct interfaces.
825825
(IMake typ (ArrayMake1 val)) -> (IMake typ val)

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

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue22683.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// cmpout
2+
3+
// Copyright 2017 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 (
10+
"fmt"
11+
)
12+
13+
type foo struct {
14+
bar [1]*int
15+
}
16+
17+
func main() {
18+
ch := make(chan foo, 2)
19+
var a int
20+
var b [1]*int
21+
b[0] = &a
22+
ch <- foo{bar: b}
23+
close(ch)
24+
25+
for v := range ch {
26+
for i := 0; i < 1; i++ {
27+
fmt.Println(v.bar[0] != nil)
28+
}
29+
}
30+
}

test/fixedbugs/issue22683.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true

0 commit comments

Comments
 (0)