summaryrefslogtreecommitdiff
path: root/pp2cc.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-11-29 11:49:26 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-11-29 11:49:26 +0000
commiteabfc84fac0e42635cccabf5c8f883585da60de8 (patch)
tree15005a40fdcc49089d69ea1fafb7b310f5e350d5 /pp2cc.py
parent90ec610f709dc7cb25bbb3c288ec3e80ae0bc97e (diff)
downloadpp2cc-eabfc84fac0e42635cccabf5c8f883585da60de8.tar.gz
Fix value for substraction in constant expressions
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-xpp2cc.py4
1 files changed, 4 insertions, 0 deletions
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