mirror of
https://github.com/golang/go
synced 2024-10-05 14:01:21 -06:00
[dev.ssa] cmd/compile: make zero-divide panic from div/mod explicit
Added an explicit compare-zero and branch-to-panic for integer division and mod so that other optimizations will not be fooled by their implicit panics. Change-Id: Ibf96f636b541c0088861907c537a6beb4b99fa4c Reviewed-on: https://go-review.googlesource.com/16450 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
c24681ae2e
commit
18559e2da7
@ -858,6 +858,8 @@ var Panicindex *Node
|
||||
|
||||
var panicslice *Node
|
||||
|
||||
var panicdivide *Node
|
||||
|
||||
var throwreturn *Node
|
||||
|
||||
var growslice *Node
|
||||
|
@ -339,6 +339,7 @@ func compile(fn *Node) {
|
||||
Deferreturn = Sysfunc("deferreturn")
|
||||
Panicindex = Sysfunc("panicindex")
|
||||
panicslice = Sysfunc("panicslice")
|
||||
panicdivide = Sysfunc("panicdivide")
|
||||
throwreturn = Sysfunc("throwreturn")
|
||||
growslice = Sysfunc("growslice")
|
||||
typedmemmove_nostore = Sysfunc("typedmemmove_nostore")
|
||||
|
@ -1655,9 +1655,22 @@ func (s *state) expr(n *Node) *ssa.Value {
|
||||
xreal = s.newValue1(ssa.OpCvt64Fto32F, pt, xreal)
|
||||
ximag = s.newValue1(ssa.OpCvt64Fto32F, pt, ximag)
|
||||
}
|
||||
|
||||
return s.newValue2(ssa.OpComplexMake, n.Type, xreal, ximag)
|
||||
}
|
||||
if n.Type.IsFloat() {
|
||||
return s.newValue2(s.ssaOp(n.Op, n.Type), a.Type, a, b)
|
||||
} else {
|
||||
// do a size-appropriate check for zero
|
||||
cmp := s.newValue2(s.ssaOp(ONE, n.Type), Types[TBOOL], b, s.zeroVal(n.Type))
|
||||
s.check(cmp, panicdivide)
|
||||
return s.newValue2(s.ssaOp(n.Op, n.Type), a.Type, a, b)
|
||||
}
|
||||
case OMOD:
|
||||
a := s.expr(n.Left)
|
||||
b := s.expr(n.Right)
|
||||
// do a size-appropriate check for zero
|
||||
cmp := s.newValue2(s.ssaOp(ONE, n.Type), Types[TBOOL], b, s.zeroVal(n.Type))
|
||||
s.check(cmp, panicdivide)
|
||||
return s.newValue2(s.ssaOp(n.Op, n.Type), a.Type, a, b)
|
||||
case OADD, OSUB:
|
||||
a := s.expr(n.Left)
|
||||
@ -1670,7 +1683,7 @@ func (s *state) expr(n *Node) *ssa.Value {
|
||||
s.newValue2(op, pt, s.newValue1(ssa.OpComplexImag, pt, a), s.newValue1(ssa.OpComplexImag, pt, b)))
|
||||
}
|
||||
return s.newValue2(s.ssaOp(n.Op, n.Type), a.Type, a, b)
|
||||
case OAND, OOR, OMOD, OHMUL, OXOR:
|
||||
case OAND, OOR, OHMUL, OXOR:
|
||||
a := s.expr(n.Left)
|
||||
b := s.expr(n.Right)
|
||||
return s.newValue2(s.ssaOp(n.Op, n.Type), a.Type, a, b)
|
||||
|
Loading…
Reference in New Issue
Block a user