code: plan9front

Download patch

ref: 47165e1c2ccc0471349691cc92f64f81984b18c5
parent: 090af6255bebf0129c891116b53b31808fe49dc7
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon May 8 22:17:34 EDT 2023

5c, 7c: fix !x compilation when x is a negative float

test case:
void
main(int, char **)
{
	union {
		float f;
		u32int u;
	}x;
	x.u = 1U<<31;
	print("%d %d\n", !x.f, x.f == 0.0f);
	exits(nil);
}

--- a/sys/src/cmd/5c/cgen.c
+++ b/sys/src/cmd/5c/cgen.c
@@ -729,9 +729,12 @@
 		o = ONE;
 		if(true)
 			o = comrel[relindex(o)];
-		if(typefd[n->type->etype]) {
-			gopcode(true ? o | BTRUE : o, nodfconst(0), &nod, Z);
-		} else
+		if(typefd[n->type->etype]){
+			regalloc(&nod1, n, Z);
+			gmove(nodfconst(0.0), &nod1);
+			gopcode(true ? o | BTRUE : o, &nod1, &nod, Z);
+			regfree(&nod1);
+		}else
 			gopcode(o, nodconst(0), &nod, Z);
 		regfree(&nod);
 		goto com;
--- a/sys/src/cmd/7c/cgen.c
+++ b/sys/src/cmd/7c/cgen.c
@@ -738,8 +738,11 @@
 		if(true)
 			o = OEQ;
 		if(typefd[n->type->etype]) {
-			gopcode(true ? o | BTRUE : o, nodfconst(0), &nod, Z);
-		} else
+			regalloc(&nod1, n, Z);
+			gmove(nodfconst(0.0), &nod1);
+			gopcode(true ? o | BTRUE : o, &nod1, &nod, Z);
+			regfree(&nod1);
+		}else
 			gopcode(o, nodconst(0), &nod, Z);
 		regfree(&nod);
 		goto com;