scc

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

commit 89db1825e0012c166dc6443493c3ebeac21d49e6
parent caa62432d65dbf35039908832765b7098f48a224
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 26 Aug 2015 11:28:09 +0200

Fix types of integer operands in pointer additions

The code was adding things of different type, and it was doing
casts that were not necessary. This new version does the multiplication
in size_t type, and convert the result to pointer.

Diffstat:
Mcc1/expr.c | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -457,9 +457,11 @@ parithmetic(char op, Node *lp, Node *rp) } if (BTYPE(rp) != INT) goto incorrect; - rp = node(OCAST, tp, promote(rp), NULL); - rp = node(OMUL, tp, rp, size); - return node(op, tp, lp, rp); + rp = convert(promote(rp), sizettype, 0); + rp = node(OMUL, sizettype, rp, size); + rp = node(OCAST, tp, rp, NULL); + + return node(OADD, tp, lp, rp); incorrect: error("incorrect arithmetic operands");