diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/torture/tls')
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/tls/thr-init-1.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/tls/thr-init-2.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/tls/tls-test.c | 52 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/tls/tls.exp | 36 |
4 files changed, 143 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/tls/thr-init-1.c b/gcc/testsuite/gcc.dg/torture/tls/thr-init-1.c new file mode 100644 index 000000000..ff3338ffb --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/tls/thr-init-1.c @@ -0,0 +1,26 @@ +/* { dg-do run } */ +/* { dg-require-effective-target tls_runtime } */ +/* { dg-add-options tls } */ + +extern int printf (char *,...); +extern void abort() ; + +int test_code(int b) +{ +static __thread int fstat = 1; + fstat += b ; + return fstat; +} + +int main (int ac, char *av[]) +{ + int a = test_code(1); + + if ( a != 2 ) + { + printf ("a=%d\n", a) ; + abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/tls/thr-init-2.c b/gcc/testsuite/gcc.dg/torture/tls/thr-init-2.c new file mode 100644 index 000000000..44156232c --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/tls/thr-init-2.c @@ -0,0 +1,29 @@ +/* { dg-do run } */ +/* { dg-require-effective-target tls_runtime } */ +/* { dg-add-options tls } */ + +extern int printf (char *,...); +extern void abort() ; + +static __thread int fstat ; +static __thread int fstat = 1; +static __thread int fstat ; + +int test_code(int b) +{ + fstat += b ; + return fstat; +} + +int main (int ac, char *av[]) +{ + int a = test_code(1); + + if ( a != 2 || fstat != 2 ) + { + printf ("a=%d fstat=%d\n", a, fstat) ; + abort (); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/tls/tls-test.c b/gcc/testsuite/gcc.dg/torture/tls/tls-test.c new file mode 100644 index 000000000..8a23e77c1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/tls/tls-test.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ +/* { dg-require-effective-target tls } */ +/* { dg-require-effective-target pthread } */ +/* { dg-options "-pthread" } */ + +#include <pthread.h> +extern int printf (char *,...); +__thread int a = 5; +int *volatile a_in_other_thread = (int *) 12345; + +static void * +thread_func (void *arg) +{ + a_in_other_thread = &a; + a+=5; + *((int *) arg) = a; + return (void *)0; +} + +int +main () +{ + pthread_t thread; + void *thread_retval; + int *volatile a_in_main_thread; + int *volatile again ; + int thr_a; + + a_in_main_thread = &a; + + if (pthread_create (&thread, (pthread_attr_t *)0, thread_func, &thr_a)) + return 0; + + if (pthread_join (thread, &thread_retval)) + return 0; + + again = &a; + if (again != a_in_main_thread) + { + printf ("FAIL: main thread addy changed from 0x%0x to 0x%0x\n", + a_in_other_thread, again); + return 1; + } + + if (a != 5 || thr_a != 10 || (a_in_other_thread == a_in_main_thread)) + { + printf ("FAIL: a= %d, thr_a = %d Addr = 0x%0x\n", + a, thr_a, a_in_other_thread); + return 1; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/tls/tls.exp b/gcc/testsuite/gcc.dg/torture/tls/tls.exp new file mode 100644 index 000000000..91c8843c4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/tls/tls.exp @@ -0,0 +1,36 @@ +# Copyright (C) 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# GCC testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib gcc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -ansi -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \ + $DEFAULT_CFLAGS + +# All done. +dg-finish |