scc

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

commit b4d92e02bc635472f47ca877add11b4581392238
parent 65d6ca357dd5101c7ef095b30ad021ba1339c96f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Apr 2014 13:12:42 +0200

Check if variable is register type before taken address

It is forbidden to take the address of a variable defined as
register.

Diffstat:
Mexpr.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/expr.c b/expr.c @@ -369,7 +369,7 @@ unary(void) { register Node *np; Type *tp; - char paren, op; + char paren, op, *err; uint8_t t; switch (yytoken) { @@ -410,8 +410,9 @@ unary(void) switch (op) { case OADDR: if (!np->b.lvalue) - goto bad_operand; - /* TODO: check if variable is register */ + goto no_lvalue; + if (np->code == emitsym && np->u.sym->s.isregister) + goto reg_address; tp = mktype(tp, PTR, NULL, 0); break; case OEXC: @@ -438,8 +439,16 @@ unary(void) return unarycode(op, tp, np); +no_lvalue: + err = "lvalue required in unary expression"; + goto error; +reg_address: + err = "address of register variable '%s' requested"; + goto error; bad_operand: - error("bad operand in unary expression"); + err = "bad operand in unary expression"; +error: + error(err, yytext); } static Node *