shithub: riscv

Download patch

ref: 125ca8ddfee1da241d86f82439e24467b25b310a
parent: 8560a458d2b4ade92ff8354e2a16db3256bead43
author: Jacob Moody <moody@posixcafe.org>
date: Thu Mar 16 00:56:17 EDT 2023

cc: add NORET

--- a/sys/src/cmd/cc/cc.h
+++ b/sys/src/cmd/cc/cc.h
@@ -327,7 +327,7 @@
 	TVOLATILE,
 	TUNSIGNED,
 	TSIGNED,
-	TFILE,
+	TNORET,
 	TOLD,
 	NALLTYPES,
 
@@ -354,9 +354,10 @@
 	GXXX		= 0,
 	GCONSTNT	= 1<<0,
 	GVOLATILE	= 1<<1,
-	NGTYPES		= 1<<2,
+	GNORET		= 1<<2,
+	NGTYPES		= 1<<4,
 
-	GINCOMPLETE	= 1<<2,
+	GINCOMPLETE	= 1<<3,
 };
 enum
 {
@@ -379,7 +380,6 @@
 	BSTRUCT		= 1L<<TSTRUCT,
 	BUNION		= 1L<<TUNION,
 	BENUM		= 1L<<TENUM,
-	BFILE		= 1L<<TFILE,
 	BDOT		= 1L<<TDOT,
 	BCONSTNT	= 1L<<TCONSTNT,
 	BVOLATILE	= 1L<<TVOLATILE,
@@ -391,6 +391,7 @@
 	BTYPEDEF	= 1L<<TTYPEDEF,
 	BTYPESTR	= 1L<<TTYPESTR,
 	BREGISTER	= 1L<<TREGISTER,
+	BNORET		= 1L<<TNORET,
 
 	BINTEGER	= BCHAR|BUCHAR|BSHORT|BUSHORT|BINT|BUINT|
 				BLONG|BULONG|BVLONG|BUVLONG,
@@ -399,7 +400,7 @@
 /* these can be overloaded with complex types */
 
 	BCLASS		= BAUTO|BEXTERN|BSTATIC|BTYPEDEF|BTYPESTR|BREGISTER,
-	BGARB		= BCONSTNT|BVOLATILE,
+	BGARB		= BCONSTNT|BVOLATILE|BNORET
 };
 
 struct	Funct
--- a/sys/src/cmd/cc/cc.y
+++ b/sys/src/cmd/cc/cc.y
@@ -64,7 +64,7 @@
 %token	LIF LINT LLONG LREGISTER LRETURN LSHORT LSIZEOF LUSED
 %token	LSTATIC LSTRUCT LSWITCH LTYPEDEF LTYPESTR LUNION LUNSIGNED
 %token	LWHILE LVOID LENUM LSIGNED LCONSTNT LVOLATILE LSET LSIGNOF
-%token	LRESTRICT LINLINE
+%token	LRESTRICT LINLINE LNORET
 %%
 prog:
 |	prog xdecl
@@ -1149,6 +1149,7 @@
 	LCONSTNT { $$ = BCONSTNT; }
 |	LVOLATILE { $$ = BVOLATILE; }
 |	LRESTRICT { $$ = 0; }
+|	LNORET { $$ = BNORET; }
 
 name:
 	LNAME
--- a/sys/src/cmd/cc/dcl.c
+++ b/sys/src/cmd/cc/dcl.c
@@ -950,6 +950,8 @@
 		et = t1->etype;
 		if(et != t2->etype)
 			return 0;
+		if((t1->garb & GNORET) != (t2->garb & GNORET))
+			return 0;
 		if(et == TFUNC) {
 			if(!rsametype(t1->link, t2->link, n, 0))
 				return 0;
--- a/sys/src/cmd/cc/lex.c
+++ b/sys/src/cmd/cc/lex.c
@@ -1209,6 +1209,7 @@
 	"inline",	LINLINE,	0,
 	"int",		LINT,		TINT,
 	"long",		LLONG,		TLONG,
+	"NORET",	LNORET,		0,
 	"register",	LREGISTER,	0,
 	"restrict",	LRESTRICT,	0,
 	"return",	LRETURN,	0,
--- a/sys/src/cmd/cc/pgen.c
+++ b/sys/src/cmd/cc/pgen.c
@@ -165,6 +165,22 @@
 		cgen(n, Z);
 		break;
 
+	case OFUNC:
+		complex(n);
+		cgen(n, Z);
+		if((n->type->garb & GNORET) == 0)
+			break;
+
+		canreach = 0;
+		warnreach = !suppress;
+		/* existing assumption that branches are at least two jumps */
+		scc = pc;
+		gbranch(OGOTO);
+		patch(p, pc);
+		gbranch(OGOTO);
+		patch(p, scc);
+		break;
+
 	case OLIST:
 	case OCOMMA:
 		gen(n->left);
--- a/sys/src/cmd/cc/sub.c
+++ b/sys/src/cmd/cc/sub.c
@@ -168,6 +168,8 @@
 		return GVOLATILE;
 	case BVOLATILE|BCONSTNT:
 		return GCONSTNT|GVOLATILE;
+	case BNORET:
+		return GNORET;
 	}
 	return GXXX;
 }
@@ -1351,7 +1353,7 @@
 	TSTRUCT,	0x7c2da3bf,	0,
 	TUNION,		0x3eb25e98,	0,
 	TENUM,		0x44b54f61,	0,
-	TFILE,		0x19242ac3,	0,
+	TNORET,		0x19242ac3,	0,
 	TOLD,		0x22b15988,	0,
 	TDOT,		0x0204f6b3,	0,
 	-1,		0,		0,
@@ -1394,7 +1396,7 @@
 	TSTRUCT,	0,	"STRUCT",
 	TUNION,		0,	"UNION",
 	TENUM,		0,	"ENUM",
-	TFILE,		0,	"FILE",
+	TNORET,		0,	"NORET",
 	TOLD,		0,	"OLD",
 	TDOT,		0,	"DOT",
 	-1,		0,	0,
@@ -1407,6 +1409,7 @@
 	GCONSTNT,		0,	"CONST",
 	GVOLATILE,		0,	"VOLATILE",
 	GVOLATILE|GCONSTNT,	0,	"CONST-VOLATILE",
+	GNORET,			0,	"NORET",
 	-1,			0,	0,
 };
 
@@ -1445,7 +1448,7 @@
 	TUNSIGNED,	0,	"UNSIGNED",
 	TSIGNED,	0,	"SIGNED",
 	TDOT,		0,	"DOT",
-	TFILE,		0,	"FILE",
+	TNORET,		0,	"NORET",
 	TOLD,		0,	"OLD",
 	-1,		0,	0,
 };