From 8e39120d8ef8a5b8267771d2bc037dd1a95850f8 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 27 Oct 2021 10:52:25 -0700 Subject: decl: Enforce that _Alignas is at least as strict as required by type --- decl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)) { -- cgit v1.2.3