This is the mail archive of the gcc-bugs@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]

[Bug c++/19450] New: __thread static class members


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.

-- 
           Summary: __thread static class members
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rcbilson at plg dot uwaterloo dot ca
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19450


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