aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-04-05 14:36:45 -0700
committerMichael Forney <mforney@mforney.org>2019-04-06 12:01:38 -0700
commit70cbf1e90934b1902769d53a4a43c0e6aa200dfd (patch)
tree5800971aca75e788b068f8afd570f7ea5cb9b9cb
parent7e5a07cfff793e5656d9868cae9cc5281f92e0d0 (diff)
Separate unqualified type and qualifiers in struct param
-rw-r--r--cc.h1
-rw-r--r--decl.c6
-rw-r--r--qbe.c4
-rw-r--r--type.c3
4 files changed, 9 insertions, 5 deletions
diff --git a/cc.h b/cc.h
index 85b50b5..0619332 100644
--- a/cc.h
+++ b/cc.h
@@ -159,6 +159,7 @@ enum typeprop {
struct param {
char *name;
struct type *type;
+ enum typequal qual;
struct value *value;
struct param *next;
};
diff --git a/decl.c b/decl.c
index 99834e6..987d6fa 100644
--- a/decl.c
+++ b/decl.c
@@ -490,7 +490,7 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs
break;
}
}
- if (typeunqual(t->func.params->type, NULL)->kind == TYPEVOID && !t->func.params->next)
+ if (t->func.params->type->kind == TYPEVOID && !t->func.params->next)
t->func.params = NULL;
break;
case TRPAREN:
@@ -600,7 +600,7 @@ parameter(struct scope *s)
if (sc && sc != SCREGISTER)
error(&tok.loc, "parameter declaration has invalid storage-class specifier");
p = mkparam(NULL, t);
- p->type = adjust(declarator(s, p->type, &p->name, true));
+ p->type = typeunqual(adjust(declarator(s, p->type, &p->name, true)), &p->qual);
return p;
}
@@ -619,7 +619,7 @@ paramdecl(struct scope *s, struct param *params)
t = adjust(declarator(s, base, &name, false));
for (p = params; p; p = p->next) {
if (strcmp(name, p->name) == 0) {
- p->type = t;
+ p->type = typeunqual(t, &p->qual);
break;
}
}
diff --git a/qbe.c b/qbe.c
index 4f6b7a1..f387ca9 100644
--- a/qbe.c
+++ b/qbe.c
@@ -364,7 +364,7 @@ mkfunc(char *name, struct type *t, struct scope *s)
if (!t->func.isprototype && !typecompatible(p->type, typeargpromote(p->type)))
error(&tok.loc, "old-style function definition with parameter type incompatible with promoted type is not yet supported");
emittype(p->type);
- d = mkdecl(DECLOBJECT, p->type, LINKNONE);
+ d = mkdecl(DECLOBJECT, mkqualifiedtype(p->type, p->qual), LINKNONE);
p->value = xmalloc(sizeof(*p->value));
functemp(f, p->value, p->type->repr);
if (p->type->repr->abi.id) {
@@ -373,7 +373,7 @@ mkfunc(char *name, struct type *t, struct scope *s)
d->value->repr = &iptr;
} else {
funcinit(f, d, NULL);
- funcstore(f, typeunqual(p->type, NULL), QUALNONE, d->value, p->value);
+ funcstore(f, p->type, QUALNONE, d->value, p->value);
}
scopeputdecl(s, p->name, d);
}
diff --git a/type.c b/type.c
index 89136ec..ed65f63 100644
--- a/type.c
+++ b/type.c
@@ -206,6 +206,8 @@ typecompatible(struct type *t1, struct type *t2)
return true;
}
for (p1 = t1->func.params, p2 = t2->func.params; p1 && p2; p1 = p1->next, p2 = p2->next) {
+ if (p1->qual != p2->qual)
+ return false;
tmp = t2->func.isprototype ? p2->type : typeargpromote(p2->type);
if (!typecompatible(p1->type, tmp))
return false;
@@ -326,6 +328,7 @@ mkparam(char *name, struct type *t)
p = xmalloc(sizeof(*p));
p->name = name;
p->type = t;
+ p->qual = QUALNONE;
p->next = NULL;
return p;