public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input
@ 2013-10-18 22:21 luto at mit dot edu
  2013-10-18 22:22 ` [Bug libstdc++/58800] " luto at mit dot edu
                   ` (27 more replies)
  0 siblings, 28 replies; 29+ messages in thread
From: luto at mit dot edu @ 2013-10-18 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58800
           Summary: [4.8 regression, I think] std::nth_element segfaults
                    on valid input
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luto at mit dot edu

This program segfaults on gcc 4.8.1 from Ubuntu 13.10.  I'm building a copy of
the 4.8 branch to see if I can reproduce it there.

This is on x86_64.  I used a gross hack to specify the input so I don't have to
think about precision issues.  The numbers are all well-behaved values near
0.9.

I'll attach preprocessed source.  The preprocessed source crashes even if built
with gcc 4.7.something.

#include <algorithm>
#include <stdint.h>
//#include <iostream>

double to_double(uint64_t x)
{
        union {double d; uint64_t x;} u;
        u.x = x;
        return u.d;
}

int main()
{
        std::vector<double> v = {
                to_double(4606672070890243784),
                to_double(4606672025854247510),
                to_double(4606671800674266141),
                to_double(4606671575494284772),
                to_double(4606672115926240057),
                to_double(4606672160962236330),
                to_double(4606672070890243784),
        };

//        for (auto i : v)
//                std::cout << i << std::endl;

        std::nth_element(v.begin(), v.begin() + 3, v.end());
        return 0;
}


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

* [Bug libstdc++/58800] [4.8 regression, I think] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
@ 2013-10-18 22:22 ` luto at mit dot edu
  2013-10-18 22:48 ` paolo.carlini at oracle dot com
                   ` (26 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: luto at mit dot edu @ 2013-10-18 22:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andy Lutomirski <luto at mit dot edu> ---
Created attachment 31047
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31047&action=edit
preprocessed source

This was generated with g++ -std=gnu++11 -E sort.cc on Ubuntu 13.10.


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

* [Bug libstdc++/58800] [4.8 regression, I think] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
  2013-10-18 22:22 ` [Bug libstdc++/58800] " luto at mit dot edu
@ 2013-10-18 22:48 ` paolo.carlini at oracle dot com
  2013-10-18 23:05 ` paolo.carlini at oracle dot com
                   ` (25 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-18 22:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Please figure out a testcase involving plain integers.


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

* [Bug libstdc++/58800] [4.8 regression, I think] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
  2013-10-18 22:22 ` [Bug libstdc++/58800] " luto at mit dot edu
  2013-10-18 22:48 ` paolo.carlini at oracle dot com
@ 2013-10-18 23:05 ` paolo.carlini at oracle dot com
  2013-10-18 23:17 ` paolo.carlini at oracle dot com
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-18 23:05 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-10-18
                 CC|                            |chris at bubblescope dot net
     Ever confirmed|0                           |1

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Unfortunately the issue seems real. I can reproduce it with:

        std::vector<uint64_t> v = {
                4606672070890243784,
                4606672025854247510,
                4606671800674266141,
                4606671575494284772,
                4606672115926240057,
                4606672160962236330,
                4606672070890243784,
        };

Chris?


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

* [Bug libstdc++/58800] [4.8 regression, I think] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (2 preceding siblings ...)
  2013-10-18 23:05 ` paolo.carlini at oracle dot com
@ 2013-10-18 23:17 ` paolo.carlini at oracle dot com
  2013-10-18 23:53 ` paolo.carlini at oracle dot com
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-18 23:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I can also reproduce with something this simple:

        std::vector<int> v = {
                207089,
                202585,
                180067,
                157549,
                211592,
                216096,
                207089
        };

-D_GLIBCXX_DEBUG reveals that we are dereferencing a past-the-end iterator. We
badly need a quick fix. Say 2-3 day max or we have to revert the fix for 58437.


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

* [Bug libstdc++/58800] [4.8 regression, I think] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (3 preceding siblings ...)
  2013-10-18 23:17 ` paolo.carlini at oracle dot com
@ 2013-10-18 23:53 ` paolo.carlini at oracle dot com
  2013-10-19  0:13 ` [Bug libstdc++/58800] [4.8.2/4.9 Regression] " luto at mit dot edu
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-18 23:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Don't tell me is just this:

Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h    (revision 203835)
+++ include/bits/stl_algo.h    (working copy)
@@ -1917,7 +1917,7 @@
                 _RandomAccessIterator __last, _Compare __comp)
     {
       _RandomAccessIterator __mid = __first + (__last - __first) / 2;
-      std::__move_median_to_first(__first, __first + 1, __mid, (__last - 2),
+      std::__move_median_to_first(__first, __first + 1, __mid, (__last - 1),
                   __comp);
       return std::__unguarded_partition(__first + 1, __last, __first, __comp);
     }

??

Andy, while waiting for Chris' feedback, you may want to test the above on your
real applications. In 4.8.x some nth_algorithm details are different (the above
is versus mainline), but you can quickly find a couple of (__last - 2) which
I'm asking you to change to (__last - 1)


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (4 preceding siblings ...)
  2013-10-18 23:53 ` paolo.carlini at oracle dot com
