From: H.J. Lu Date: Fri, 5 Sep 2025 22:40:51 +0000 (-0700) Subject: c: Update TLS model after processing a TLS variable X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cad8f94b450be9b73d07bdeef7fa1778d3f2b96;p=thirdparty%2Fgcc.git c: Update TLS model after processing a TLS variable Set a tentative TLS model in grokvardecl and update TLS mode with the default TLS access model after a TLS variable has been fully processed if the default TLS access model is stronger. gcc/c/ PR c/107419 * c-decl.cc (c_decl_attributes): Update TLS model with the default TLS access model if the default TLS access model is stronger. (grokdeclarator): Set a tentative TLS model which will be updated by c_decl_attributes later. Signed-off-by: H.J. Lu --- diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 589abf4e4e2..62a0545947e 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5582,7 +5582,16 @@ c_decl_attributes (tree *node, tree attributes, int flags) tree last_decl = lookup_last_decl (*node); if (last_decl == error_mark_node) last_decl = NULL_TREE; - return decl_attributes (node, attributes, flags, last_decl); + tree attr = decl_attributes (node, attributes, flags, last_decl); + if (VAR_P (*node) && DECL_THREAD_LOCAL_P (*node)) + { + // tls_model attribute can set a stronger TLS access model. + tls_model model = DECL_TLS_MODEL (*node); + tls_model default_model = decl_default_tls_model (*node); + if (default_model > model) + set_decl_tls_model (*node, default_model); + } + return attr; } @@ -8181,8 +8190,11 @@ grokdeclarator (const struct c_declarator *declarator, TREE_PUBLIC (decl) = extern_ref; } + // NB: Set a tentative TLS model to avoid tls_model attribute + // warnings due to lack of thread storage duration. It will + // be updated by c_decl_attributes later. if (threadp) - set_decl_tls_model (decl, decl_default_tls_model (decl)); + set_decl_tls_model (decl, TLS_MODEL_REAL); } if ((storage_class == csc_extern