From 966e1f7b5ae375380f2e4c2a52fdea82ca3c01dd Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 15 Apr 2019 21:57:48 -0700 Subject: expr: Check operand to '&' operator --- expr.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/expr.c b/expr.c index 4a746bc..f9f1703 100644 --- a/expr.c +++ b/expr.c @@ -81,6 +81,14 @@ mkunaryexpr(enum tokenkind op, struct expr *base) base->decayed = false; return base; } + /* + Allow struct and union types even if they are not lvalues, + since we take their address when compiling member access. + */ + if (!base->lvalue && base->type->kind != TYPEFUNC && base->type->kind != TYPESTRUCT && base->type->kind != TYPEUNION) + error(&tok.loc, "'&' operand is not an lvalue or function designator"); + if (base->kind == EXPRBITFIELD) + error(&tok.loc, "cannot take address of bit-field"); expr = mkexpr(EXPRUNARY, mkpointertype(base->type, base->qual)); expr->unary.op = op; expr->unary.base = base; -- cgit v1.2.3