public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer
@ 2024-01-29 17:31 ostash at ostash dot kiev.ua
  2024-01-29 17:51 ` [Bug c++/113662] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ostash at ostash dot kiev.ua @ 2024-01-29 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113662
           Summary: [13/14 Regression] Wrong code for std::sort with fancy
                    pointer
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ostash at ostash dot kiev.ua
  Target Milestone: ---

Hello,

For the following snippet compiled with "-O3 -std=c++20"
---
#include <boost/container/vector.hpp>
#include <boost/interprocess/offset_ptr.hpp>

#include <algorithm>
#include <iostream>

struct Foo
{
public:
  uint32_t m1; 
  uint32_t m2;
  uint8_t m3;
};

bool operator<(const Foo& lhs, const Foo& rhs)
{
  return lhs.m1 < rhs.m1;
}

template <typename T>
class MyAllocator 
{
public:
  using value_type = T;
  using pointer = boost::interprocess::offset_ptr<T>;

  boost::interprocess::offset_ptr<T> allocate( std::size_t n ) {
      return boost::interprocess::offset_ptr<T>(a.allocate(n));
  }
  void deallocate(  boost::interprocess::offset_ptr<T> p, std::size_t n ) {
      a.deallocate(p.get(), n);
  }

  std::allocator<T> a;
};

int main()
{
    boost::container::vector<Foo, MyAllocator<Foo>> vec;
    vec.emplace_back().m1 = 4748;
    vec.emplace_back().m1 = 4687;
    vec.emplace_back().m1 = 4717;
    vec.emplace_back().m1 = 4779;

    std::cout << "before: " <<  vec.size() << '\n';
    for (const auto& x : vec)
        std::cout << std::to_string(x.m1) << '\n';

    std::sort(vec.begin(), vec.end());

    std::cout << "after: " <<  vec.size() << '\n';
    for (const auto& x : vec)
        std::cout << std::to_string(x.m1) << '\n';
}
---

we receive the following output:
---
before: 4
4748
4687
4717
4779
after: 4
4687
4717
4717
4779
---

I've managed to bisect this issue to the following commit:
429a7a88438cc80e7c58d9f63d44838089899b12 is the first bad commit
commit 429a7a88438cc80e7c58d9f63d44838089899b12
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Tue Mar 28 12:16:34 2023 -0400
   Add recursive GORI recompuations with a depth limit.
           PR tree-optimization/109154
           gcc/
           * gimple-range-gori.cc (gori_compute::may_recompute_p): Add depth
limit.
           * gimple-range-gori.h (may_recompute_p): Add depth param.
           * params.opt (ranger-recompute-depth): New param.
           gcc/testsuite/
           * gcc.dg/Walloca-13.c: Remove bogus warning that is now fixed.
gcc/gimple-range-gori.cc          | 30 ++++++++++++++++++++++--------
gcc/gimple-range-gori.h           |  4 ++--
gcc/params.opt                    |  5 +++++
gcc/testsuite/gcc.dg/Walloca-13.c |  2 +-
4 files changed, 30 insertions(+), 11 deletions(-)

I tried different versions of Boost to ensure that the problem is not coming
from offset_ptr. It looks like that it is possible to reproduce issue with "-O2
-ftree-partial-pre".

Everything works fine with std::vector or std::allocator.

I'd be glad to perform other tests if needed.

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

* [Bug c++/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
@ 2024-01-29 17:51 ` pinskia at gcc dot gnu.org
  2024-01-29 17:52 ` [Bug tree-optimization/113662] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
One thing I noticed is both -fwrapv and -fno-strict-aliasing does not change
the code generation.

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
  2024-01-29 17:51 ` [Bug c++/113662] " pinskia at gcc dot gnu.org
@ 2024-01-29 17:52 ` pinskia at gcc dot gnu.org
  2024-01-29 17:53 ` ostash at ostash dot kiev.ua
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 17:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.3
          Component|c++                         |tree-optimization

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
  2024-01-29 17:51 ` [Bug c++/113662] " pinskia at gcc dot gnu.org
  2024-01-29 17:52 ` [Bug tree-optimization/113662] " pinskia at gcc dot gnu.org
@ 2024-01-29 17:53 ` ostash at ostash dot kiev.ua
  2024-01-29 17:58 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ostash at ostash dot kiev.ua @ 2024-01-29 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Viktor Ostashevskyi <ostash at ostash dot kiev.ua> ---
Adding --param=ranger-recompute-depth=1 or --param=ranger-recompute-depth=2
also fixes the issue. Higher values behave wrongly.

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
                   ` (2 preceding siblings ...)
  2024-01-29 17:53 ` ostash at ostash dot kiev.ua
@ 2024-01-29 17:58 ` pinskia at gcc dot gnu.org
  2024-01-30  5:51 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Add -fno-ivopts also fixes the issue ...

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
                   ` (3 preceding siblings ...)
  2024-01-29 17:58 ` pinskia at gcc dot gnu.org
@ 2024-01-30  5:51 ` pinskia at gcc dot gnu.org
  2024-03-07 20:43 ` [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer since r13-6945-g429a7a88438cc8 law at gcc dot gnu.org
  2024-03-12 13:21 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-30  5:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> Add -fno-ivopts also fixes the issue ...

Note -fstack-reuse=none does NOT fix the issue so it is NOT the same as those.

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer since r13-6945-g429a7a88438cc8
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
                   ` (4 preceding siblings ...)
  2024-01-30  5:51 ` pinskia at gcc dot gnu.org
@ 2024-03-07 20:43 ` law at gcc dot gnu.org
  2024-03-12 13:21 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 20:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-03-07
     Ever confirmed|0                           |1
           Priority|P3                          |P1
                 CC|                            |law at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

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

* [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer since r13-6945-g429a7a88438cc8
  2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
                   ` (5 preceding siblings ...)
  2024-03-07 20:43 ` [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer since r13-6945-g429a7a88438cc8 law at gcc dot gnu.org
@ 2024-03-12 13:21 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-12 13:21 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.{1,2} has been released with this bug, so P2.

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

end of thread, other threads:[~2024-03-12 13:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-29 17:31 [Bug c++/113662] New: [13/14 Regression] Wrong code for std::sort with fancy pointer ostash at ostash dot kiev.ua
2024-01-29 17:51 ` [Bug c++/113662] " pinskia at gcc dot gnu.org
2024-01-29 17:52 ` [Bug tree-optimization/113662] " pinskia at gcc dot gnu.org
2024-01-29 17:53 ` ostash at ostash dot kiev.ua
2024-01-29 17:58 ` pinskia at gcc dot gnu.org
2024-01-30  5:51 ` pinskia at gcc dot gnu.org
2024-03-07 20:43 ` [Bug tree-optimization/113662] [13/14 Regression] Wrong code for std::sort with fancy pointer since r13-6945-g429a7a88438cc8 law at gcc dot gnu.org
2024-03-12 13:21 ` jakub 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).