@ 2013-10-19  0:13 ` luto at mit dot edu
  2013-10-19  0:20 ` luto at mit dot edu
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: luto at mit dot edu @ 2013-10-19  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andy Lutomirski <luto at mit dot edu> ---
I changed two instances of __last - 2 to __last - 1.  I'm running against
r203836 on gcc-4_8-branch.

The thing that caught it was an experiment, not part of my test suite, so this
is a little tricky.  It already survived longer than the unpatched version did.
 The crash wasn't the same segfault, though -- it was a much later crash due to
memory corruption.  I'll let it run for a while under valgrind to see what, if
anything, pops up.


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (5 preceding siblings ...)
  2013-10-19  0:13 ` [Bug libstdc++/58800] [4.8.2/4.9 Regression] " luto at mit dot edu
@ 2013-10-19  0:20 ` luto at mit dot edu
  2013-10-19  0:22 ` paolo.carlini at oracle dot com
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: luto at mit dot edu @ 2013-10-19  0:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andy Lutomirski <luto at mit dot edu> ---
FWIW, replacing that list with a random permutation seems to crash about 5% of
the time.


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (6 preceding siblings ...)
  2013-10-19  0:20 ` luto at mit dot edu
@ 2013-10-19  0:22 ` paolo.carlini at oracle dot com
  2013-10-19  0:35 ` luto at mit dot edu
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19  0:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thanks Andy. We really want to fix this as soon as possible. In the meanwhile
in my tests the tweak passed the testsuite, without regressing on the
performance of std::sort (libstdc++/58437). Thus apparently we are on the right
track.


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (7 preceding siblings ...)
  2013-10-19  0:22 ` paolo.carlini at oracle dot com
@ 2013-10-19  0:35 ` luto at mit dot edu
  2013-10-19  7:36 ` glisse at gcc dot gnu.org
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: luto at mit dot edu @ 2013-10-19  0:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Andy Lutomirski <luto at mit dot edu> ---
This code has survived my smoke test so far, which is a good sign.  If it was
causing some kind of bad problem, I'd expect something to have exploded by now.


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (8 preceding siblings ...)
  2013-10-19  0:35 ` luto at mit dot edu
@ 2013-10-19  7:36 ` glisse at gcc dot gnu.org
  2013-10-19  7:48 ` paolo.carlini at oracle dot com
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-19  7:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Marc Glisse <glisse at gcc dot gnu.org> ---
{0, 1, 2, 0} should be enough.

__unguarded_partition only stops increasing __first when *__first is not
smaller than the pivot. If all elements are smaller than the pivot, boom. And
when we have fewer than 5 elements (the check in __introselect is only for >
3), the pivot selection code doesn't guarantee that (some of the 3 pointers
used to compute the median are the same, and with Paolo's change they become
distinct).


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

