aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/zc0.c22
-rw-r--r--tests/conformance/known.txt11
2 files changed, 20 insertions, 13 deletions
diff --git a/src/tools/zc0.c b/src/tools/zc0.c
index 51ea9f8..782d548 100644
--- a/src/tools/zc0.c
+++ b/src/tools/zc0.c
@@ -145,6 +145,24 @@ static void docblock(void)
while (dn && (dbuf[dn - 1] == ' ' || dbuf[dn - 1] == '\t' || dbuf[dn - 1] == '\r' || dbuf[dn - 1] == '\n')) dn--;
dbuf[dn++] = '\n'; dlast = line; docpending = 1;
}
+/* an integer literal at pos, as the compiler reads it: decimal digits (a leading 0 is
+ not octal: 010 is 10), or 0x and hex digits (0x alone is 0). the value wraps modulo
+ 2^64 instead of saturating. the token text is the literal's source. */
+static void intlit(int base)
+{
+ int p = pos, d; uint64_t u = 0;
+ if (base == 16) pos += 2;
+ for (;;) {
+ int c = (unsigned char)src[pos];
+ if (c >= '0' && c <= '9') d = c - '0';
+ else if (base == 16 && c >= 'a' && c <= 'f') d = c - 'a' + 10;
+ else if (base == 16 && c >= 'A' && c <= 'F') d = c - 'A' + 10;
+ else break;
+ u = u * (uint64_t)base + (uint64_t)d; pos++;
+ }
+ tsroom((size_t)(pos - p) + 1); memcpy(ts, src + p, (size_t)(pos - p)); ts[pos - p] = 0;
+ tv = (int64_t)u; tk = T_NUM;
+}
static void next(void)
{
int ws = 0, i;
@@ -165,7 +183,7 @@ static void next(void)
if (isdigit((unsigned char)src[pos]) || (src[pos] == '.' && isdigit((unsigned char)src[pos + 1]))) {
int p = pos, fl = 0;
if (src[pos] == '0' && (src[pos + 1] == 'x' || src[pos + 1] == 'X')) {
- char *e; tv = (int64_t)strtoll(src + pos, &e, 0); memcpy(ts, src + pos, e - src - pos); ts[e - src - pos] = 0; pos = e - src; tk = T_NUM; return;
+ intlit(16); return;
}
if (src[p] == '.') {
int nch = (unsigned char)src[p + 1];
@@ -198,7 +216,7 @@ static void next(void)
}
b[n] = 0; memcpy(ts, b, (size_t)n + 1); tv = (int64_t)fop_parse(b); tk = T_FLT; return;
}
- { char *e; tv = (int64_t)strtoll(src + pos, &e, 0); memcpy(ts, src + pos, e - src - pos); ts[e - src - pos] = 0; pos = e - src; tk = T_NUM; return; }
+ intlit(10); return;
}
if (isalpha((unsigned char)src[pos]) || src[pos] == '_') {
i = 0; while (isalnum((unsigned char)src[pos]) || src[pos] == '_') { tsroom((size_t)i + 2); ts[i++] = src[pos++]; }
diff --git a/tests/conformance/known.txt b/tests/conformance/known.txt
index 13ef43c..9bec99b 100644
--- a/tests/conformance/known.txt
+++ b/tests/conformance/known.txt
@@ -17,13 +17,6 @@
9-appendix-b/b2_15_duplicate_case.zc zy c appendix b.2.15 confirmed; 4.7.2 says duplicates are allowed
9-appendix-b/b2_16_local_const_in_const_expr.zc zy c appendix b.2.16 confirmed; 3.14.2 documents it
1-source/ident_tags_as_variables_glued_star.zc zc0 b u*d with visible u and d is read as a recast (no code); zy follows 1.6.3
-1-source/lit_hex.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_hex_wide.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_hex_wraps.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_int_max.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_int_wraps.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_int_zero_and_leading_zeros.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_minus_folded.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
2-types/conv_argument_and_return.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
2-types/conv_assignment_to_float.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
2-types/conv_f32_rounds.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
@@ -50,7 +43,3 @@
3-expressions/prec_as_binds_tight.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
4-statements/return_value_converted_float.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
4-statements/return_value_converted_int.zc zc0 b types are read and dropped: no conversion, no sized cut (appendix a)
-9-appendix-b/b1_11_zc0_octal.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-9-appendix-b/b1_11_zc0_saturation.zc zc0 b literals read with strtoll base 0: octal and saturation (appendix b.1.11)
-1-source/lit_hex_no_digits_is_zero.zc zc0 b 0x with no digits is rejected (strtoll)
-1-source/lit_int_octal_is_decimal.zc zc0 b 08 is rejected (strtoll base 0 octal)