scc

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

commit dfe85dcaa8a0216b88815c0cf67ef247c51dc18c
parent cc438f5538915a874dd03bf8b24f2556862db280
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  9 Aug 2016 14:06:39 +0200

[cc1] Do not allow operations with pointers to incomplete types

The only operations allowed with pointers to incomplete types
is the assignation and the comparition, so we have to catch
all the rest and give a good error message.

Diffstat:
Mcc1/expr.c | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -316,7 +316,12 @@ parithmetic(char op, Node *lp, Node *rp) if (lp->type->op != PTR) XCHG(lp, rp, np); + tp = rp->type; + if (tp->op == PTR && !(tp->type->prop & TDEFINED)) + goto incomplete; tp = lp->type; + if (!(tp->type->prop & TDEFINED)) + goto incomplete; size = sizeofnode(tp->type); if (op == OSUB && BTYPE(rp) == PTR) { @@ -334,9 +339,13 @@ parithmetic(char op, Node *lp, Node *rp) return simplify(OADD, tp, lp, rp); +incomplete: + errorp("invalid use of undefined type"); + return lp; incorrect: errorp("incorrect arithmetic operands"); - return node(OADD, tp, lp, rp); + return lp; + } static Node * @@ -542,6 +551,10 @@ incdec(Node *np, char op) if (!(tp->prop & TDEFINED)) { errorp("invalid use of undefined type"); return np; + } else if (tp->op == PTR && !(tp->type->prop & TDEFINED)) { + errorp("%s of pointer to an incomplete type", + (op == OINC) ? "increment" : "decrement"); + return np; } else if (tp->prop & TARITH) { inc = constnode(one); } else if (tp->op == PTR) {