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

--- Comment #2 from Dan Klishch <daklishch at gmail dot com> ---
GCC incorrectly gimplifies the program. The code that is causing the warning is
in the coroutine's actor function:
              try
                {
                  D.9829 = &frame_ptr->__p;
                  .UBSAN_NULL (D.9829, 4B, 0);
                  coro::promise_type::return_void (D.9829);
                  goto final.suspend;
                }
              finally
                {
                  .UBSAN_NULL (D.9828, 4B, 0); // here
                  a::~a (D.9828);
                }
Obviously, an assignment to D.9828 is missing. However, a little bit earlier a
similar destruction of `struct a' is handled correctly:
                      try
                        {
                          b::~b (&D.9562);
                        }
                      catch
                        {
                          D.9828 = &frame_ptr->__obj.2.3;
                          .UBSAN_NULL (D.9828, 4B, 0);
                          a::~a (D.9828);
                        }

I guess one of this destructor calls is a copy of another and this might be the
root of the problem. After ubsan instrumentation the call to the destructor
looks like this:
        a::~a (.UBSAN_NULL (SAVE_EXPR <&frame_ptr->__obj.2.3>, 4B, 0);,
SAVE_EXPR <&frame_ptr->__obj.2.3>;);

I believe the same SAVE_EXPR is copied to the second invocation of the
destructor but the enclosed expression evaluation is placed only before the
first use of SAVE_EXPR and the control flow does not reach it before a call to
the actual (second) destructor.

I guess this can be fixed by instrumenting the calls to the destructors using
temporary variable and not SAVE_EXPR, like this:
  void *ptr = &frame_ptr->__obj.2.3;
  .UBSAN_NULL (ptr, 4B, 0);
  a::~a (ptr);

But I don't have a solid understanding of GCC internals, so I'm not sure if it
is right.

Reply via email to