From 9382a3ad58536d84757fd15cf8105969fc4654ba Mon Sep 17 00:00:00 2001 From: Devin Hussey Date: Wed, 20 Mar 2019 15:03:27 -0400 Subject: [PATCH] C11 conformance: Add _Noreturn, stdnoreturn.h, and partial _Alignas support _Noreturn, just like __attribute__((noreturn)), is ignored. I also added stdnoreturn.h, in all its glorious uselessness. _Alignas only works for integer expressions right now. In order to comply, we need: - _Alignas(type) -> _Alignas(_Alignof(type)). - stdalign.h as soon as it is done. Note: DR 444 is supported; it works on struct members. Signed-off-by: Devin Hussey --- include/stdnoreturn.h | 7 +++++++ tccgen.c | 38 +++++++++++++++++++++++++++++++++++++- tcctok.h | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 include/stdnoreturn.h diff --git a/include/stdnoreturn.h b/include/stdnoreturn.h new file mode 100644 index 00000000..4d580ea5 --- /dev/null +++ b/include/stdnoreturn.h @@ -0,0 +1,7 @@ +#ifndef _STDNORETURN_H +#define _STDNORETURN_H + +/* ISOC11 noreturn */ +#define noreturn _Noreturn + +#endif /* _STDNORETURN_H */ diff --git a/tccgen.c b/tccgen.c index 8c6bdfa0..c6edcc3f 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4172,6 +4172,22 @@ static int parse_btype(CType *type, AttributeDef *ad) case TOK_INT: u = VT_INT; goto basic_type; + case TOK_ALIGNAS: + { int n; + next(); + /* TODO: _Alignas(type) -> _Alignas(_Alignof(type)) */ + if (tok == '(') { + next(); + n = expr_const(); + if (n <= 0 || (n & (n - 1)) != 0) + tcc_error("alignment must be a positive power of two"); + skip(')'); + } else { + expect("("); + } + ad->a.aligned = exact_log2p1(n); + } + continue; case TOK_LONG: if ((t & VT_BTYPE) == VT_DOUBLE) { t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE; @@ -4281,7 +4297,11 @@ static int parse_btype(CType *type, AttributeDef *ad) t |= VT_INLINE; next(); break; - + case TOK_NORETURN3: + /* currently, no need to handle it because tcc does not + track unused objects */ + next(); + break; /* GNUC attribute */ case TOK_ATTRIBUTE1: case TOK_ATTRIBUTE2: @@ -4569,6 +4589,22 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) case TOK_RESTRICT2: case TOK_RESTRICT3: goto redo; + case TOK_ALIGNAS: + { int n; + next(); + /* TODO: _Alignas(type) -> _Alignas(_Alignof(type)) */ + if (tok == '(') { + next(); + n = expr_const(); + if (n <= 0 || (n & (n - 1)) != 0) + tcc_error("alignment must be a positive power of two"); + skip(')'); + } else { + expect("("); + } + ad->a.aligned = exact_log2p1(n); + } + break; /* XXX: clarify attribute handling */ case TOK_ATTRIBUTE1: case TOK_ATTRIBUTE2: diff --git a/tcctok.h b/tcctok.h index 64c579c9..a3befd65 100644 --- a/tcctok.h +++ b/tcctok.h @@ -54,6 +54,7 @@ DEF(TOK_ALIGNOF1, "__alignof") DEF(TOK_ALIGNOF2, "__alignof__") DEF(TOK_ALIGNOF3, "_Alignof") + DEF(TOK_ALIGNAS, "_Alignas") DEF(TOK_TYPEOF1, "typeof") DEF(TOK_TYPEOF2, "__typeof") DEF(TOK_TYPEOF3, "__typeof__") @@ -138,6 +139,7 @@ DEF(TOK_NODECORATE, "nodecorate") DEF(TOK_NORETURN1, "noreturn") DEF(TOK_NORETURN2, "__noreturn__") + DEF(TOK_NORETURN3, "_Noreturn") DEF(TOK_VISIBILITY1, "visibility") DEF(TOK_VISIBILITY2, "__visibility__")