cmd/compile/internal/gc: fix mayAffectMemory in esc.go

For OINDEX and other Left+Right nodes, we want the whole
node to be considered as "may affect memory" if either
of Left or Right affect memory. Initial implementation
only considered node as such if both Left and Right were non-safe.

Change-Id: Icfb965a0b4c24d8f83f3722216db068dad2eba95
Reviewed-on: https://go-review.googlesource.com/133275
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Iskander Sharipov 2018-09-04 17:17:32 +03:00
parent 3fd364988c
commit 4cf33e361a
2 changed files with 10 additions and 2 deletions

View file

@ -696,9 +696,9 @@ func (e *EscState) mayAffectMemory(n *Node) bool {
case OCONV:
return e.mayAffectMemory(n.Left)
case OINDEX:
return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right)
return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right)
case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD:
return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right)
return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right)
case ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF:
return e.mayAffectMemory(n.Left)
default:

View file

@ -11,6 +11,8 @@
package escape
func zero() int { return 0 }
var sink interface{}
// in -> out
@ -62,6 +64,12 @@ func paramArraySelfAssign(p *PairOfPairs) { // ERROR "p does not escape"
p.pairs[0] = p.pairs[1] // ERROR "ignoring self-assignment in p.pairs\[0\] = p.pairs\[1\]"
}
func paramArraySelfAssignUnsafeIndex(p *PairOfPairs) { // ERROR "leaking param content: p"
// Function call inside index disables self-assignment case to trigger.
p.pairs[zero()] = p.pairs[1]
p.pairs[zero()+1] = p.pairs[1]
}
type PairOfPairs struct {
pairs [2]*Pair
}