From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25527 invoked from network); 5 May 2022 13:20:37 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 5 May 2022 13:20:37 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 9front; Thu May 5 09:18:50 -0400 2022 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 85056f91 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Thu, 5 May 2022 06:18:38 -0700 (PDT) Message-ID: <13CBD0AF060D51D940C5C190309C99E9@eigenstate.org> To: 9front@9front.org Date: Thu, 05 May 2022 09:18:36 -0400 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: map/reduce reduce/map framework Subject: [9front] cc: fix conversion of constants to match c99. Reply-To: 9front@9front.org Precedence: bulk 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< 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;