Permalink
Browse files

vrp: correctly flip token

When flipping the lhs and rhs, the token shouldn't be inverted, it
should be flipped. For example, 'lhs > rhs' should turn into 'rhs <
lhs', not rhs <= lhs'.
  • Loading branch information...
1 parent 0ea8279 commit 1ed90c8ee41b1eb0d9b95f784038536abde0c7a0 @dominikh committed Dec 6, 2016
Showing with 22 additions and 3 deletions.
  1. +22 −3 vrp/vrp.go
View
@@ -135,7 +135,7 @@ func sigmaInteger(g *Graph, ins *ssa.Sigma, cond *ssa.BinOp, ops []*ssa.Value) C
} else {
a = *ops[1]
b = *ops[0]
- op = invertToken(op)
+ op = flipToken(op)
}
return NewIntIntersectionConstraint(a, b, op, g.ranges, ins)
}
@@ -161,7 +161,7 @@ func sigmaString(g *Graph, ins *ssa.Sigma, cond *ssa.BinOp, ops []*ssa.Value) Co
} else {
a = *ops[1]
b = *ops[0]
- op = invertToken(op)
+ op = flipToken(op)
}
return NewStringIntersectionConstraint(a, b, op, g.ranges, ins)
}
@@ -172,7 +172,7 @@ func sigmaString(g *Graph, ins *ssa.Sigma, cond *ssa.BinOp, ops []*ssa.Value) Co
} else {
a = *ops[1]
b = *ops[0]
- op = invertToken(op)
+ op = flipToken(op)
}
return NewStringIntersectionConstraint(a, b, op, g.ranges, ins)
}
@@ -1003,6 +1003,25 @@ func invertToken(tok token.Token) token.Token {
}
}
+func flipToken(tok token.Token) token.Token {
+ switch tok {
+ case token.LSS:
+ return token.GTR
+ case token.GTR:
+ return token.LSS
+ case token.EQL:
+ return token.EQL
+ case token.NEQ:
+ return token.NEQ
+ case token.GEQ:
+ return token.LEQ
+ case token.LEQ:
+ return token.GEQ
+ default:
+ panic(fmt.Sprintf("unsupported token %s", tok))
+ }
+}
+
type CopyConstraint struct {
aConstraint
X ssa.Value

0 comments on commit 1ed90c8

Please sign in to comment.