summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-11-28 21:11:37 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-11-28 21:11:37 +0000
commit64e5f4cbc2819b7f17eab7fc84593d15887d7000 (patch)
treec3110ad3bdf3ebb84435a6bbde56e9a2f2053064
parent308fc185484231d3d73174b68f455c0578469373 (diff)
downloadpp2cc-64e5f4cbc2819b7f17eab7fc84593d15887d7000.tar.gz
Make unary one's complement operator ~ treat signed integers as unsigned
-rwxr-xr-xpp2cc.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/pp2cc.py b/pp2cc.py
index 5dce20c..b130356 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -622,9 +622,9 @@ class Parse(object):
elif op == "-":
lines.append(self.asm.binary_op("MULS", reg, "-1"))
elif op == "~":
- # XXX unsigned vs signed integers. Assume signed for now
- mask = "1" * (self.WORDSIZE - 1)
- lines.append(self.asm.binary_op("XOR", reg, "%0" + mask))
+ # Conforming K&R A7.4.6, signed types are treated as unsigned when
+ # applying ~
+ lines.append(self.asm.binary_op("XOR", reg, "%1"))
elif op == "!":
lbl_false = self.uniqLbl("not_false")
lbl_true = self.uniqLbl("not_true")