aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-10-27 10:52:25 -0700
committerMichael Forney <mforney@mforney.org>2021-12-06 13:51:48 -0800
commit8e39120d8ef8a5b8267771d2bc037dd1a95850f8 (patch)
treee9cfb0cf656889695d4e32a81c371a72605f93f0
parent06d52f69408299eff611e57b39714b37abbb06a8 (diff)
downloadcproc-8e39120d8ef8a5b8267771d2bc037dd1a95850f8.tar.xz
decl: Enforce that _Alignas is at least as strict as required by type
-rw-r--r--decl.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/decl.c b/decl.c
index 268ee01..d31196f 100644
--- a/decl.c
+++ b/decl.c
@@ -697,8 +697,11 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, un
if (width == -1) {
m->bits.before = 0;
m->bits.after = 0;
- if (align < mt.type->align)
+ if (align < mt.type->align) {
+ if (align)
+ error(&tok.loc, "specified alignment of struct member '%s' is less strict than is required by type", name);
align = mt.type->align;
+ }
t->size = ALIGNUP(t->size, align);
if (t->kind == TYPESTRUCT) {
m->offset = t->size;
@@ -946,6 +949,8 @@ decl(struct scope *s, struct func *f)
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);
if (d->align < align)
d->align = align;
if (consume(TASSIGN)) {