wcc: reject final-band integer overflow; restore rewind columns

This commit is contained in:
2026-08-09 03:25:17 +09:00
parent cd11d6e573
commit 53a9e94736
5 changed files with 76 additions and 9 deletions

View File

@@ -80,6 +80,7 @@ static const struct row rows[] = {
{ "0xDE_AD_BE_EF", "INT(3735928559)" },
{ "0b1010", "INT(10)" },
{ "0o777", "INT(511)" },
{ "18446744073709551616", "ERR(18446744073709551616)" },
{ "3.14", "FLOAT(3.14)" },
{ "1.5e3", "FLOAT(1500)" },
@@ -149,6 +150,28 @@ runerr(const char *src)
return ok;
}
static int
runrewind(void)
{
const char *src = "1foo bar";
Arena *a = newarena();
Lex l;
lexinit(&l, a, "<test>", src, strlen(src));
Tok n = lexnext(&l);
Tok f = lexnext(&l);
Tok b = lexnext(&l);
int ok = n.kind == TK_INT && n.pos.col == 1 && n.v.uval == 1
&& f.kind == TK_IDENT && f.pos.col == 2
&& strcmp(f.text, "foo") == 0
&& b.kind == TK_IDENT && b.pos.col == 6
&& strcmp(b.text, "bar") == 0;
if (!ok)
fprintf(stderr, "suffix rewind columns: want 1,2,6 got %d,%d,%d\n",
n.pos.col, f.pos.col, b.pos.col);
freearena(a);
return ok;
}
static const char *const errrows[] = {
"'\\uZ'", /* unexpected rune scanning for escape */
"\"\\u00g0\"", /* non-hex digit inside a string escape */
@@ -169,6 +192,8 @@ main(void)
fail++;
}
}
if (!runrewind())
fail++;
for (size_t i = 0; i < sizeof errrows / sizeof errrows[0]; i++) {
if (!runerr(errrows[i])) {
fprintf(stderr, "errrow %zu failed\n", i);

View File

@@ -1,7 +1,7 @@
//ww:error "bad integer literal"
// 989_intoverflow_reject dec_overflow: a 21-digit decimal exceeds u64.
// Exact final-digit band: MAX/10 with 6 greater than MAX%10.
package main;
export fn main() i32 = {
let x: u64 = 99999999999999999999u64;
let x: u64 = 18446744073709551616u64;
return x: i32;
};