scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 6f68ced69160ec08b765f6e121d698d569881a07
parent 48f3f5ac1c6fde47cbefefc1fcf125515a71a0e2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  7 Apr 2014 21:03:24 +0200

Check against incomplete type operations

Operations about incomplete types (or pointers
to incomplete types) are not defined, so this check
must be done.

Diffstat:
expr.c | 5++++-
types.c | 34++++++++++++++++++++++++----------
2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/expr.c b/expr.c @@ -89,9 +89,10 @@ int_float: break; case PTR: case ARY: pointer: + if (!tp1->defined) + goto nocomplete; if (op != OADD && op != OSUB) goto incorrect; - /* TODO: check that the the base type is a complete type */ tp3 = tp1->type; if (t1 == ARY) tp1 = mktype(tp1->type, PTR, NULL, 0); @@ -107,6 +108,8 @@ pointer: return bincode(op, tp1, np1, np2); +nocomplete: + error("invalid use of indefined type"); incorrect: error("incorrect arithmetic operands"); } diff --git a/types.c b/types.c @@ -16,63 +16,77 @@ Type }, *booltype = &(Type) { .op = INT, - .letter = 'B' + .letter = 'B', + .defined = 1 }, *uchartype = &(Type) { .op = INT, .letter = 'M', - .sign = 1 + .sign = 1, + .defined = 1 }, *chartype = &(Type) { .op = INT, .letter = 'C', + .defined = 1 }, *uinttype = &(Type) { .op = INT, .letter = 'U', - .sign = 1 + .sign = 1, + .defined = 1 }, *inttype = &(Type) { .op = INT, .letter = 'I', + .defined = 1 }, *ushortype = &(Type) { .op = INT, - .letter = 'E' + .letter = 'E', + .defined = 1 }, *shortype = &(Type) { .op = INT, .letter = 'K', + .defined = 1 }, *longtype = &(Type) { .op = INT, - .letter = 'L' + .letter = 'L', + .defined = 1 }, *ulongtype = &(Type) { .op = INT, .letter = 'Z', - .sign = 1 + .sign = 1, + .defined = 1 }, *ullongtype = &(Type) { .op = INT, .letter = 'O', - .sign = 1 + .sign = 1, + .defined = 1 }, *llongtype = &(Type) { .op = INT, .letter = 'G', + .defined = 1 }, *floattype = &(Type) { .op = FLOAT, - .letter = 'F' + .letter = 'F', + .defined = 1 }, *doubletype = &(Type) { .op = FLOAT, - .letter = 'D' + .letter = 'D', + .defined = 1 }, *ldoubletype = &(Type) { .op = FLOAT, - .letter = 'H' + .letter = 'H', + .defined = 1 }; Type *