summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpp2cc.py3
-rw-r--r--tests/params.c7
-rw-r--r--tests/read-timer.c6
3 files changed, 15 insertions, 1 deletions
diff --git a/pp2cc.py b/pp2cc.py
index 2f58f9b..81f6a79 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -1317,7 +1317,8 @@ class Parse(object):
linked_node))
if op == "-":
# negating a value in PP2 is flipping the WORDSIZE-th bit
- value = operand ^ msb
+ value = -operand
+ #(operand ^ (pow(2, self.WORDSIZE) - 1)) + 1
elif op == "~":
# invert all bits
value = operand ^ (pow(2, self.WORDSIZE) - 1)
diff --git a/tests/params.c b/tests/params.c
index 2232fdd..2073000 100644
--- a/tests/params.c
+++ b/tests/params.c
@@ -3,9 +3,16 @@ int square(int x) {
res = x * x;
return res;
}
+int div(int a, int b) {
+ int aa = -a;
+ int bb = 1 * b;
+ return aa / bb;
+}
int main() {
int x;
x = square(9);// 81
e:goto e;
+ x = div(-150, 10);// 15
+ ef:goto ef;
return x;
}
diff --git a/tests/read-timer.c b/tests/read-timer.c
new file mode 100644
index 0000000..d7bb2c3
--- /dev/null
+++ b/tests/read-timer.c
@@ -0,0 +1,6 @@
+int timer;
+int *timerp = (int*)-3;
+void main() {
+ timer = *timerp;
+ g:goto g;
+}