On 8/1/25 4:56 AM, H.J. Lu wrote:
Set a tentative TLS model in grokvardecl and update DECL_TLS_MODEL with
the default TLS access model after a TLS variable has been fully processed
if the default TLS access model is stronger.
gcc/cp/
PR c++/107393
* decl.cc (grokvardecl): Add a pointer to bool argument to
indicate if DECL_TLS_MODEL should be updated later. Set a
tentative TLS model if DECL_TLS_MODEL will be updated later.
(start_decl): Pass a pointer to bool argument to grokdeclarator.
Call set_decl_tls_model to update DECL_TLS_MODEL with the default
TLS access model after calling grokdeclarator if the default TLS
access model is stronger.
(grokdeclarator): Add a pointer to bool argument and pass it to
grokvardecl.
* decl.h (grokdeclarator): Add a pointer to bool argument and
default it to nullptr.
* pt.cc (tsubst_decl): Call set_decl_tls_model after processing
a variable.
The tests pass with only the pt.cc changes, do you have an example that
motivates the other changes? I'd rather not add this sort of pass-back
parameter.
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index acfeb816592..e053f2453ab 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -15934,6 +15934,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain,
if (type == error_mark_node && !(complain & tf_error))
RETURN (error_mark_node);
r = copy_decl (t);
+ bool need_tls_model = false;
if (VAR_P (r))
{
DECL_INITIALIZED_P (r) = 0;
@@ -15994,7 +15995,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain,
}
if (CP_DECL_THREAD_LOCAL_P (r)
&& !processing_template_decl)
- set_decl_tls_model (r, decl_default_tls_model (r));
+ need_tls_model = true;
}
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
@@ -16057,6 +16058,9 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain,
register_local_specialization (r, t);
}
+ if (need_tls_model)
+ set_decl_tls_model (r, decl_default_tls_model (r));
I don't see the need for a new variable, we could move the existing
tests (plus VAR_P) down along with the set?
Jason