* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
@ 2021-03-05 12:16 ` redi at gcc dot gnu.org
2021-03-05 12:30 ` redi at gcc dot gnu.org
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Known to work| |9.3.0
Target Milestone|--- |10.3
Summary|std::copy creates |[10/11 Regression]
|_GLIBCXX_DEBUG false |std::copy creates
|positive for attempt to |_GLIBCXX_DEBUG false
|subscript a dereferenceable |positive for attempt to
|(start-of-sequence) |subscript a dereferenceable
|iterator |(start-of-sequence)
| |iterator
CC| |fdumont at gcc dot gnu.org
Known to fail| |10.1.0, 10.2.0, 11.0
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-03-05
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Probably caused by r276600
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
2021-03-05 12:16 ` [Bug libstdc++/99402] [10/11 Regression] " redi at gcc dot gnu.org
@ 2021-03-05 12:30 ` redi at gcc dot gnu.org
2021-03-05 12:33 ` redi at gcc dot gnu.org
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Kip Warner from comment #0)
> // This results in memory corruption, or an abort with STL debugging
I don't see any memory corruption, I think it's just a bug in the Debug Mode
checks, which aborts when it shouldn't do. Without those bad checks it doesn't
abort, and works correctly.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
2021-03-05 12:16 ` [Bug libstdc++/99402] [10/11 Regression] " redi at gcc dot gnu.org
2021-03-05 12:30 ` redi at gcc dot gnu.org
@ 2021-03-05 12:33 ` redi at gcc dot gnu.org
2021-03-05 12:40 ` redi at gcc dot gnu.org
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
François, this can't be right:
return std::make_pair(-__seq_dist.first,
__seq_dist.second == __dp_exact
? __dp_sign_max_size : __seq_dist.second);
This uses __seq_dist.second, but __seq_dist comes from _SeqTraits::_S_size
which is:
template<typename _Sequence>
struct _Sequence_traits
{
typedef _Distance_traits<typename _Sequence::iterator> _DistTraits;
static typename _DistTraits::__type
_S_size(const _Sequence& __seq)
{ return std::make_pair(__seq.size(), __dp_exact); }
};
i.e. __seq_dist.second is always __dp_exact, so this function always returns
__dp_sign_max_size.
You should be using __base_dist.second, no?
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (2 preceding siblings ...)
2021-03-05 12:33 ` redi at gcc dot gnu.org
@ 2021-03-05 12:40 ` redi at gcc dot gnu.org
2021-03-05 12:55 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This causes __valid_range to return {11, __dp_sign_max_size} and then we check
__result._M_can_advance(11) which fails.
We don't want to advance the result by the size of the other sequence, only by
distance(__first, __last). We don't care if there are elements in the sequence
past __last because we're not trying to copy them.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (3 preceding siblings ...)
2021-03-05 12:40 ` redi at gcc dot gnu.org
@ 2021-03-05 12:55 ` redi at gcc dot gnu.org
2021-03-05 12:59 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> You should be using __base_dist.second, no?
No, it's not that simple. I don't understand how this code is meant to work,
but this can't be right:
if (this->_M_is_begin())
{
if (__rhs._M_is_before_begin())
return std::make_pair(-1, __dp_exact);
if (__rhs._M_is_end())
return __seq_dist;
return std::make_pair(__seq_dist.first,
__seq_dist.second == __dp_exact
? __dp_sign_max_size : __seq_dist.second);
}
We can't use __seq_dist.first as the distance, because we have already
established that __rhs is not the end iterator, so it must be before the end.
And so the distance we're trying to find must be less than __seq_dist.first.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (4 preceding siblings ...)
2021-03-05 12:55 ` redi at gcc dot gnu.org
@ 2021-03-05 12:59 ` redi at gcc dot gnu.org
2021-03-05 19:26 ` fdumont at gcc dot gnu.org
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-05 12:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int main()
{
// any container with non-random access iterators:
const set<int> source = { 0, 1 };
vector<int> dest(1);
copy(source.begin(), ++source.begin(), dest.begin());
}
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (5 preceding siblings ...)
2021-03-05 12:59 ` redi at gcc dot gnu.org
@ 2021-03-05 19:26 ` fdumont at gcc dot gnu.org
2021-03-05 20:00 ` kip at thevertigo dot com
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: fdumont at gcc dot gnu.org @ 2021-03-05 19:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
François Dumont <fdumont at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |fdumont at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #7 from François Dumont <fdumont at gcc dot gnu.org> ---
Yes, when I introduced __dp_sign_max_size in the _Distance_precision enum I
forgot to adapt some code.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (6 preceding siblings ...)
2021-03-05 19:26 ` fdumont at gcc dot gnu.org
@ 2021-03-05 20:00 ` kip at thevertigo dot com
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: kip at thevertigo dot com @ 2021-03-05 20:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #8 from Kip Warner <kip at thevertigo dot com> ---
And for anyone finding this from a search engine, the temporary workaround is
to use std::copy_n.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (7 preceding siblings ...)
2021-03-05 20:00 ` kip at thevertigo dot com
@ 2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2021-04-08 12:53 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 12:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.3 |10.4
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10.3 is being released, retargeting bugs to GCC 10.4.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10/11 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (8 preceding siblings ...)
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
@ 2021-04-08 12:53 ` rguenth at gcc dot gnu.org
2021-04-13 20:51 ` [Bug libstdc++/99402] [10 " redi at gcc dot gnu.org
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 12:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (9 preceding siblings ...)
2021-04-08 12:53 ` rguenth at gcc dot gnu.org
@ 2021-04-13 20:51 ` redi at gcc dot gnu.org
2021-04-13 22:19 ` kip at thevertigo dot com
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-13 20:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[10/11 Regression] |[10 Regression] std::copy
|std::copy creates |creates _GLIBCXX_DEBUG
|_GLIBCXX_DEBUG false |false positive for attempt
|positive for attempt to |to subscript a
|subscript a dereferenceable |dereferenceable
|(start-of-sequence) |(start-of-sequence)
|iterator |iterator
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This was fixed on trunk by r11-8100:
libstdc++: [_GLIBCXX_DEBUG] Fix management of __dp_sign_max_size [PR 99402]
__dp_sign precision indicates that we found out what iterator comes first or
last in the range. __dp_sign_max_size is the same plus it gives the information
of the max size of the range that is to say the max_size value such that
distance(lhs, rhs) < max_size.
Thanks to this additional information we are able to tell when a copy of n
elements
to that range will fail even if we do not know exactly how large it is.
This patch makes sure that we are properly using this information.
libstdc++-v3/ChangeLog:
PR libstdc++/99402
* include/debug/helper_functions.h (__can_advance(_InputIterator,
const std::pair<_Diff, _Distance_precision>&, int)): New.
(__can_advance(const _Safe_iterator<>&,
const std::pair<_Diff, _Distance_precision>&, int)): New.
* include/debug/macros.h (__glibcxx_check_can_increment_dist): New,
use latter.
(__glibcxx_check_can_increment_range): Adapt to use latter.
(__glibcxx_check_can_decrement_range): Likewise.
* include/debug/safe_iterator.h
(_Safe_iterator<>::_M_can_advance(const std::pair<_Diff,
_Distance_precision>&,
int)): New.
(__can_advance(const _Safe_iterator<>&,
const std::pair<_Diff, _Distance_precision>&, int)): New.
* include/debug/safe_iterator.tcc
(_Safe_iterator<>::_M_can_advance(const std::pair<_Diff,
_Distance_precision>&,
int)): New.
(_Safe_iterator<>::_M_valid_range(const _Safe_iterator<>&,
std::pair<difference_type, _Distance_precision>&, bool)): Adapt for
__dp_sign_max_size.
(__copy_move_a): Adapt to use __glibcxx_check_can_increment_dist.
(__copy_move_backward_a): Likewise.
(__equal_aux): Likewise.
* include/debug/stl_iterator.h (__can_advance(const
std::reverse_iterator<>&,
const std::pair<_Diff, _Distance_precision>&, int)): New.
(__can_advance(const std::move_iterator<>&,
const std::pair<_Diff, _Distance_precision>&, int)): New.
* testsuite/25_algorithms/copy/debug/99402.cc: New test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (10 preceding siblings ...)
2021-04-13 20:51 ` [Bug libstdc++/99402] [10 " redi at gcc dot gnu.org
@ 2021-04-13 22:19 ` kip at thevertigo dot com
2021-04-13 22:45 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: kip at thevertigo dot com @ 2021-04-13 22:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #11 from Kip Warner <kip at thevertigo dot com> ---
Thanks Jonathan. That was a constructive follow up.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (11 preceding siblings ...)
2021-04-13 22:19 ` kip at thevertigo dot com
@ 2021-04-13 22:45 ` redi at gcc dot gnu.org
2021-04-23 12:02 ` fdumont at gcc dot gnu.org
2021-04-23 13:04 ` redi at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-13 22:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
François fixed it. I just pasted the info here that didn't get automatically
added by the commit hooks, for some reason.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (12 preceding siblings ...)
2021-04-13 22:45 ` redi at gcc dot gnu.org
@ 2021-04-23 12:02 ` fdumont at gcc dot gnu.org
2021-04-23 13:04 ` redi at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: fdumont at gcc dot gnu.org @ 2021-04-23 12:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
--- Comment #13 from François Dumont <fdumont at gcc dot gnu.org> ---
Fixed on gcc-10 branch by this commit
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ab83ce42ea0b2fbc09d51b7bd5e69905dcaa2041.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug libstdc++/99402] [10 Regression] std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator
2021-03-05 9:09 [Bug c++/99402] New: std::copy creates _GLIBCXX_DEBUG false positive for attempt to subscript a dereferenceable (start-of-sequence) iterator kip at thevertigo dot com
` (13 preceding siblings ...)
2021-04-23 12:02 ` fdumont at gcc dot gnu.org
@ 2021-04-23 13:04 ` redi at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-04-23 13:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99402
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 10.4 then. Thanks, François.
^ permalink raw reply [flat|nested] 16+ messages in thread