commit 664f0e4c15d0ece133ed752dbbf34faecf1f540d
parent d26a8c64f5d47e5ad3033285f06b314306ae5ed3
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 15 Nov 2022 15:16:39 -0500
cc/vm/i386: fix mis-mutation on unaryop applied to pointers
Diffstat:
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/cc/vm/i386.fs b/fs/cc/vm/i386.fs
@@ -213,7 +213,7 @@ UNOPCNT wordtbl _tbl
:w ( boolify ) neg, _z>vmop ;
:w ( boolnot ) neg, vmop :compile 0 i) mov, vmop :compile setz, ;
-: unop, ( opid -- ) vmop :>reg vmop :compilesz _tbl swap wexec ;
+: unop, ( opid -- ) vmop :>res vmop :compilesz _tbl swap wexec ;
: _doit vmop :compilesz ( n ) case
1 of = inc, endof
diff --git a/fs/tests/app/uxn/vm.fs b/fs/tests/app/uxn/vm.fs
@@ -7,8 +7,7 @@ wst 42 push8
wst $1234 push16
create expected 4 nc, 3 42 $12 $34
wst expected 4 []= #
-\ TODO: this line below is broken on i386
-\ wst pop8 $34 #eq
+wst pop8 $34 #eq
\ TODO: this line below is broken in all arches
\ wst pop16 $2a12 #eq
diff --git a/fs/tests/cc/cc.fs b/fs/tests/cc/cc.fs
@@ -59,7 +59,6 @@ S" foobar" dup 2 'X' set8b S" fXobar" #s=
S" foobar" dup 6 'X' set8b S" foobaX" #s=
5 whilesum 15 #eq
5 dowhilesum 15 #eq
-42 unaryopmut 42 #eq
create mydata 42 , $12345678 , $23456789 ,
mydata structget $35 #eq
mydata $42 structset mydata 4 + @ $42345678 #eq
@@ -91,6 +90,9 @@ opwidth6 1 #eq
to' myval ptrari4 not #
1 to+ myval
to' myval ptrari4 #
+42 unaryop1 42 #eq
+to' myval unaryop2 to' myval #eq
+myval 42 #eq
\ and what about inline functions?
:c int myinline() { return 42; }
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -227,11 +227,6 @@ void dowhilesum(int n) {
} while (n);
return res;
}
-// unary op, apart from ++ and --, *don't* modify their target.
-int unaryopmut(int n) {
- !n;
- return n;
-}
typedef char MyType;
typedef MyType** MyTypePtr;
@@ -336,7 +331,7 @@ int structop4() {
// the combination of struct pointer, struct field subscripting, assignment and
// postop all at once caused the i386 VM to misallocate registers.
int structop5() {
- MyStruct *s = globdata;
+ MyStruct *s = &globdata;
s->foo = 1;
s->baz[s->foo++] = 42;
return globdata.baz[1];
@@ -395,3 +390,13 @@ int* ptrari3(int *lo, int *hi) {
int ptrari4(int *a) {
return *(a++) == 42;
}
+// unary op, apart from ++ and --, *don't* modify their target.
+int unaryop1(int n) {
+ !n;
+ return n;
+}
+// ... even if it's a pointer!
+int* unaryop2(int *n) {
+ !*n;
+ return n;
+}