aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc.h1
-rw-r--r--decl.c15
-rw-r--r--qbe.c4
3 files changed, 15 insertions, 5 deletions
diff --git a/cc.h b/cc.h
index d595eb8..b6effc7 100644
--- a/cc.h
+++ b/cc.h
@@ -278,6 +278,7 @@ struct decl {
struct {
/* alignment of object storage (may be stricter than type requires) */
int align;
+ enum storageduration storage;
} obj;
struct {
/* the function might have an "inline definition" (C11 6.7.4p7) */
diff --git a/decl.c b/decl.c
index 17b5e2e..eb5fc95 100644
--- a/decl.c
+++ b/decl.c
@@ -710,6 +710,7 @@ declarator(struct scope *s, struct qualtype base, char **name, struct scope **fu
static struct decl *
parameter(struct scope *s)
{
+ struct decl *d;
char *name;
struct qualtype t;
enum storageclass sc;
@@ -722,7 +723,9 @@ parameter(struct scope *s)
error(&tok.loc, "parameter declaration has invalid storage-class specifier");
t = declarator(s, t, &name, NULL, true);
t.type = typeadjust(t.type, &t.qual);
- return mkdecl(name, DECLOBJECT, t.type, t.qual, LINKNONE);
+ d = mkdecl(name, DECLOBJECT, t.type, t.qual, LINKNONE);
+ d->u.obj.storage = SDAUTO;
+ return d;
}
static void
@@ -1019,6 +1022,10 @@ decl(struct scope *s, struct func *f)
d = declcommon(s, kind, name, asmname, t, tq, sc, prior);
if (d->u.obj.align < align)
d->u.obj.align = align;
+ if (d->linkage == LINKNONE && !(sc & SCSTATIC))
+ d->u.obj.storage = SDAUTO;
+ else
+ d->u.obj.storage = sc & SCTHREADLOCAL ? SDTHREAD : SDSTATIC;
init = NULL;
hasinit = false;
if (consume(TASSIGN)) {
@@ -1036,10 +1043,10 @@ decl(struct scope *s, struct func *f)
}
break;
}
- if (d->linkage != LINKNONE || sc & SCSTATIC)
- emitdata(d, init);
- else
+ if (d->u.obj.storage == SDAUTO)
funcinit(f, d, init, hasinit);
+ else
+ emitdata(d, init);
d->defined = true;
break;
case DECLFUNC:
diff --git a/qbe.c b/qbe.c
index a5817f9..83fe1ed 100644
--- a/qbe.c
+++ b/qbe.c
@@ -503,6 +503,7 @@ mkfunc(struct decl *decl, char *name, struct type *t, struct scope *s)
t = mkarraytype(&typechar, QUALCONST, strlen(name) + 1);
d = mkdecl("__func__", DECLOBJECT, t, QUALNONE, LINKNONE);
+ d->u.obj.storage = SDSTATIC;
d->value = mkglobal(d->name, true, false);
scopeputdecl(s, d);
f->namedecl = d;
@@ -637,6 +638,7 @@ funclval(struct func *f, struct expr *e)
break;
case EXPRCOMPOUND:
d = mkdecl(NULL, DECLOBJECT, e->type, e->qual, LINKNONE);
+ d->u.obj.storage = SDAUTO;
funcinit(f, d, e->u.compound.init, true);
lval.addr = d->value;
break;
@@ -1328,7 +1330,7 @@ emitdata(struct decl *d, struct init *init)
align = d->u.obj.align;
for (cur = init; cur; cur = cur->next)
cur->expr = eval(cur->expr);
- if (d->value->threadlocal)
+ if (d->u.obj.storage == SDTHREAD)
fputs("thread ", stdout);
if (d->linkage == LINKEXTERN)
fputs("export ", stdout);