History

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.

Devin Hussey committed 7 years ago

Commit 9382a3a1 parent 1fd37093 files · +46 −1Browse files

Unified · Split

3 files
  1. include/stdnoreturn.h +7 −0
  2. tccgen.c +37 −1
  3. tcctok.h +2 −0
include/stdnoreturn.h+7−0
@@ -0,0 +1,7 @@
1+#ifndef _STDNORETURN_H
2+#define _STDNORETURN_H
3+
4+/* ISOC11 noreturn */
5+#define noreturn _Noreturn
6+
7+#endif /* _STDNORETURN_H */
tccgen.c+37−1
@@ -4172,6 +4172,22 @@ static int parse_btype(CType *type, AttributeDef *ad) · 4171 unmodified lines
41724172 case TOK_INT:
41734173 u = VT_INT;
41744174 goto basic_type;
4175+ case TOK_ALIGNAS:
4176+ { int n;
4177+ next();
4178+ /* TODO: _Alignas(type) -> _Alignas(_Alignof(type)) */
4179+ if (tok == '(') {
4180+ next();
4181+ n = expr_const();
4182+ if (n <= 0 || (n & (n - 1)) != 0)
4183+ tcc_error("alignment must be a positive power of two");
4184+ skip(')');
4185+ } else {
4186+ expect("(");
4187+ }
4188+ ad->a.aligned = exact_log2p1(n);
4189+ }
4190+ continue;
41754191 case TOK_LONG:
41764192 if ((t & VT_BTYPE) == VT_DOUBLE) {
41774193 t = (t & ~(VT_BTYPE|VT_LONG)) | VT_LDOUBLE;
@@ -4281,7 +4297,11 @@ static int parse_btype(CType *type, AttributeDef *ad) · 103 unmodified lines
42814297 t |= VT_INLINE;
42824298 next();
42834299 break;
4284−
4300+ case TOK_NORETURN3:
4301+ /* currently, no need to handle it because tcc does not
4302+ track unused objects */
4303+ next();
4304+ break;
42854305 /* GNUC attribute */
42864306 case TOK_ATTRIBUTE1:
42874307 case TOK_ATTRIBUTE2:
@@ -4569,6 +4589,22 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) · 281 unmodified lines
45694589 case TOK_RESTRICT2:
45704590 case TOK_RESTRICT3:
45714591 goto redo;
4592+ case TOK_ALIGNAS:
4593+ { int n;
4594+ next();
4595+ /* TODO: _Alignas(type) -> _Alignas(_Alignof(type)) */
4596+ if (tok == '(') {
4597+ next();
4598+ n = expr_const();
4599+ if (n <= 0 || (n & (n - 1)) != 0)
4600+ tcc_error("alignment must be a positive power of two");
4601+ skip(')');
4602+ } else {
4603+ expect("(");
4604+ }
4605+ ad->a.aligned = exact_log2p1(n);
4606+ }
4607+ break;
45724608 /* XXX: clarify attribute handling */
45734609 case TOK_ATTRIBUTE1:
45744610 case TOK_ATTRIBUTE2:
tcctok.h+2−0
@@ -54,6 +54,7 @@ · 53 unmodified lines
5454 DEF(TOK_ALIGNOF1, "__alignof")
5555 DEF(TOK_ALIGNOF2, "__alignof__")
5656 DEF(TOK_ALIGNOF3, "_Alignof")
57+ DEF(TOK_ALIGNAS, "_Alignas")
5758 DEF(TOK_TYPEOF1, "typeof")
5859 DEF(TOK_TYPEOF2, "__typeof")
5960 DEF(TOK_TYPEOF3, "__typeof__")
@@ -138,6 +139,7 @@ · 78 unmodified lines
138139 DEF(TOK_NODECORATE, "nodecorate")
139140 DEF(TOK_NORETURN1, "noreturn")
140141 DEF(TOK_NORETURN2, "__noreturn__")
142+ DEF(TOK_NORETURN3, "_Noreturn")
141143 DEF(TOK_VISIBILITY1, "visibility")
142144 DEF(TOK_VISIBILITY2, "__visibility__")
143145

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t