[hackers] [scc] [cc1] Add ptrdiff_t type || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Mon, 25 Jan 2016 12:46:06 +0100 (CET)

commit 4f388adfd3574c516b7e7c6ef36324d483b0c2d6
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Mon Jan 25 12:35:35 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Mon Jan 25 12:35:35 2016 +0100

    [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.

diff --git a/cc1/arch/amd64-sysv/arch.c b/cc1/arch/amd64-sysv/arch.c
index 7eb8dc8..9fbd32d 100644
--- a/cc1/arch/amd64-sysv/arch.c
+++ b/cc1/arch/amd64-sysv/arch.c
_AT_@ -211,7 +211,19 @@ static Type types[] = {
                 .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],
_AT_@ -222,7 +234,8 @@ Type *voidtype = &types[0], *pvoidtype = &types[1],
      *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]},
diff --git a/cc1/arch/i386-sysv/arch.c b/cc1/arch/i386-sysv/arch.c
index 237ba41..792686b 100644
--- a/cc1/arch/i386-sysv/arch.c
+++ b/cc1/arch/i386-sysv/arch.c
_AT_@ -211,9 +211,22 @@ static Type types[] = {
                 .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],
_AT_@ -222,9 +235,11 @@ Type *voidtype = &types[0], *pvoidtype = &types[1],
      *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]};
 Symbol *zero = &dummy0, *one = &dummy1;
diff --git a/cc1/arch/z80/arch.c b/cc1/arch/z80/arch.c
index 7a0f601..996dce7 100644
--- a/cc1/arch/z80/arch.c
+++ b/cc1/arch/z80/arch.c
_AT_@ -211,7 +211,19 @@ static Type types[] = {
                 .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],
_AT_@ -222,7 +234,8 @@ Type *voidtype = &types[0], *pvoidtype = &types[1],
      *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]},
diff --git a/cc1/cc1.h b/cc1/cc1.h
index 5f3fcc7..a5dd178 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -433,7 +433,8 @@ extern Symbol *curfun, *zero, *one;
 
 extern Type *voidtype, *pvoidtype, *booltype,
             *uchartype, *chartype, *schartype,
- *uinttype, *inttype, *sizettype,
+ *uinttype, *inttype,
+ *sizettype, *pdifftype,
             *ushortype, *shortype,
             *longtype, *ulongtype,
             *ullongtype, *llongtype,
diff --git a/cc1/expr.c b/cc1/expr.c
index 79d7e35..a50ada8 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -318,7 +318,7 @@ parithmetic(char op, Node *lp, Node *rp)
         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)
Received on Mon Jan 25 2016 - 12:46:06 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 25 2016 - 12:48:28 CET