This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

tls: error out on incompatible TLS decls


This patch adds errors for declarations such as:

     extern __thread int I;
     int I;

     extern int j;
     __thread int j;

Jakub, Richard said you're supposed to do something with this.
(include it in some rpm?)

Bootstrapped on powerpc-linux.

Ok?

2002-08-06  Aldy Hernandez  <aldyh@redhat.com>

	* c-decl.c (duplicate_decls): Error out for incompatible TLS
	declarations.

	* testsuite/gcc.dg/tls/diag-3.c: New.


Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.344
diff -c -p -r1.344 c-decl.c
*** c-decl.c	1 Aug 2002 06:20:30 -0000	1.344
--- c-decl.c	7 Aug 2002 01:01:55 -0000
*************** duplicate_decls (newdecl, olddecl, diffe
*** 1400,1405 ****
--- 1400,1419 ----
  	}
        error_with_decl (olddecl, "previous declaration of `%s'");
      }
+   /* TLS cannot follow non-TLS declaration.  */
+   else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
+ 	   && !DECL_THREAD_LOCAL (olddecl) && DECL_THREAD_LOCAL (newdecl))
+     {
+       error_with_decl (newdecl, "thread-local declaration of `%s' follows non thread-local declaration");
+       error_with_decl (olddecl, "previous declaration of `%s'");
+     }
+   /* non-TLS declaration cannot follow TLS declaration.  */
+   else if (TREE_CODE (olddecl) == VAR_DECL && TREE_CODE (newdecl) == VAR_DECL
+ 	   && DECL_THREAD_LOCAL (olddecl) && !DECL_THREAD_LOCAL (newdecl))
+     {
+       error_with_decl (newdecl, "non thread-local declaration of `%s' follows thread-local declaration");
+       error_with_decl (olddecl, "previous declaration of `%s'");
+     }
    else
      {
        errmsg = redeclaration_error_message (newdecl, olddecl);
Index: testsuite/gcc.dg/tls/diag-3.c
===================================================================
RCS file: testsuite/gcc.dg/tls/diag-3.c
diff -N testsuite/gcc.dg/tls/diag-3.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/tls/diag-3.c	7 Aug 2002 01:01:55 -0000
***************
*** 0 ****
--- 1,10 ----
+ /* Report invalid extern and __thread combinations.  */
+ 
+ extern int j;		/* { dg-error "previous declaration" } */
+ __thread int j;		/* { dg-error "thread-local declaration for" } */
+ 
+ extern __thread int i;	/* { dg-error "previous declaration" } */
+ int i;			/* { dg-error "non thread-local" } */
+ 
+ extern __thread int k;	/* This is fine.  */
+ __thread int k;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]