Bug 19450 - __thread static class members
Summary: __thread static class members
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P3 normal
Target Milestone: 4.0.3
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
: 13668 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-01-14 19:14 UTC by Richard C. Bilson
Modified: 2005-11-09 23:42 UTC (History)
3 users (show)

See Also:
Host: i486-pc-linux-gnu
Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-11-08 13:07:56


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard C. Bilson 2005-01-14 19:14:37 UTC
gcc generates incorrect code for static members in some cases.  Consider the
following code:

struct C {
        static __thread int x;
        static __thread int y;
};

__thread int C::x;

void g() {
        int z = C::x;
        z = C::y;
}

When this is compiled on an x86 machine with gcc -S, the body of g() is
translated as:

        movl    %gs:_ZN1C1xE@NTPOFF, %eax
        movl    %eax, -4(%ebp)
        movl    _ZN1C1yE, %eax
        movl    %eax, -4(%ebp)

note that C::x is accessed using an offset from the thread pointer, which
is correct.  C::y, however, is accessed as if it were an ordinary (not
thread-local) static member, which is incorrect.  I have also observed
this problem on ia64 machines, so it seems to be a general issue.

These are similar to the symptoms described in bug 13668, although that was
determined to be a glibc issue.  I see no way in which glibc could be
involved here.

Environment:
System: Linux algol.uwaterloo.ca 2.6.8-1-k7 #1 Thu Nov 25 04:13:37 UTC 2004 i686 GNU/Linux
Architecture: i686

	
host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../gcc/configure -v --enable-languages=c,c++ --prefix=/u/rcbilson/software/gcc --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug i486-linux

How-To-Repeat:
        Compile the above code fragment using gcc -S.
Comment 1 Andrew Pinski 2005-01-14 19:31:21 UTC
It does not work with 20041211 but that is the last gcc which I have access to which has __thread 
support.
Comment 2 Andrew Pinski 2005-02-12 23:18:56 UTC
Confirmed.
Comment 3 Andrew Pinski 2005-11-08 13:02:13 UTC
*** Bug 13668 has been marked as a duplicate of this bug. ***
Comment 4 Simon Marshall 2005-11-08 17:41:46 UTC
Is there a target milestone for this?  IWBI it were fixed on 3.4 as well as 4.0.
(Appologies if I seem impertinent, I'm not too familiar with the way things work.)
Comment 5 Jakub Jelinek 2005-11-08 21:45:10 UTC
Subject: Bug 19450

Author: jakub
Date: Tue Nov  8 21:44:58 2005
New Revision: 106657

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106657
Log:
	PR c++/19450
	* decl.c (redeclaration_error_message): Issue diagnostics about
	olddecl and newdecl disagreement on __thread property.
	(grokdeclarator): Set DECL_TLS_MODEL on class static variables.

	* g++.dg/tls/diag-3.C: New test.
	* g++.dg/tls/diag-4.C: New test.
	* g++.dg/tls/static-1.C: New test.
	* g++.dg/tls/static-1a.cc: New file.

Added:
    trunk/gcc/testsuite/g++.dg/tls/diag-3.C
    trunk/gcc/testsuite/g++.dg/tls/diag-4.C
    trunk/gcc/testsuite/g++.dg/tls/static-1.C
    trunk/gcc/testsuite/g++.dg/tls/static-1a.cc
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Andrew Pinski 2005-11-08 22:13:44 UTC
Fixed.
Comment 7 Jakub Jelinek 2005-11-09 21:44:41 UTC
Subject: Bug 19450

Author: jakub
Date: Wed Nov  9 21:44:36 2005
New Revision: 106710

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106710
Log:
	PR c++/19450
	* decl.c (redeclaration_error_message): Issue diagnostics about
	olddecl and newdecl disagreement on __thread property.
	(grokdeclarator): Set DECL_THREAD_LOCAL on class static variables.

	* g++.dg/tls/diag-3.C: New test.
	* g++.dg/tls/diag-4.C: New test.
	* g++.dg/tls/static-1.C: New test.
	* g++.dg/tls/static-1a.cc: New file.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/tls/diag-3.C
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/tls/diag-4.C
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/tls/static-1.C
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/tls/static-1a.cc
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/decl.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 8 Andrew Pinski 2005-11-09 23:42:13 UTC
Fixed for 4.0.3 also.