public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->'
@ 2014-03-26 16:47 michael at ensslin dot cc
  2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: michael at ensslin dot cc @ 2014-03-26 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60673
           Summary: c++11 static thread_local members may cause a segfault
                    when accessed via 'this->'
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michael at ensslin dot cc

In the following minimal example, f() causes a segfault in the compiled
program, while g() and h() don't.
Note that the error also occurs in clang++.

mic@mic-nb $ cat test.cpp
#include <string>

struct A{
    static thread_local std::string s;

    void f() {
        this->s = "segv";
    }

    void g() {
        A::s =    "no segv";
    }

    void h() {
        s =       "no segv";
    }
};

thread_local std::string A::s;

int main() {
    A{}.f();
    return 0;
}

mic@mic-nb $ g++ -std=c++11 -lpthread test.cpp         
mic@mic-nb $ ./a.out 
[1]    11729 segmentation fault (core dumped)  ./a.out
mic@mic-nb $ clang++ -std=c++11 -lpthread test.cpp
mic@mic-nb $ ./a.out 
[1]    11764 segmentation fault (core dumped)  ./a.out

Precise versions of installed software:

mic@mic-nb $ g++ --version    
g++ (GCC) 4.8.2 20140206 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mic@mic-nb $ clang++ --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
mic@mic-nb $ uname -a
Linux mic-nb 3.13.6-1-ARCH #1 SMP PREEMPT Fri Mar 7 22:47:48 CET 2014 x86_64
GNU/Linux


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/60673] c++11 static thread_local members may cause a segfault when accessed via 'this->'
  2014-03-26 16:47 [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->' michael at ensslin dot cc
@ 2014-03-26 18:44 ` redi at gcc dot gnu.org
  2021-08-22 22:46 ` pinskia at gcc dot gnu.org
  2021-08-22 22:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2014-03-26 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-03-26
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/60673] c++11 static thread_local members may cause a segfault when accessed via 'this->'
  2014-03-26 16:47 [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->' michael at ensslin dot cc
  2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
@ 2021-08-22 22:46 ` pinskia at gcc dot gnu.org
  2021-08-22 22:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 22:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60673

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> This seems to be fixed in GCC 5 onwards (and recent Clang versions).

It was not fixed until GCC 7.5, 8.4 and 9+.
Here is a reduced testcase which shows it was not fixed until then:
extern "C" void abort(void);
struct tt
{
  int *tt1 = new int{1};
  int bucket_count() const {return *tt1;}
};
struct A{
        static thread_local tt  s;

        int f() {
                return this->s.bucket_count();
        }
        int g() {
                return A::s.bucket_count();
        }
        int h() {
                return s.bucket_count();
        }
};
thread_local tt A::s;
int main() {
        if (A{}.f() != 1) abort();
        return 0;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/60673] c++11 static thread_local members may cause a segfault when accessed via 'this->'
  2014-03-26 16:47 [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->' michael at ensslin dot cc
  2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
  2021-08-22 22:46 ` pinskia at gcc dot gnu.org
@ 2021-08-22 22:48 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-22 22:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60673

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Which makes this a dup of bug 60702.

*** This bug has been marked as a duplicate of bug 60702 ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-22 22:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-26 16:47 [Bug c++/60673] New: c++11 static thread_local members may cause a segfault when accessed via 'this->' michael at ensslin dot cc
2014-03-26 18:44 ` [Bug c++/60673] " redi at gcc dot gnu.org
2021-08-22 22:46 ` pinskia at gcc dot gnu.org
2021-08-22 22:48 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).