public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag
@ 2014-01-01 19:20 chus_flores at hotmail dot com
  2014-01-06 17:34 ` [Bug libstdc++/59656] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: chus_flores at hotmail dot com @ 2014-01-01 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59656
           Summary: weak_ptr::lock function crashes when compiling with
                    -fno-exceptions flag
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chus_flores at hotmail dot com

weak_ptr::lock crashes when the code is compiled with the -fno-exceptions flag
and the data pointed by the weak_ptr expires during the execution of the lock
function itself:

(from http://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01518_source.html)

shared_ptr<_Tp>
  494       lock() const noexcept
  495       {
  496 #ifdef __GTHREADS
  497     if (this->expired())
  498       return shared_ptr<_Tp>();
  499 
  500     __try
  501       {
  502         return shared_ptr<_Tp>(*this);
  503       }
  504     __catch(const bad_weak_ptr&)
  505       {
  506         return shared_ptr<_Tp>();
  507       }
  508 #else
  509     return this->expired() ? shared_ptr<_Tp>() : shared_ptr<_Tp>(*this);
  510 #endif
  511       }

If the data is valid when line 497 is executed and the data is released in a
different thread just before executing line 502, the program will crash because
it will try to throw an exception (exceptions are disabled because of the flag
-fno-exceptions). This code only works when exceptions are enabled because the
try/catch will resolve the problem, but not otherwise.

The standard definition says that this function must return safely and it
doesn't throw any exception. I presume this must apply even if the exceptions
are not enabled.


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
@ 2014-01-06 17:34 ` redi at gcc dot gnu.org
  2014-01-18 16:55 ` ppluzhnikov at google dot com
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-06 17:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The standard says exceptions are always enabled, if you disable them you are no
longer using standard C++, so what it says in the standard doesn't necessarily
apply.

I don't think it would be simple to make this work with -fno-exceptions


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
  2014-01-06 17:34 ` [Bug libstdc++/59656] " redi at gcc dot gnu.org