* [Bug libstdc++/58800] [4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (9 preceding siblings ...)
  2013-10-19  7:36 ` glisse at gcc dot gnu.org
@ 2013-10-19  7:48 ` paolo.carlini at oracle dot com
  2013-10-19  7:55 ` [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 " chris at bubblescope dot net
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19  7:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Hi Marc. I'm coming to the conclusion that the '- 2' in the patch sent by Chris
was in any case a typo. Now, sorry I didn't investigate the issue further, I'm
not sure to understand if you think changing it to '- 1' is enough or not: it
certainly passes or my tests so far ({0, 1, 2, 0} included)


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (10 preceding siblings ...)
  2013-10-19  7:48 ` paolo.carlini at oracle dot com
@ 2013-10-19  7:55 ` chris at bubblescope dot net
  2013-10-19  8:05 ` paolo.carlini at oracle dot com
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: chris at bubblescope dot net @ 2013-10-19  7:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Chris Jefferson <chris at bubblescope dot net> ---
Yes, I didn't trace all the members which call __unguarded_partition_pivot.

The better (in my opinion) fix is to change __introselect from:

__last - __first > 3

to:

__last - __first > int(_S_threshold)

Like the other call the __unguarded_partition_pivot.

I am currently testing that change.

The 'last - 2' was on purpose (although, it is causing the problem!), as 'last
- 1' is the the last element of the array which we want to avoid (think of it
as 'last - 1 - 1', to go with 'first + 1'. Obviously we couldn't de-ref 'last -
1'.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (11 preceding siblings ...)
  2013-10-19  7:55 ` [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 " chris at bubblescope dot net
@ 2013-10-19  8:05 ` paolo.carlini at oracle dot com
  2013-10-19  8:15 ` glisse at gcc dot gnu.org
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Ok, note that I was reviewing the description you originally sent to the
mailing list and it never talked about the - 2...

Let's figure out something safe, please.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (12 preceding siblings ...)
  2013-10-19  8:05 ` paolo.carlini at oracle dot com
@ 2013-10-19  8:15 ` glisse at gcc dot gnu.org
  2013-10-19  8:49 ` chris at bubblescope dot net
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-19  8:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Chris Jefferson from comment #12)
> The better (in my opinion) fix is to change __introselect from:
> 
> __last - __first > 3
> 
> to:
> 
> __last - __first > int(_S_threshold)
> 
> Like the other call the __unguarded_partition_pivot.

Note that the optimal threshold is probably not the same for sort and for
select (which drops to full sorting below that threshold!).


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (13 preceding siblings ...)
  2013-10-19  8:15 ` glisse at gcc dot gnu.org
@ 2013-10-19  8:49 ` chris at bubblescope dot net
  2013-10-19  8:54 ` chris at bubblescope dot net
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: chris at bubblescope dot net @ 2013-10-19  8:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #15 from Chris Jefferson <chris at bubblescope dot net> ---
In my last comment, "Obviously we couldn't de-ref 'last - 1'" should have been
"Obviously we couldn't de-ref 'last'"


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (14 preceding siblings ...)
  2013-10-19  8:49 ` chris at bubblescope dot net
@ 2013-10-19  8:54 ` chris at bubblescope dot net
  2013-10-19 10:02 ` paolo.carlini at oracle dot com
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: chris at bubblescope dot net @ 2013-10-19  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #16 from Chris Jefferson <chris at bubblescope dot net> ---
Created attachment 31049
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31049&action=edit
random test

In order to catch any other issues, and stop this kind of thing happening
again, I want to quickly and massively expand the algorithms testsuite.

The attached test tests a whole set of random nth_element cases (it would catch
the problem we are currently having).

The problem is on my computer, unoptimised, this test takes 30 seconds, and I
want to add a similar test to all the sorting related algorithms. Is there a
standard way of submitting tests that take a lot of time and memory?


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (15 preceding siblings ...)
  2013-10-19  8:54 ` chris at bubblescope dot net
@ 2013-10-19 10:02 ` paolo.carlini at oracle dot com
  2013-10-19 11:06 ` chris at bubblescope dot net
                   ` (10 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #17 from Paolo Carlini <paolo.carlini at oracle dot com> ---
At the moment there isn't, but some tests self adjust to run less on
simulators. For the time being I think we could certainly add a few (not 10 or
20) of the tests tou are talking about, but remember all with the bits for the
simulators. We could also easily add some tests to the performance testsuite
(there are no limits there and isn't run by default) which, outside the timing
loop also check that the computation is correct (well, we should probably
allways do that)


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (16 preceding siblings ...)
  2013-10-19 10:02 ` paolo.carlini at oracle dot com
@ 2013-10-19 11:06 ` chris at bubblescope dot net
  2013-10-19 12:11 ` chris at bubblescope dot net
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: chris at bubblescope dot net @ 2013-10-19 11:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #18 from Chris Jefferson <chris at bubblescope dot net> ---
(In reply to Paolo Carlini from comment #13)
> Ok, note that I was reviewing the description you originally sent to the
> mailing list and it never talked about the - 2...
> 
> Let's figure out something safe, please.

I miswrote in my final paragraph:

...first+1, mid, last-1 (there is no reason in this bug to consider
last-1 instead of last, but I thought it wouldn't do any harm, and
might avoid other issues of accidentally choosing a bad pivot.

Should have said:

...first+1, mid, last-2 (there is no reason in this bug to consider *last-2*
instead of *last-1*, but I thought it wouldn't do any harm, and might avoid
other issues of accidentally choosing a bad pivot.

So, the original code chose last-1, I moved that to last-2, not checking all
the places that called the code enough (although, I could also have broken it
with the first+1 if the ranges had been small enough).

Changing 'last-2' to 'last-1' might well be the easiest, smallest fix, if it
does not effect the performance testsuite. We can then, once we have a much
more comphrehensive testsuite, make another pass at performance improvements
and tweaks.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (17 preceding siblings ...)
  2013-10-19 11:06 ` chris at bubblescope dot net
@ 2013-10-19 12:11 ` chris at bubblescope dot net
  2013-10-19 17:47 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: chris at bubblescope dot net @ 2013-10-19 12:11 UTC (permalink / raw)
  To: gcc-bugs

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

Chris Jefferson <chris at bubblescope dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #31049|0                           |1
        is obsolete|                            |

--- Comment #19 from Chris Jefferson <chris at bubblescope dot net> ---
Created attachment 31051
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31051&action=edit
nth_element patch

Here is a patch. The actual patch is just changing '__last - 2' to '__last - 1'
(***NOTE*** When back-applying this patch, before the recent merge of
algorithms, there will be two copies of __last - 2 to change).

The larger part is a patch just for this bug, and a general big improvement in
the test procedure, to sanity check no other related methods have any issues
(they do not). I intend to continue to add new testsuite functions in the
future, but this will do to start.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (18 preceding siblings ...)
  2013-10-19 12:11 ` chris at bubblescope dot net
@ 2013-10-19 17:47 ` paolo.carlini at oracle dot com
  2013-10-19 18:07 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19 17:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #20 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Chris, <random> isn't unconditionally available (requires
_GLIBCXX_USE_C99_STDINT_TR1 defined). Please massage the new tests (and the new
header) to just do nothing when <random> isn't available and send the result
separately to the library mailing list. Let's first commit everywhere fix +
minimal testcase.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (19 preceding siblings ...)
  2013-10-19 17:47 ` paolo.carlini at oracle dot com
@ 2013-10-19 18:07 ` paolo.carlini at oracle dot com
  2013-10-20  9:07 ` paolo at gcc dot gnu.org
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-19 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #21 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I think you can probably simply add at the beginning of the new tests:

// { dg-require-cstdint "" }

and then the new include doesn't require any change. But please double check,
we don't want new Bugzillas: say, damage check_v3_target_cstdint to
artificially return false on your machine and double check that the new
testcases are simply skipped.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (20 preceding siblings ...)
  2013-10-19 18:07 ` paolo.carlini at oracle dot com
@ 2013-10-20  9:07 ` paolo at gcc dot gnu.org
  2013-10-20  9:08 ` paolo at gcc dot gnu.org
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-10-20  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #22 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Sun Oct 20 09:07:36 2013
New Revision: 203872

URL: http://gcc.gnu.org/viewcvs?rev=203872&root=gcc&view=rev
Log:
2013-10-20  Chris Jefferson  <chris@bubblescope.net>
        Paolo Carlini  <paolo.carlini@oracle.com>

    PR libstdc++/58800
    * include/bits/stl_algo.h (__unguarded_partition_pivot): Change
    __last - 2 to __last - 1.
    * testsuite/25_algorithms/nth_element/58800.cc: New

Added:
    trunk/libstdc++-v3/testsuite/25_algorithms/nth_element/58800.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/stl_algo.h


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (21 preceding siblings ...)
  2013-10-20  9:07 ` paolo at gcc dot gnu.org
@ 2013-10-20  9:08 ` paolo at gcc dot gnu.org
  2013-10-20  9:08 ` paolo at gcc dot gnu.org
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-10-20  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #23 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Sun Oct 20 09:08:12 2013
New Revision: 203873

URL: http://gcc.gnu.org/viewcvs?rev=203873&root=gcc&view=rev
Log:
2013-10-20  Chris Jefferson  <chris@bubblescope.net>
        Paolo Carlini  <paolo.carlini@oracle.com>

    PR libstdc++/58800
    * include/bits/stl_algo.h (__unguarded_partition_pivot): Change
    __last - 2 to __last - 1.
    * testsuite/25_algorithms/nth_element/58800.cc: New

Added:
   
branches/gcc-4_8-branch/libstdc++-v3/testsuite/25_algorithms/nth_element/58800.cc
Modified:
    branches/gcc-4_8-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_8-branch/libstdc++-v3/include/bits/stl_algo.h


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (22 preceding siblings ...)
  2013-10-20  9:08 ` paolo at gcc dot gnu.org
@ 2013-10-20  9:08 ` paolo at gcc dot gnu.org
  2013-10-20  9:09 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-10-20  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #24 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Sun Oct 20 09:08:26 2013
New Revision: 203874

URL: http://gcc.gnu.org/viewcvs?rev=203874&root=gcc&view=rev
Log:
2013-10-20  Chris Jefferson  <chris@bubblescope.net>
        Paolo Carlini  <paolo.carlini@oracle.com>

    PR libstdc++/58800
    * include/bits/stl_algo.h (__unguarded_partition_pivot): Change
    __last - 2 to __last - 1.
    * testsuite/25_algorithms/nth_element/58800.cc: New

Added:
   
branches/gcc-4_7-branch/libstdc++-v3/testsuite/25_algorithms/nth_element/58800.cc
Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/bits/stl_algo.h


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (23 preceding siblings ...)
  2013-10-20  9:08 ` paolo at gcc dot gnu.org
@ 2013-10-20  9:09 ` paolo.carlini at oracle dot com
  2013-10-21  8:39 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 29+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-20  9:09 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

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

--- Comment #25 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed for 4.7.4/4.8.3/4.9.0.


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

* [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (24 preceding siblings ...)
  2013-10-20  9:09 ` paolo.carlini at oracle dot com
@ 2013-10-21  8:39 ` rguenth at gcc dot gnu.org
  2013-11-13 15:59 ` [Bug libstdc++/58800] [4.7/4.8/4.9 " glisse at gcc dot gnu.org
  2013-12-19 16:12 ` rguenth at gcc dot gnu.org
  27 siblings, 0 replies; 29+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-21  8:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.7.4, 4.8.3, 4.9.0
   Target Milestone|---                         |4.7.4


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

* [Bug libstdc++/58800] [4.7/4.8/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (25 preceding siblings ...)
  2013-10-21  8:39 ` rguenth at gcc dot gnu.org
@ 2013-11-13 15:59 ` glisse at gcc dot gnu.org
  2013-12-19 16:12 ` rguenth at gcc dot gnu.org
  27 siblings, 0 replies; 29+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-11-13 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chandraprakashblr at gmail dot com

--- Comment #26 from Marc Glisse <glisse at gcc dot gnu.org> ---
*** Bug 59116 has been marked as a duplicate of this bug. ***


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

* [Bug libstdc++/58800] [4.7/4.8/4.9 Regression] std::nth_element segfaults on valid input
  2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
                   ` (26 preceding siblings ...)
  2013-11-13 15:59 ` [Bug libstdc++/58800] [4.7/4.8/4.9 " glisse at gcc dot gnu.org
@ 2013-12-19 16:12 ` rguenth at gcc dot gnu.org
  27 siblings, 0 replies; 29+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-12-19 16:12 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #27 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 59557 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2013-12-19 16:12 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-18 22:21 [Bug libstdc++/58800] New: [4.8 regression, I think] std::nth_element segfaults on valid input luto at mit dot edu
2013-10-18 22:22 ` [Bug libstdc++/58800] " luto at mit dot edu
2013-10-18 22:48 ` paolo.carlini at oracle dot com
2013-10-18 23:05 ` paolo.carlini at oracle dot com
2013-10-18 23:17 ` paolo.carlini at oracle dot com
2013-10-18 23:53 ` paolo.carlini at oracle dot com
2013-10-19  0:13 ` [Bug libstdc++/58800] [4.8.2/4.9 Regression] " luto at mit dot edu
2013-10-19  0:20 ` luto at mit dot edu
2013-10-19  0:22 ` paolo.carlini at oracle dot com
2013-10-19  0:35 ` luto at mit dot edu
2013-10-19  7:36 ` glisse at gcc dot gnu.org
2013-10-19  7:48 ` paolo.carlini at oracle dot com
2013-10-19  7:55 ` [Bug libstdc++/58800] [4.7.4/4.8.2/4.9 " chris at bubblescope dot net
2013-10-19  8:05 ` paolo.carlini at oracle dot com
2013-10-19  8:15 ` glisse at gcc dot gnu.org
2013-10-19  8:49 ` chris at bubblescope dot net
2013-10-19  8:54 ` chris at bubblescope dot net
2013-10-19 10:02 ` paolo.carlini at oracle dot com
2013-10-19 11:06 ` chris at bubblescope dot net
2013-10-19 12:11 ` chris at bubblescope dot net
2013-10-19 17:47 ` paolo.carlini at oracle dot com
2013-10-19 18:07 ` paolo.carlini at oracle dot com
2013-10-20  9:07 ` paolo at gcc dot gnu.org
2013-10-20  9:08 ` paolo at gcc dot gnu.org
2013-10-20  9:08 ` paolo at gcc dot gnu.org
2013-10-20  9:09 ` paolo.carlini at oracle dot com
2013-10-21  8:39 ` rguenth at gcc dot gnu.org
2013-11-13 15:59 ` [Bug libstdc++/58800] [4.7/4.8/4.9 " glisse at gcc dot gnu.org
2013-12-19 16:12 ` rguenth 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).