summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@pingthings.io>2020-09-20 15:59:06 -0400
committerOri Bernstein <ori@pingthings.io>2020-09-20 15:59:06 -0400
commit285be77897e18d68efede25a98f423bddd4f2cb9 (patch)
treeed3eecbafa64733bddacf330cc4c65e0497cf970
parent433357fe9fd4e99c70c780a0204244f5fd618cf2 (diff)
downloadmc-master.tar.gz
Fix range checking for numbers.HEADmaster
-rw-r--r--lib/std/test/fmt.myr4
-rw-r--r--parse/infer.c20
-rw-r--r--parse/tok.c5
3 files changed, 17 insertions, 12 deletions
diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr
index 0d0385d..1522534 100644
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -139,9 +139,9 @@ const variablewidth = {c
check(c, "77", "{w=?}", 77, (-1 : int8))
check(c, "77", "{w=?}", 77, (-1 : int16))
check(c, "77", "{w=?}", 77, (-1 : int32))
- check(c, "77", "{w=?}", 77, (-4294967294 : int32))
+ check(c, "77", "{w=?}", 77, (-4294967294L : int32))
check(c, "77", "{w=?}", 77, (-1 : int64))
- check(c, "77", "{w=?}", 77, (-18446744073709551614 : int64))
+ check(c, "77", "{w=?}", 77, (-18446744073709551614L : int64))
check(c, "77", "{w=?}", 77, (0 : int8))
check(c, "77", "{w=?}", 77, (0 : int16))
check(c, "77", "{w=?}", 77, (0 : int32))
diff --git a/parse/infer.c b/parse/infer.c
index ba5509d..79e45cf 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2570,22 +2570,22 @@ checkrange(Node *n)
int64_t sval;
uint64_t uval;
static const int64_t svranges[][2] = {
- /* signed ints */
- [Tyint8] = {-128LL, 127LL},
- [Tyint16] = {-32768LL, 32767LL},
- [Tyint32] = {-2147483648LL, 2147483647LL},
- [Tyint] = {-2147483648LL, 2147483647LL},
- [Tyint64] = {-9223372036854775808ULL, 9223372036854775807LL},
+ /* signed ints; allow one above max range for unary -'ve operator */
+ [Tyint8] = {-128LL, 128LL},
+ [Tyint16] = {-32768LL, 32768LL},
+ [Tyint32] = {-2147483648LL, 2147483648LL},
+ [Tyint] = {-2147483648LL, 2147483648LL},
+ [Tyint64] = {-9223372036854775808ULL, 9223372036854775807ULL},
};
static const uint64_t uvranges[][2] = {
- [Tybyte] = {0, 255ULL},
- [Tyuint8] = {0, 255ULL},
+ [Tybyte] = {0, 255ULL},
+ [Tyuint8] = {0, 255ULL},
[Tyuint16] = {0, 65535ULL},
- [Tyuint] = {0, 4294967295ULL},
+ [Tyuint] = {0, 4294967295ULL},
[Tyuint32] = {0, 4294967295ULL},
[Tyuint64] = {0, 18446744073709551615ULL},
- [Tychar] = {0, 4294967295ULL},
+ [Tychar] = {0, 4294967295ULL},
};
/* signed types */
diff --git a/parse/tok.c b/parse/tok.c
index f4505d5..8b40dc2 100644
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -732,12 +732,14 @@ nextsuffix
:
switch (peek()) {
case 'u':
+ case 'U':
if (unsignedval == 1)
lfatal(curloc, "Duplicate 'u' integer specifier");
next();
unsignedval = 1;
goto nextsuffix;
case 'l':
+ case 'L':
next();
if (unsignedval)
t->inttype = Tyuint64;
@@ -745,6 +747,7 @@ nextsuffix
t->inttype = Tyint64;
break;
case 'i':
+ case 'I':
next();
if (unsignedval)
t->inttype = Tyuint32;
@@ -752,6 +755,7 @@ nextsuffix
t->inttype = Tyint32;
break;
case 's':
+ case 'S':
next();
if (unsignedval)
t->inttype = Tyuint16;
@@ -759,6 +763,7 @@ nextsuffix
t->inttype = Tyint16;
break;
case 'b':
+ case 'B':
next();
if (unsignedval)
t->inttype = Tyuint8;