shithub: scc

Download patch

ref: 6fe9948519b756f46cb42fa132b158541f024222
parent: 6b79855c62dc196ceb55fc0e585f6feb27db2fda
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 6 15:07:10 EST 2016

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.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -35,13 +35,11 @@
 
 struct limits {
 	union {
-		TINT i;
-		TUINT u;
+		TUINT i;
 		TFLOAT f;
 	} max;
 	union {
-		TINT i;
-		TUINT u;
+		TUINT i;
 		TFLOAT f;
 	} min;
 };
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -21,7 +21,7 @@
 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 @@
 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 @@
 {
 	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;
 	}
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -266,7 +266,7 @@
 	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 @@
 		}
 		sym->type = tp;
 		lim = getlimits(tp);
-		max = (tp->sign) ? lim->max.u : lim->max.i;
+		max = lim->max.i;
 		goto repeat;
 	}
 
--- 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
 		}
 	},
 	{