```9front - general discussion about 9front
help / color / mirror / Atom feed```
```From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] cc: fix conversion of constants to match c99.
Date: Thu, 05 May 2022 09:18:36 -0400	[thread overview]
Message-ID: <13CBD0AF060D51D940C5C190309C99E9@eigenstate.org> (raw)

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;

```

```next             reply	other threads:[~2022-05-05 13:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-05 13:18 ori [this message]
2022-05-05 18:20 ` Michael Forney
```

```Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,

Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

switches of git-send-email(1):

git send-email \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
--subject='Re: [9front] cc: fix conversion of constants to match c99.' \
```This is a public inbox, see mirroring instructions