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,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13CBD0AF060D51D940C5C190309C99E9@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).