aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-04-05 15:59:12 -0700
committerMichael Forney <mforney@mforney.org>2019-04-06 12:01:38 -0700
commitabec185dead30d4034721619befc847f4c05621c (patch)
treefc54dfcba11890da5fa33d94f02643fb41b30b00
parent70cbf1e90934b1902769d53a4a43c0e6aa200dfd (diff)
Separate unqualified type and qualifiers in struct member
-rw-r--r--cc.h1
-rw-r--r--decl.c3
-rw-r--r--expr.c2
-rw-r--r--qbe.c4
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)