Skip to content
This repository has been archived by the owner on Dec 30, 2018. It is now read-only.

Commit

Permalink
vrp: correctly flip token
Browse files Browse the repository at this point in the history
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
dominikh committed Dec 6, 2016
1 parent 0ea8279 commit 1ed90c8
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions vrp/vrp.go
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ed90c8

Please sign in to comment.