scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 9b65a9cadd670f9cdd7ac4d8e203240fbfcd80cf
parent 58a6c79cc36af196485e291e0d5599f351653a21
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 20 Jul 2015 08:19:25 +0200

Use uintptr_t for arithmetic on pointers

Conversion between pointers and integers are allowed,
but the result is implementation defined, except in
the case of uinptr_t which is big enough to hold
the value of the pointer without losing any information
and allow return to the pointer type.

Diffstat:
Mcc1/types.c | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/cc1/types.c b/cc1/types.c @@ -210,9 +210,12 @@ mktype(Type *tp, unsigned op, short nelem, void *data) unsigned t; Type *bp; static char letters[] = { - [PTR] = L_POINTER, [ARY] = L_ARRAY, - [FTN] = L_FUNCTION, [ENUM] = L_INT, - [STRUCT] = L_STRUCT, [UNION] = L_UNION + [PTR] = L_POINTER, + [ARY] = L_ARRAY, + [FTN] = L_FUNCTION, + [ENUM] = L_INT, + [STRUCT] = L_STRUCT, + [UNION] = L_UNION }; if (op == PTR && tp == voidtype) @@ -230,7 +233,7 @@ mktype(Type *tp, unsigned op, short nelem, void *data) else type.defined = 1; - t = (op ^ (char) ((unsigned short) tp >> 3)) & NR_TYPE_HASH-1; + t = (op ^ (uintptr_t) tp >> 3) & NR_TYPE_HASH-1; tbl = &typetab[t]; for (bp = *tbl; bp; bp = bp->next) { if (eqtype(bp, &type)) {