aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cc.h2
-rw-r--r--decl.c16
-rw-r--r--qbe.c7
3 files changed, 10 insertions, 15 deletions
diff --git a/cc.h b/cc.h
index 0d29dde..263b209 100644
--- a/cc.h
+++ b/cc.h
@@ -268,6 +268,7 @@ struct decl {
struct type *type;
enum typequal qual;
struct value *value;
+ char *asmname;
_Bool defined;
/* link in list of tentative object definitions */
@@ -523,7 +524,6 @@ void switchcase(struct switchcases *, unsigned long long, struct block *);
struct block *mkblock(char *);
struct value *mkglobal(char *, _Bool);
-char *globalname(struct value *);
struct value *mkintconst(unsigned long long);
unsigned long long intconstvalue(struct value *);
diff --git a/decl.c b/decl.c
index 98d7b72..809cf25 100644
--- a/decl.c
+++ b/decl.c
@@ -833,7 +833,6 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
struct decl *d;
enum linkage linkage;
const char *kindstr = kind == DECLFUNC ? "function" : "object";
- char *priorname;
if (prior) {
if (prior->linkage == LINKNONE)
@@ -843,7 +842,7 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
error(&tok.loc, "%s '%s' redeclared with different linkage", kindstr, name);
if (!typecompatible(t, prior->type) || tq != prior->qual)
error(&tok.loc, "%s '%s' redeclared with incompatible type", kindstr, name);
- if (asmname && strcmp(globalname(prior->value), asmname) != 0)
+ if (asmname && (!prior->asmname || strcmp(prior->asmname, asmname) != 0))
error(&tok.loc, "%s '%s' redeclared with different assembler name", kindstr, name);
prior->type = typecomposite(t, prior->type);
return prior;
@@ -862,18 +861,21 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
error(&tok.loc, "%s '%s' redeclared with different linkage", kindstr, name);
if (!typecompatible(t, prior->type) || tq != prior->qual)
error(&tok.loc, "%s '%s' redeclared with incompatible type", kindstr, name);
- priorname = globalname(prior->value);
if (!asmname)
- asmname = priorname;
- else if (strcmp(priorname, asmname) != 0)
+ asmname = prior->asmname;
+ else if (!prior->asmname || strcmp(prior->asmname, asmname) != 0)
error(&tok.loc, "%s '%s' redeclared with different assembler name", kindstr, name);
t = typecomposite(t, prior->type);
}
}
d = mkdecl(kind, t, tq, linkage);
scopeputdecl(s, name, d);
- if (kind == DECLFUNC || linkage != LINKNONE || sc & SCSTATIC)
- d->value = mkglobal(asmname ? asmname : name, linkage == LINKNONE && !asmname);
+ if (kind == DECLFUNC || linkage != LINKNONE || sc & SCSTATIC) {
+ if (asmname)
+ name = asmname;
+ d->value = mkglobal(name, linkage == LINKNONE && !asmname);
+ d->asmname = asmname;
+ }
return d;
}
diff --git a/qbe.c b/qbe.c
index d24d963..3bcd0ae 100644
--- a/qbe.c
+++ b/qbe.c
@@ -140,13 +140,6 @@ mkglobal(char *name, bool private)
return v;
}
-char *
-globalname(struct value *v)
-{
- assert(v->kind == VALUE_GLOBAL && !v->id);
- return v->u.name;
-}
-
struct value *
mkintconst(unsigned long long n)
{