Skip to content

Commit

Permalink
cmd/compile/internal/gc: treat cap/len as safe in mayAffectMemory
Browse files Browse the repository at this point in the history
OLEN and OCAP can't affect memory state as long as their
arguments don't.

Re-organized case bodies to avoid duplicating same branches for
recursive invocations.

Change-Id: I30407143429f7dd1891badb70df88969ed267535
Reviewed-on: https://go-review.googlesource.com/133555
Run-TryBot: Iskander Sharipov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
Iskander Sharipov committed Sep 17, 2018
1 parent 930ce09 commit 2d82465
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/cmd/compile/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,18 +689,16 @@ func (e *EscState) mayAffectMemory(n *Node) bool {
switch n.Op {
case ONAME, OCLOSUREVAR, OLITERAL:
return false
case ODOT, ODOTPTR:
return e.mayAffectMemory(n.Left)
case OIND, OCONVNOP:
return e.mayAffectMemory(n.Left)
case OCONV:
return e.mayAffectMemory(n.Left)
case OINDEX:
return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right)
case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD:

// Left+Right group.
case OINDEX, OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD:
return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right)
case ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF:

// Left group.
case ODOT, ODOTPTR, OIND, OCONVNOP, OCONV, OLEN, OCAP,
ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF:
return e.mayAffectMemory(n.Left)

default:
return true
}
Expand Down

0 comments on commit 2d82465

Please sign in to comment.