From eabfc84fac0e42635cccabf5c8f883585da60de8 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 29 Nov 2011 11:49:26 +0000 Subject: Fix value for substraction in constant expressions --- pp2cc.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pp2cc.py') diff --git a/pp2cc.py b/pp2cc.py index ecd73a8..a1d1bbd 100755 --- a/pp2cc.py +++ b/pp2cc.py @@ -1112,6 +1112,10 @@ class Parse(object): else: operand1 = self.determineConstValue(node.left) operand2 = self.determineConstValue(node.right) + if op == "-": + # ensure that the result of substraction is positive by + # setting the (WORDSIZE+1)-nth bit on the first operand + operand1 |= pow(2, self.WORDSIZE) if op in ("<", ">", "<=", ">="): value = int(getattr(operator, op)(operand1, operand2)) # 0 < 1 and -2 < -1 holds, but -1 < 0 does not. If the sign -- cgit v1.2.1