From abec185dead30d4034721619befc847f4c05621c Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 5 Apr 2019 15:59:12 -0700 Subject: Separate unqualified type and qualifiers in struct member --- cc.h | 1 + decl.c | 3 ++- expr.c | 2 +- qbe.c | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cc.h b/cc.h index 0619332..cae963d 100644 --- a/cc.h +++ b/cc.h @@ -172,6 +172,7 @@ struct bitfield { struct member { char *name; struct type *type; + enum typequal qual; uint64_t offset; struct bitfield bits; struct member *next; diff --git a/decl.c b/decl.c index 987d6fa..665752b 100644 --- a/decl.c +++ b/decl.c @@ -643,7 +643,8 @@ addmember(struct structbuilder *b, struct type *mt, char *name, int align, uint6 assert(mt->align > 0); if (name || width == -1) { m = xmalloc(sizeof(*m)); - m->type = mt; + m->qual = QUALNONE; + m->type = typeunqual(mt, &m->qual); m->name = name; m->next = NULL; *b->last = m; diff --git a/expr.c b/expr.c index c973666..755fdef 100644 --- a/expr.c +++ b/expr.c @@ -562,7 +562,7 @@ postfixexpr(struct scope *s, struct expr *r) if (m->bits.before || m->bits.after) error(&tok.loc, "bit-field access is not yet supported"); r = mkbinaryexpr(&tok.loc, TADD, r, mkconstexpr(&typeulong, offset)); - r = exprconvert(r, mkpointertype(mkqualifiedtype(m->type, tq))); + r = exprconvert(r, mkpointertype(mkqualifiedtype(m->type, tq | m->qual))); e = mkunaryexpr(TMUL, r); e->lvalue = lvalue; next(); diff --git a/qbe.c b/qbe.c index f387ca9..1fa637d 100644 --- a/qbe.c +++ b/qbe.c @@ -1007,7 +1007,7 @@ emittype(struct type *t) for (m = t->structunion.members; m; m = m->next) { for (sub = m->type; sub->kind == TYPEARRAY; sub = sub->base) ; - emittype(typeunqual(sub, NULL)); + emittype(sub); } fputs("type :", stdout); emitname(&t->repr->abi); @@ -1017,7 +1017,7 @@ emittype(struct type *t) fputs("{ ", stdout); for (i = 1, sub = m->type; sub->kind == TYPEARRAY; sub = sub->base) i *= sub->array.length; - emitrepr(typeunqual(sub, NULL)->repr, true, true); + emitrepr(sub->repr, true, true); if (i > 1) printf(" %" PRIu64, i); if (t->kind == TYPEUNION) -- cgit v1.2.3