commit 6fe9948519b756f46cb42fa132b158541f024222 Author: Roberto E. Vargas Caballero <k...@shike2.com> AuthorDate: Wed Jan 6 20:07:10 2016 +0100 Commit: Roberto E. Vargas Caballero <k...@shike2.com> CommitDate: Wed Jan 6 20:07:10 2016 +0100
Remove TINT field in limits struct Having this field was a problem because it made impossible to take a value of the union without checking the type which generates this limits. This complexity is not needed, because TUINT can cover the maximum of any integer type, and in the case of the min, we only have to negate the value. diff --git a/cc1/cc1.h b/cc1/cc1.h index e4ce5dd..b680121 100644 --- a/cc1/cc1.h +++ b/cc1/cc1.h @@ -35,13 +35,11 @@ typedef struct input Input; struct limits { union { - TINT i; - TUINT u; + TUINT i; TFLOAT f; } max; union { - TINT i; - TUINT u; + TUINT i; TFLOAT f; } min; }; diff --git a/cc1/fold.c b/cc1/fold.c index 7d14a5c..66824c4 100644 --- a/cc1/fold.c +++ b/cc1/fold.c @@ -21,7 +21,7 @@ static bool addi(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - TINT max = lim->max.i, min = lim->min.i; + TINT max = lim->max.i, min = -lim->min.i; if (l < 0 && r < 0 && l >= min - r || l == 0 || @@ -69,7 +69,7 @@ static bool muli(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - TINT max = lim->max.i, min = lim->min.i; + TINT max = lim->max.i, min = -lim->min.i; if (l > -1 && l <= 1 || r > -1 && r <= 1 || @@ -106,7 +106,7 @@ divi(TINT l, TINT r, Type *tp) { struct limits *lim = getlimits(tp); - if (r == 0 || l == lim->min.i && r == -1) { + if (r == 0 || l == -lim->min.i && r == -1) { warn("overflow in constant expression"); return 0; } diff --git a/cc1/lex.c b/cc1/lex.c index 96a71c8..1155cfd 100644 --- a/cc1/lex.c +++ b/cc1/lex.c @@ -266,7 +266,7 @@ readint(char *s, int base, int sign, Symbol *sym) int c; lim = getlimits(tp); - max = (tp->sign) ? lim->max.u : lim->max.i; + max = lim->max.i; if (*s == '0') ++s; if (toupper(*s) == 'X') @@ -295,7 +295,7 @@ readint(char *s, int base, int sign, Symbol *sym) } sym->type = tp; lim = getlimits(tp); - max = (tp->sign) ? lim->max.u : lim->max.i; + max = lim->max.i; goto repeat; } diff --git a/cc1/types.c b/cc1/types.c index 5840218..74fb338 100644 --- a/cc1/types.c +++ b/cc1/types.c @@ -19,20 +19,20 @@ static struct limits limits[][4] = { { { /* 0 = unsigned 1 byte */ - .min.u = 0, - .max.u = 255 + .min.i = 0, + .max.i = 255 }, { /* 1 = unsigned 2 bytes */ - .min.u = 0, - .max.u = 65535u + .min.i = 0, + .max.i = 65535u }, { /* 2 = unsigned 4 bytes */ - .min.u = 0, - .max.u = 4294967295u + .min.i = 0, + .max.i = 4294967295u }, { /* 3 = unsigned 8 bytes */ - .min.u = 0, - .max.u = 18446744073709551615u + .min.i = 0, + .max.i = 18446744073709551615u } }, {