shithub: scc

Download patch

ref: 4f388adfd3574c516b7e7c6ef36324d483b0c2d6
parent: 0df4f021feb170f1dbd7ec5946234f6a6334b167
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jan 25 07:35:35 EST 2016

[cc1] Add ptrdiff_t type

This is the type used for the difference between pointers,
and it not always has the same size than int.

--- a/cc1/arch/amd64-sysv/arch.c
+++ b/cc1/arch/amd64-sysv/arch.c
@@ -211,7 +211,19 @@
 		.letter = L_ELLIPSIS,
 		.defined = 1,
 		.printed = 1
-	}
+	},
+	{      /* 19 = pdifftype */
+		.op = INT,
+		.letter = L_LONG,
+		.defined = 1,
+		.size = 8,
+		.integer = 1,
+		.arith = 1,
+		.align = 8,
+		.sign = 1,
+		.n.rank = RANK_LONG,
+		.printed = 1
+	},
 };
 
 Type *voidtype = &types[0], *pvoidtype = &types[1],
@@ -222,7 +234,8 @@
      *longtype = &types[10], *ulongtype = &types[11],
      *ullongtype = &types[12], *llongtype = &types[13],
      *floattype = &types[14], *doubletype = &types[15],
-     *ldoubletype = &types[16], *sizettype = &types[17],
+     *ldoubletype = &types[16],
+     *sizettype = &types[17], *pdifftype = &types[19],
      *ellipsistype = &types[18];
 
 static Symbol dummy0 = {.u.i = 0, .type = &types[9]},
--- a/cc1/arch/i386-sysv/arch.c
+++ b/cc1/arch/i386-sysv/arch.c
@@ -211,9 +211,22 @@
 		.letter = L_ELLIPSIS,
 		.defined = 1,
 		.printed = 1
-	}
+	},
+	{       /* 19 = pdifftype */
+		.op = INT,
+		.letter = L_INT,
+		.defined = 1,
+		.size = 4,
+		.integer = 1,
+		.arith = 1,
+		.align = 4,
+		.sign = 1,
+		.n.rank = RANK_INT,
+		.printed = 1
+	},
 };
 
+
 Type *voidtype = &types[0], *pvoidtype = &types[1],
      *booltype = &types[2], *schartype = &types[3],
      *uchartype = &types[4], *chartype = &types[5],
@@ -222,8 +235,10 @@
      *longtype = &types[10], *ulongtype = &types[11],
      *ullongtype = &types[12], *llongtype = &types[13],
      *floattype = &types[14], *doubletype = &types[15],
-     *ldoubletype = &types[16], *sizettype = &types[17],
+     *ldoubletype = &types[16],
+     *sizettype = &types[17], *pdifftype = &types[19],
      *ellipsistype = &types[18];
+
 
 static Symbol dummy0 = {.u.i = 0, .type = &types[9]},
               dummy1 = {.u.i = 1, .type = &types[9]};
--- a/cc1/arch/z80/arch.c
+++ b/cc1/arch/z80/arch.c
@@ -211,7 +211,19 @@
 		.letter = L_ELLIPSIS,
 		.defined = 1,
 		.printed = 1
-	}
+	},
+	{       /* 7 = pdifftype */
+		.op = INT,
+		.letter = L_SHORT,
+		.defined = 1,
+		.size = 2,
+		.integer = 1,
+		.arith = 1,
+		.align = 1,
+		.sign = 1,
+		.n.rank = RANK_SHORT,
+		.printed = 1
+	},
 };
 
 Type *voidtype = &types[0], *pvoidtype = &types[1],
@@ -222,7 +234,8 @@
      *longtype = &types[10], *ulongtype = &types[11],
      *ullongtype = &types[12], *llongtype = &types[13],
      *floattype = &types[14], *doubletype = &types[15],
-     *ldoubletype = &types[16], *sizettype = &types[17],
+     *ldoubletype = &types[16],
+     *sizettype = &types[17], *pdifftype = &types[19],
      *ellipsistype = &types[18];
 
 static Symbol dummy0 = {.u.i = 0, .type = &types[9]},
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -433,7 +433,8 @@
 
 extern Type *voidtype, *pvoidtype, *booltype,
             *uchartype,   *chartype, *schartype,
-            *uinttype,    *inttype,     *sizettype,
+            *uinttype,    *inttype,
+            *sizettype, *pdifftype,
             *ushortype,   *shortype,
             *longtype,    *ulongtype,
             *ullongtype,  *llongtype,
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -318,7 +318,7 @@
 	if (op == OSUB && BTYPE(rp) == PTR) {
 		if (tp != rp->type)
 			goto incorrect;
-		lp = node(OSUB, inttype, lp, rp);
+		lp = node(OSUB, pdifftype, lp, rp);
 		return node(ODIV, inttype, lp, size);
 	}
 	if (!rp->type->integer)