@ 2014-01-18 16:55 ` ppluzhnikov at google dot com
  2014-01-18 16:58 ` ppluzhnikov at google dot com
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-18 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot com

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
(In reply to Jonathan Wakely from comment #1)
> The standard says exceptions are always enabled, if you disable them you are
> no longer using standard C++, so what it says in the standard doesn't
> necessarily apply.

It's a quality of implementation issue: effectively current std::weak_ptr is
not usable in any multithreaded program built with -fno-exceptions.

> I don't think it would be simple to make this work with -fno-exceptions

We have a patch that makes it work.


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
  2014-01-06 17:34 ` [Bug libstdc++/59656] " redi at gcc dot gnu.org
  2014-01-18 16:55 ` ppluzhnikov at google dot com
@ 2014-01-18 16:58 ` ppluzhnikov at google dot com
  2014-01-21 21:05 ` ppluzhnikov at google dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-18 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
*** Bug 59869 has been marked as a duplicate of this bug. ***


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (2 preceding siblings ...)
  2014-01-18 16:58 ` ppluzhnikov at google dot com
@ 2014-01-21 21:05 ` ppluzhnikov at google dot com
  2014-01-22 11:21 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-21 21:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Created attachment 31911
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31911&action=edit
test case

Copy of test case from PR 59869


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (3 preceding siblings ...)
  2014-01-21 21:05 ` ppluzhnikov at google dot com
@ 2014-01-22 11:21 ` redi at gcc dot gnu.org
  2014-01-22 13:31 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-22 11:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Thanks Paul. You mentioned a proposed patch, are you working on that? From a
quick look I didn't see how to fix it without adding a
_Sp_counted_base::_M_add_ref_lock_nothrow() function and adding new
constructors taking an additional std::nothrow_t argument to the whole class
hierarchy. Did you have a simpler fix in mind?


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (4 preceding siblings ...)
  2014-01-22 11:21 ` redi at gcc dot gnu.org
@ 2014-01-22 13:31 ` redi at gcc dot gnu.org
  2014-01-22 19:20 ` ppluzhnikov at google dot com
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-22 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Created attachment 31920
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31920&action=edit
don't use _M_add_ref_lock() when exceptions are disabled

Here's a patch which fixes Paul's testcase


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (5 preceding siblings ...)
  2014-01-22 13:31 ` redi at gcc dot gnu.org
@ 2014-01-22 19:20 ` ppluzhnikov at google dot com
  2014-01-24 17:43 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-01-22 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Created attachment 31924
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31924&action=edit
Alternate fix from Kyle Lippincott

Alternate patch, courtesy Kyle Lippincott <spectral@google.com>.

AFAIU, Kyle's patch uses roughly the same idea as Jonathan's,
but no #ifdef's.

Should we take these patches to gcc-patches list?


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (6 preceding siblings ...)
  2014-01-22 19:20 ` ppluzhnikov at google dot com
@ 2014-01-24 17:43 ` redi at gcc dot gnu.org
  2014-01-28 10:24 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-24 17:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2014-01-24
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Thanks, yes the general idea is identical. I prefer some parts of Kyle's fix
but I don't want the new constructor to be public, so I'll combine the two
patches and post it to gcc-patches next week.


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (8 preceding siblings ...)
  2014-01-28 10:24 ` redi at gcc dot gnu.org
@ 2014-01-28 10:24 ` redi at gcc dot gnu.org
  2014-01-28 19:08 ` ppluzhnikov at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-28 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Tue Jan 28 10:23:27 2014
New Revision: 207180

URL: http://gcc.gnu.org/viewcvs?rev=207180&root=gcc&view=rev
Log:
2014-01-28  Jonathan Wakely  <jwakely@redhat.com>
        Kyle Lippincott  <spectral@google.com>

    PR libstdc++/59656
    * include/bits/shared_ptr.h (shared_ptr): Add new non-throwing
    constructor and grant friendship to weak_ptr.
    (weak_ptr::lock()): Use new constructor.
    * include/bits/shared_ptr_base.h
    (_Sp_counted_base::_M_add_ref_lock_nothrow()): Declare new function
    and define specializations.
    (__shared_count): Add new non-throwing constructor.
    (__shared_ptr): Add new non-throwing constructor and grant friendship
    to __weak_ptr.
    (__weak_ptr::lock()): Use new constructor.
    * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error.
    * testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/shared_ptr.h
    trunk/libstdc++-v3/include/bits/shared_ptr_base.h
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (7 preceding siblings ...)
  2014-01-24 17:43 ` redi at gcc dot gnu.org
@ 2014-01-28 10:24 ` redi at gcc dot gnu.org
  2014-01-28 10:24 ` redi at gcc dot gnu.org
  2014-01-28 19:08 ` ppluzhnikov at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-01-28 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.9.0

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk


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

* [Bug libstdc++/59656] weak_ptr::lock function crashes when compiling with -fno-exceptions flag
  2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
                   ` (9 preceding siblings ...)
  2014-01-28 10:24 ` redi at gcc dot gnu.org
@ 2014-01-28 19:08 ` ppluzhnikov at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at gcc dot gnu.org @ 2014-01-28 19:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from ppluzhnikov at gcc dot gnu.org ---
Author: ppluzhnikov
Date: Tue Jan 28 19:08:00 2014
New Revision: 207201

URL: http://gcc.gnu.org/viewcvs?rev=207201&root=gcc&view=rev
Log:
For Google b/12533273 and PR 59656, partially backport r207180 from trunk.

(The new test: libstdc++-v3/testsuite/20_util/shared_ptr/cons/void_neg.cc
is not added, because it succeeds to compile with gcc-4_8.)

Modified:
    branches/google/gcc-4_8/libstdc++-v3/include/bits/shared_ptr.h
    branches/google/gcc-4_8/libstdc++-v3/include/bits/shared_ptr_base.h
   
branches/google/gcc-4_8/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc


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

end of thread, other threads:[~2014-01-28 19:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-01 19:20 [Bug libstdc++/59656] New: weak_ptr::lock function crashes when compiling with -fno-exceptions flag chus_flores at hotmail dot com
2014-01-06 17:34 ` [Bug libstdc++/59656] " redi at gcc dot gnu.org
2014-01-18 16:55 ` ppluzhnikov at google dot com
2014-01-18 16:58 ` ppluzhnikov at google dot com
2014-01-21 21:05 ` ppluzhnikov at google dot com
2014-01-22 11:21 ` redi at gcc dot gnu.org
2014-01-22 13:31 ` redi at gcc dot gnu.org
2014-01-22 19:20 ` ppluzhnikov at google dot com
2014-01-24 17:43 ` redi at gcc dot gnu.org
2014-01-28 10:24 ` redi at gcc dot gnu.org
2014-01-28 10:24 ` redi at gcc dot gnu.org
2014-01-28 19:08 ` ppluzhnikov 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).