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

            Bug ID: 105683
           Summary: [12 Regression] Infinite loop with construction of
                    vector of variant
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeanmichael.celerier at gmail dot com
  Target Milestone: ---

Created attachment 53012
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53012&action=edit
Full repro

Hello,

Full repro attached (g++ -std=gnu++20 repro.cpp && ./a.out is enough to trigger
the issue).
Same code works fine for every GCC version < 12 in c++17, c++20, as well as
with every released clang version in c++17, c++20, with both libc++ and
libstdc++.

My code more-or-less looks like this (trying to keep only the relevant parts):



    // line 58584
    struct value_variant_type {
      union Impl { std::vector<ossia::value> m_value8; } m_impl;

      value_variant_type(const std::vector<ossia::value>& v); 
      value_variant_type(std::vector<ossia::value>&& v);
    };


    // line 58681
    class value {
      value_variant_type v;
      value(const std::vector<ossia::value>& val) noexcept : v{val}
      {
      }
      explicit value(std::vector<ossia::value>&& val) noexcept :
v{std::move(val)}
      {
      }
    };



    // line 75925
    inline value_variant_type::value_variant_type(const
std::vector<ossia::value>& v) : m_type{Type8}
    {
      new (&m_impl.m_value8) std::vector<ossia::value>(v);
    }

    inline value_variant_type::value_variant_type(std::vector<ossia::value>&&
v) : m_type{Type8}
    {
      new (&m_impl.m_value8) std::vector<ossia::value>(std::move(v));
    }




    // line 58916
    inline ossia::value init_value(ossia::val_type type)
    {
      return std::vector<ossia::value>{};
    }



    // line 76232
    void create_value_inline(ossia::value& v, ossia::val_type t) {
      v = ossia::init_value(t);
    }

    int main()
    {
        ossia::value v;
        create_value_inline(v, ossia::val_type::LIST);
    }


What it looks that is happening is a loop between the construction of the value
and of the vector: 


    #1822 0x00005555555587b7 in ossia::value::value (other=...,
this=0x555555abff10)
    at
/home/jcelerier/ossia/score/3rdparty/libossia/src/ossia/network/value/value.hpp:302
    #1823 std::_Construct<ossia::value, ossia::value const&>
(__p=0x555555abff10) at /usr/include/c++/12.1.0/bits/stl_construct.h:119
    #1824 std::__do_uninit_copy<ossia::value const*, ossia::value*>
(__result=<optimized out>, __last=<optimized out>, __first=0x7fffff802a50)
    at /usr/include/c++/12.1.0/bits/stl_uninitialized.h:120
    #1825 std::__uninitialized_copy<false>::__uninit_copy<ossia::value const*,
ossia::value*> (__result=<optimized out>, __last=<optimized out>, 
    __first=<optimized out>) at
/usr/include/c++/12.1.0/bits/stl_uninitialized.h:137
    #1826 std::uninitialized_copy<ossia::value const*, ossia::value*>
(__result=<optimized out>, __last=<optimized out>, __first=<optimized out>)
    at /usr/include/c++/12.1.0/bits/stl_uninitialized.h:185
    #1827 std::__uninitialized_copy_a<ossia::value const*, ossia::value*,
ossia::value> (__result=0x555555abff10, __last=0x7fffff802a78,
__first=0x7fffff802a50)
    at /usr/include/c++/12.1.0/bits/stl_uninitialized.h:372
    #1828 std::vector<ossia::value, std::allocator<ossia::value>
>::_M_range_initialize<ossia::value const*> (__last=0x7fffff802a78,
__first=0x7fffff802a50, 
    this=0x555555abfee0) at /usr/include/c++/12.1.0/bits/stl_vector.h:1690
    #1829 std::vector<ossia::value, std::allocator<ossia::value> >::vector
(__a=..., Python Exception <class 'gdb.error'>: value has been optimized out
    __l=, this=0x555555abfee0) at /usr/include/c++/12.1.0/bits/stl_vector.h:677
    #1830 ossia::value_variant_type::value_variant_type (other=...,
this=0x555555abfee0)
    at
/home/jcelerier/ossia/score/3rdparty/libossia/src/ossia/network/value/value_variant_impl.hpp:17017
    #1831 ossia::value::value (other=..., this=0x555555abfee0) at
/home/jcelerier/ossia/score/3rdparty/libossia/src/ossia/network/value/value.hpp:302

Reply via email to