shithub: riscv

Download patch

ref: 63191949b911658c3774e727061fcf166ad9ace2
parent: 159f96c534563f26edeeb227cd00f1bdd3bd2596
author: cinap_lenrek <[email protected]>
date: Wed Jun 19 19:50:33 EDT 2019

cc: remove nullwarn() from OCAST codegen, zap void casts

implicit casts would cause spurious "result of operation not used"
warnings such as ape's stdio putc() macro.

make (void) casts non-ops when the casted expression has no
side effects. this avoid spurious warning with ape's assert()
macro.

--- a/sys/src/cmd/1c/cgen.c
+++ b/sys/src/cmd/1c/cgen.c
@@ -376,10 +376,7 @@
 
 	case OCAST:
 		if(result == D_NONE) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, D_NONE, Z);
+			cgen(l, D_NONE, Z);
 			break;
 		}
 		lg = result;
--- a/sys/src/cmd/2c/cgen.c
+++ b/sys/src/cmd/2c/cgen.c
@@ -376,10 +376,7 @@
 
 	case OCAST:
 		if(result == D_NONE) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, D_NONE, Z);
+			cgen(l, D_NONE, Z);
 			break;
 		}
 		lg = result;
--- a/sys/src/cmd/5c/cgen.c
+++ b/sys/src/cmd/5c/cgen.c
@@ -399,10 +399,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
@@ -927,7 +924,7 @@
 
 	case OCAST:
 		if(nn == Z){
-			nullwarn(l, Z);
+			cgen(l, Z);
 			goto Out;
 		}
 		if(typeilp[n->type->etype] && typev[l->type->etype]){
--- a/sys/src/cmd/6c/cgen.c
+++ b/sys/src/cmd/6c/cgen.c
@@ -976,10 +976,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
--- a/sys/src/cmd/6c/sgen.c
+++ b/sys/src/cmd/6c/sgen.c
@@ -326,7 +326,7 @@
 		break;
 
 	case OCAST:
-		if(l->type->etype == TUVLONG && typefd[n->type->etype])
+		if(l != Z && l->type->etype == TUVLONG && typefd[n->type->etype])
 			n->complex += 2;
 		break;
 
--- a/sys/src/cmd/7c/cgen.c
+++ b/sys/src/cmd/7c/cgen.c
@@ -442,7 +442,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			nullwarn(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
--- a/sys/src/cmd/8c/cgen.c
+++ b/sys/src/cmd/8c/cgen.c
@@ -994,10 +994,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
--- a/sys/src/cmd/cc/com.c
+++ b/sys/src/cmd/cc/com.c
@@ -1073,6 +1073,11 @@
 		break;
 
 	case OCAST:
+		if(n->type == types[TVOID] && !side(l)){
+			n->left = Z;
+			n->type = T;
+			break;
+		}
 		if(castucom(n))
 			warn(n, "32-bit unsigned complement zero-extended to 64 bits");
 		ccom(l);
--- a/sys/src/cmd/kc/cgen.c
+++ b/sys/src/cmd/kc/cgen.c
@@ -358,10 +358,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
--- a/sys/src/cmd/qc/cgen.c
+++ b/sys/src/cmd/qc/cgen.c
@@ -395,10 +395,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*
--- a/sys/src/cmd/vc/cgen.c
+++ b/sys/src/cmd/vc/cgen.c
@@ -359,10 +359,7 @@
 
 	case OCAST:
 		if(nn == Z) {
-			if(n->type != types[TVOID])
-				nullwarn(l, Z);
-			else
-				cgen(l, Z);
+			cgen(l, Z);
 			break;
 		}
 		/*