mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-27 06:10:06 +08:00
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 <husseydevin@gmail.com>
This commit is contained in:
parent
1fd3709379
commit
9382a3ad58
7
include/stdnoreturn.h
Normal file
7
include/stdnoreturn.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef _STDNORETURN_H
|
||||||
|
#define _STDNORETURN_H
|
||||||
|
|
||||||
|
/* ISOC11 noreturn */
|
||||||
|
#define noreturn _Noreturn
|
||||||
|
|
||||||
|
#endif /* _STDNORETURN_H */
|
38
tccgen.c
38
tccgen.c
@ -4172,6 +4172,22 @@ static int parse_btype(CType *type, AttributeDef *ad)
|
|||||||
case TOK_INT:
|
case TOK_INT:
|
||||||
u = VT_INT;
|
u = VT_INT;
|
||||||
goto basic_type;
|
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:
|
case TOK_LONG:
|
||||||
if ((t & VT_BTYPE) == VT_DOUBLE) {
|
if ((t & VT_BTYPE) == VT_DOUBLE) {
|
||||||
t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE;
|
t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE;
|
||||||
@ -4281,7 +4297,11 @@ static int parse_btype(CType *type, AttributeDef *ad)
|
|||||||
t |= VT_INLINE;
|
t |= VT_INLINE;
|
||||||
next();
|
next();
|
||||||
break;
|
break;
|
||||||
|
case TOK_NORETURN3:
|
||||||
|
/* currently, no need to handle it because tcc does not
|
||||||
|
track unused objects */
|
||||||
|
next();
|
||||||
|
break;
|
||||||
/* GNUC attribute */
|
/* GNUC attribute */
|
||||||
case TOK_ATTRIBUTE1:
|
case TOK_ATTRIBUTE1:
|
||||||
case TOK_ATTRIBUTE2:
|
case TOK_ATTRIBUTE2:
|
||||||
@ -4569,6 +4589,22 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
|
|||||||
case TOK_RESTRICT2:
|
case TOK_RESTRICT2:
|
||||||
case TOK_RESTRICT3:
|
case TOK_RESTRICT3:
|
||||||
goto redo;
|
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 */
|
/* XXX: clarify attribute handling */
|
||||||
case TOK_ATTRIBUTE1:
|
case TOK_ATTRIBUTE1:
|
||||||
case TOK_ATTRIBUTE2:
|
case TOK_ATTRIBUTE2:
|
||||||
|
2
tcctok.h
2
tcctok.h
@ -54,6 +54,7 @@
|
|||||||
DEF(TOK_ALIGNOF1, "__alignof")
|
DEF(TOK_ALIGNOF1, "__alignof")
|
||||||
DEF(TOK_ALIGNOF2, "__alignof__")
|
DEF(TOK_ALIGNOF2, "__alignof__")
|
||||||
DEF(TOK_ALIGNOF3, "_Alignof")
|
DEF(TOK_ALIGNOF3, "_Alignof")
|
||||||
|
DEF(TOK_ALIGNAS, "_Alignas")
|
||||||
DEF(TOK_TYPEOF1, "typeof")
|
DEF(TOK_TYPEOF1, "typeof")
|
||||||
DEF(TOK_TYPEOF2, "__typeof")
|
DEF(TOK_TYPEOF2, "__typeof")
|
||||||
DEF(TOK_TYPEOF3, "__typeof__")
|
DEF(TOK_TYPEOF3, "__typeof__")
|
||||||
@ -138,6 +139,7 @@
|
|||||||
DEF(TOK_NODECORATE, "nodecorate")
|
DEF(TOK_NODECORATE, "nodecorate")
|
||||||
DEF(TOK_NORETURN1, "noreturn")
|
DEF(TOK_NORETURN1, "noreturn")
|
||||||
DEF(TOK_NORETURN2, "__noreturn__")
|
DEF(TOK_NORETURN2, "__noreturn__")
|
||||||
|
DEF(TOK_NORETURN3, "_Noreturn")
|
||||||
DEF(TOK_VISIBILITY1, "visibility")
|
DEF(TOK_VISIBILITY1, "visibility")
|
||||||
DEF(TOK_VISIBILITY2, "__visibility__")
|
DEF(TOK_VISIBILITY2, "__visibility__")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user