@@ -57,6 +57,7 @@ typedef struct {
5757 bool is_static ;
5858 bool is_extern ;
5959 bool is_inline ;
60+ bool is_tls ;
6061 int align ;
6162} VarAttr ;
6263
@@ -417,7 +418,7 @@ static Type *typespec(Token **rest, Token *tok, VarAttr *attr) {
417418 while (is_typename (tok )) {
418419 // Handle storage class specifiers.
419420 if (equal (tok , "typedef" ) || equal (tok , "static" ) || equal (tok , "extern" ) ||
420- equal (tok , "inline" )) {
421+ equal (tok , "inline" ) || equal ( tok , "_Thread_local" ) || equal ( tok , "__thread" ) ) {
421422 if (!attr )
422423 error_tok (tok , "storage class specifier is not allowed in this context" );
423424
@@ -427,11 +428,15 @@ static Type *typespec(Token **rest, Token *tok, VarAttr *attr) {
427428 attr -> is_static = true;
428429 else if (equal (tok , "extern" ))
429430 attr -> is_extern = true;
430- else
431+ else if ( equal ( tok , "inline" ))
431432 attr -> is_inline = true;
433+ else
434+ attr -> is_tls = true;
432435
433- if (attr -> is_typedef && attr -> is_static + attr -> is_extern + attr -> is_inline > 1 )
434- error_tok (tok , "typedef may not be used together with static, extern or inline" );
436+ if (attr -> is_typedef &&
437+ attr -> is_static + attr -> is_extern + attr -> is_inline + attr -> is_tls > 1 )
438+ error_tok (tok , "typedef may not be used together with static,"
439+ " extern, inline, __thread or _Thread_local" );
435440 tok = tok -> next ;
436441 continue ;
437442 }
@@ -1411,6 +1416,7 @@ static bool is_typename(Token *tok) {
14111416 "typedef" , "enum" , "static" , "extern" , "_Alignas" , "signed" , "unsigned" ,
14121417 "const" , "volatile" , "auto" , "register" , "restrict" , "__restrict" ,
14131418 "__restrict__" , "_Noreturn" , "float" , "double" , "typeof" , "inline" ,
1419+ "_Thread_local" , "__thread" ,
14141420 };
14151421
14161422 for (int i = 0 ; i < sizeof (kw ) / sizeof (* kw ); i ++ )
@@ -2941,6 +2947,7 @@ static Token *global_variable(Token *tok, Type *basety, VarAttr *attr) {
29412947 Obj * var = new_gvar (get_ident (ty -> name ), ty );
29422948 var -> is_definition = !attr -> is_extern ;
29432949 var -> is_static = attr -> is_static ;
2950+ var -> is_tls = attr -> is_tls ;
29442951 if (attr -> align )
29452952 var -> align = attr -> align ;
29462953
0 commit comments