commit bd25b5a311d0e9fb99eb88364be986b6b7209baf
parent 27ab1afc6d69bbe3f9aeed87d7e25c522a621a28
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sat, 1 Apr 2023 21:21:18 -0400
halcc: opwidth tests all passing!
no fix necessary!
Diffstat:
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs
@@ -99,7 +99,6 @@ structop5 42 #eq
structop6 54 #eq
structop7 42 #eq
12 42 structop8 54 #eq
-testend \s
cond2 scnt not # \ don't crash or leak
opwidth1 42 #eq
opwidth2 42 #eq
@@ -109,6 +108,7 @@ opwidth5 42 #eq
opwidth6 1 #eq
$ff 1 opwidth7 $1fe #eq
opwidth8 0 #eq
+testend \s
42 50 ptrari3 46 #eq
41 value myval
to' myval ptrari4 not #
diff --git a/fs/tests/comp/c/test2.c b/fs/tests/comp/c/test2.c
@@ -421,3 +421,65 @@ int structop8(int a, int b) {
return ptr->func(a, b);
}
+// we used to leak VM ops in condition blocks without {}
+void cond1() {
+ int x = 42;
+ if (x==0) x++; else x--;
+}
+
+// Having a return statement in a conditional, if nothing came after it, would
+// prevent the parent from having an implicit return.
+void cond2() { if (0) return; }
+// The forth VM used to assign to the SF in the wrong width
+short opwidth1() {
+ short x = 42;
+ short y = $12345678;
+ return x;
+}
+short opwidth2() {
+ short x = 42;
+ short y = 12;
+ y += $12345678;
+ return x;
+}
+// The i386 VM didn't carry the $100
+int opwidth3() {
+ int x = 42;
+ unsigned char y = $ff;
+ x += y;
+ return x;
+}
+// The Forth VM lost track of opwidth through expressions
+// Forth VM and i386 VM mis-initialized the char array.
+char opwidth4() {
+ char x[2] = {1, 2};
+ int y = 0;
+ x[y] = 12;
+ return x[0] + x[1];
+}
+// The Forth and i386 VMs didn't properly apply size in inc/dec ops
+unsigned char opwidth5() {
+ unsigned char x = 42;
+ unsigned char y = $ff;
+ y++; y--;
+ ++y;
+ return x;
+}
+// The i386 VM always performed "test" on a 4b width
+short opwidth6() {
+ short x = 42;
+ short y = 0;
+ if (y) return 0; else return 1;
+}
+// The i386 VM didn't properly promote "a" to int
+int opwidth7(char a, int b) {
+ return a << b;
+}
+// Under i386, integer promotion of a non-reg operand would result in a buggy
+// operation because we would read too much information from memory.
+int opwidth8() {
+ int x = 54;
+ globdata.baz[0] = 42;
+ globdata.baz[1] = 1;
+ return x < globdata.baz[0];
+}