diff options
author | Michael Forney <mforney@mforney.org> | 2021-10-27 10:52:25 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-12-06 13:51:48 -0800 |
commit | 8e39120d8ef8a5b8267771d2bc037dd1a95850f8 (patch) | |
tree | e9cfb0cf656889695d4e32a81c371a72605f93f0 | |
parent | 06d52f69408299eff611e57b39714b37abbb06a8 (diff) | |
download | cproc-8e39120d8ef8a5b8267771d2bc037dd1a95850f8.tar.xz |
decl: Enforce that _Alignas is at least as strict as required by type
-rw-r--r-- | decl.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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)) { |