On Tue, Aug 12, 2025 at 6:11 PM H.J. Lu <hjl.to...@gmail.com> wrote:
>
> On Tue, Aug 12, 2025 at 4:19 PM Jason Merrill <ja...@redhat.com> wrote:
> >
> > 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
>
> There are 3 tests submitted with the C frontend patch:
>
> https://patchwork.sourceware.org/project/gcc/patch/20250801115455.1024683-1-hjl.to...@gmail.com/
>
> These tests are common to both C and C++.   One of them looks like:
>
> [hjl@gnu-cfl-3 testsuite]$ cat c-c++-common/tls-attr-le-pic.c
> /* { dg-do compile } */
> /* { dg-require-effective-target fpic } */
> /* { dg-require-effective-target tls } */
> /* { dg-options "-O2 -fpic -fdump-ipa-whole-program" } */
>
> __attribute__ ((tls_model ("local-exec"))) __thread int i;
>
> int *
> foo (void)
> {
>   return &i;
> }
>
> /* tls_model should be local-exec due to tls_model attribute.  */
> /* { dg-final { scan-ipa-dump "Varpool flags: tls-local-exec"
> "whole-program" } } */
> [hjl@gnu-cfl-3 testsuite]$
>
> > motivates the other changes?  I'd rather not add this sort of pass-back
> > parameter.

I submitted a test patch for both C and C++:

https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692509.html

The C front end needs a similar fix.

> > > 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?
>
> I will check it out.

I changed it to

+  if (VAR_P (r)
+      && CP_DECL_THREAD_LOCAL_P (r)
+      && !processing_template_decl)
+    set_decl_tls_model (r, decl_default_tls_model (r));

in v2 patch:

https://gcc.gnu.org/pipermail/gcc-patches/2025-August/692510.html

> Thanks.
>
> > Jason
> >
>
>
> --
> H.J.



-- 
H.J.

Reply via email to