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

--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Reproduces even with
#include <variant>
#include <vector>

using A = std::vector <double>;
using B = std::vector <int>;

struct C
{
  bool c;
  std::variant <A, B> d;
};

[[gnu::noipa, gnu::optimize ("assume-sane-operators-new-delete")]] bool
foo (C *m, A *e)
{
  bool c = false;

  if (m->c)
    {
      *e = std::move (std::get <A> (m->d));
      c = true;
    }
  else
    std::get <B> (m->d);

  delete m;
  return c;
}

int
main ()
{
  A e { 1 };
  C *m = new C;
  m->c = true;
  m->d = A { 1 };
  foo (m, &e);
}
at -O2 and doesn't reproduce with s/"assume/"no-assume/
So it is clearly foo that is problematic.
sink1 diff is
@@ -126,7 +126,7 @@ _39 = MEM[(struct _Vector_base *)m_3(D)
  from bb 11 to bb 12
 Sinking _26 = _20 - _18;
  from bb 5 to bb 6
-__attribute__((optimize ("assume-sane-operators-new-delete"), noipa, noinline,
noclone, no_icf))
+__attribute__((optimize ("no-assume-sane-operators-new-delete"), noipa,
noinline, noclone, no_icf))
 bool foo (struct C * m, struct A * e)
 {
   bool c;
@@ -344,8 +344,8 @@ _115 = e._M_impl.D.36905._M_end_of_stora
  from bb 8 to bb 9
 int main ()
 {
-  unsigned long SR.171;
-  unsigned long SR.170;
+  unsigned long SR.173;
+  unsigned long SR.172;
   struct A e;
   const double D.40760[1];
   struct A D.40763;
but dse3 adds to that
@@ -125,6 +125,9 @@ bool foo (struct C * m, struct A * e)
   MEM[(struct _Vector_impl_data *)e_4(D)]._M_finish = _22;
   _23 = MEM[(const struct _Vector_impl_data &)m_3(D) + 8]._M_end_of_storage;
   MEM[(struct _Vector_impl_data *)e_4(D)]._M_end_of_storage = _23;
+  MEM[(struct _Vector_impl_data *)m_3(D) + 8B]._M_start = 0B;
+  MEM[(struct _Vector_impl_data *)m_3(D) + 8B]._M_finish = 0B;
+  MEM[(struct _Vector_impl_data *)m_3(D) + 8B]._M_end_of_storage = 0B;
   if (_18 != 0B)
     goto <bb 6>; [53.47%]
   else

Reply via email to