diff options
| author | Michael Forney <mforney@mforney.org> | 2022-11-26 23:45:38 -0800 | 
|---|---|---|
| committer | Michael Forney <mforney@mforney.org> | 2022-11-26 23:47:52 -0800 | 
| commit | 8a3ed28569f14bfde94cd7a75fa89c356caf459c (patch) | |
| tree | 5781d8a0200c872443768e54740248599931e715 | |
| parent | 3809a018648d2e5597af5eb941e1d003e7ed01cd (diff) | |
| download | cproc-8a3ed28569f14bfde94cd7a75fa89c356caf459c.tar.xz | |
Check object alignment in only one place
| -rw-r--r-- | decl.c | 6 | ||||
| -rw-r--r-- | qbe.c | 10 | 
2 files changed, 5 insertions, 11 deletions
| @@ -69,6 +69,8 @@ mkdecl(enum declkind k, struct type *t, enum typequal tq, enum linkage linkage)  	d->linkage = linkage;  	d->type = t;  	d->qual = tq; +	if (k == DECLOBJECT) +		d->u.obj.align = t->align;  	return d;  } @@ -944,9 +946,9 @@ decl(struct scope *s, struct func *f)  				error(&tok.loc, "typedef '%s' redefined with different type", name);  			break;  		case DECLOBJECT: -			d = declcommon(s, kind, name, asmname, t, tq, sc, prior);  			if (align && align < t->align) -				error(&tok.loc, "specified alignment of object '%s' is less strict than is required by type", name); +				error(&tok.loc, "object '%s' requires alignment %d, which is stricter than specified alignment %d", name, t->align, align); +			d = declcommon(s, kind, name, asmname, t, tq, sc, prior);  			if (d->u.obj.align < align)  				d->u.obj.align = align;  			init = NULL; @@ -260,12 +260,8 @@ funcalloc(struct func *f, struct decl *d)  	assert(!d->type->incomplete);  	assert(d->type->size > 0); -	align = d->u.obj.align; -	if (!align) -		align = d->type->align; -	else if (align < d->type->align) -		error(&tok.loc, "object requires alignment %d, which is stricter than %d", d->type->align, align);  	size = d->type->size; +	align = d->u.obj.align;  	switch (align) {  	case 1:  	case 2: @@ -1326,10 +1322,6 @@ emitdata(struct decl *d, struct init *init)  	int align;  	align = d->u.obj.align; -	if (!align) -		align = d->type->align; -	else if (align < d->type->align) -		error(&tok.loc, "object requires alignment %d, which is stricter than %d", d->type->align, align);  	for (cur = init; cur; cur = cur->next)  		cur->expr = eval(cur->expr, EVALINIT);  	if (d->linkage == LINKEXTERN) | 
