On Mon, Sep 8, 2025 at 3:10 PM H.J. Lu <hjl.to...@gmail.com> wrote:
>
> Both C and C++ frontends should 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.
>
>         PR c/107419
>         PR c++/107393
>         * c-c++-common/tls-attr-common.c: New test.
>         * c-c++-common/tls-attr-le-pic.c: Likewise.
>         * c-c++-common/tls-attr-le-pie.c: Likewise.
>
> Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
> ---
>  gcc/testsuite/c-c++-common/tls-attr-common.c | 20 ++++++++++++++++++++
>  gcc/testsuite/c-c++-common/tls-attr-le-pic.c | 15 +++++++++++++++
>  gcc/testsuite/c-c++-common/tls-attr-le-pie.c | 15 +++++++++++++++
>  3 files changed, 50 insertions(+)
>  create mode 100644 gcc/testsuite/c-c++-common/tls-attr-common.c
>  create mode 100644 gcc/testsuite/c-c++-common/tls-attr-le-pic.c
>  create mode 100644 gcc/testsuite/c-c++-common/tls-attr-le-pie.c
>
> diff --git a/gcc/testsuite/c-c++-common/tls-attr-common.c 
> b/gcc/testsuite/c-c++-common/tls-attr-common.c
> new file mode 100644
> index 00000000000..55153bbbb8f
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/tls-attr-common.c
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target pie } */
> +/* { dg-require-effective-target tls } */
> +/* { dg-options "-O2 -fdump-ipa-whole-program" } */
> +/* Add -fPIE or -mno-direct-extern-access to disable direct access to
> +   external symbol from executable.  */
> +/* { dg-additional-options "-fPIE" { target { ! { i?86-*-* x86_64-*-* } } } 
> } */
> +/* { dg-additional-options "-mno-direct-extern-access" { target { i?86-*-* 
> x86_64-*-* } } } */
> +
> +__attribute__((common))
> +__thread int i;
> +
> +int *
> +foo (void)
> +{
> +  return &i;
> +}
> +
> +/* tls_model should be tls-initial-exec due to common attribute.  */
> +/* { dg-final { scan-ipa-dump "Varpool flags: tls-initial-exec" 
> "whole-program" } } */
> diff --git a/gcc/testsuite/c-c++-common/tls-attr-le-pic.c 
> b/gcc/testsuite/c-c++-common/tls-attr-le-pic.c
> new file mode 100644
> index 00000000000..c02df6919f1
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/tls-attr-le-pic.c
> @@ -0,0 +1,15 @@
> +/* { 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" } } */
> diff --git a/gcc/testsuite/c-c++-common/tls-attr-le-pie.c 
> b/gcc/testsuite/c-c++-common/tls-attr-le-pie.c
> new file mode 100644
> index 00000000000..b8ef7840d79
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/tls-attr-le-pie.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile { target { tls && pie } } } */
> +/* { dg-options "-O2 -fPIE -fdump-ipa-whole-program" } */
> +
> +extern const int afoo[3];
> +
> +__thread const int *pfoo __attribute__ ((tls_model ("initial-exec"))) = afoo;
> +
> +const int **
> +ppfoo (void)
> +{
> +  return &pfoo;
> +}
> +
> +/* tls_model should be local-exec due to -fPIE.  */
> +/* { dg-final { scan-ipa-dump "Varpool flags: initialized tls-local-exec" 
> "whole-program" } } */
> --
> 2.51.0
>

I am checking in this patch.

-- 
H.J.

Reply via email to