9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] cc: fix conversion of constants to match c99.
@ 2022-05-05 13:18 ori
  2022-05-05 18:20 ` Michael Forney
  0 siblings, 1 reply; 2+ messages in thread
From: ori @ 2022-05-05 13:18 UTC (permalink / raw)
  To: 9front

Earlier, I'd done a half-assed job of this, this patch corrects
it and makes the code less ugly. (thanks to adr on 9fans)

ok to commit?

diff 641bd4512ff02b1b86157263ab604bc790f0c89d uncommitted
--- a/sys/src/cmd/cc/lex.c
+++ b/sys/src/cmd/cc/lex.c
@@ -444,7 +444,7 @@
 yylex(void)
 {
 	vlong vv;
-	long c, c1, t, w;
+	long c, c1, t;
 	char *cp;
 	Rune rune;
 	Sym *s;
@@ -848,17 +848,11 @@
 		yyerror("overflow in constant");
 
 	vv = yylval.vval;
-	/*
-	 * c99 is silly: decimal constants stay signed,
-	 * hex and octal go unsigned before widening.
-	 */
-	w = 32;
-	if((c1 & (Numdec|Numuns)) == Numdec)
-		w = 31;
-	if(c1 & Numvlong || (c1 & Numlong) == 0 && (uvlong)vv >= 1ULL<<w){
-		if((c1&(Numdec|Numvlong)) == Numdec && vv < 1ULL<<32)
-			warn(Z, "int constant widened to vlong: %s", symb);
-		if((c1 & Numuns) || convvtox(vv, TVLONG) < 0) {
+	if(c1 & Numvlong ||
+	  convvtox(vv, TUVLONG) > convvtox(vv, TULONG) ||
+	  (c1 & (Numdec|Numuns)) == Numdec && convvtox(vv, TLONG) < 0) {
+   		if((c1 & (Numdec|Numuns)) == 0 &&
+		  ((c1 & Numuns) || convvtox(vv, TVLONG) < 0)) {
 			c = LUVLCONST;
 			t = TUVLONG;
 			goto nret;
@@ -867,8 +861,11 @@
 		t = TVLONG;
 		goto nret;
 	}
-	if(c1 & Numlong) {
-		if((c1 & Numuns) || convvtox(vv, TLONG) < 0) {
+	if(c1 & Numlong ||
+	  convvtox(vv, TULONG) > convvtox(vv, TUINT) ||
+	  (c1 & (Numdec|Numuns)) == Numdec && convvtox(vv, TINT) < 0) {
+		if((c1 & (Numdec|Numuns)) == 0 && 
+		  ((c1 & Numuns) || convvtox(vv, TLONG) < 0)) {
 			c = LULCONST;
 			t = TULONG;
 			goto nret;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-05 18:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 13:18 [9front] cc: fix conversion of constants to match c99 ori
2022-05-05 18:20 ` Michael Forney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).