public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101663] New: GCC crashes when assigning one single_view to another.
@ 2021-07-28 22:09 gcc at zoecarver dot com
  2021-08-03 12:35 ` [Bug c++/101663] " marxin at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gcc at zoecarver dot com @ 2021-07-28 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101663
           Summary: GCC crashes when assigning one single_view to another.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at zoecarver dot com
  Target Milestone: ---

GCC trunk seems to crash because of a constexpr issue when assigning two single
views with non-assignable types. 

Here's a godbolt: https://tinyurl.com/2edutprj

Here's a sample program:

```
#include <ranges>
#include <cassert>

struct NotAssignable {
  NotAssignable() = default;
  NotAssignable(const NotAssignable&) = default;
  NotAssignable(NotAssignable&&) = default;

  NotAssignable& operator=(const NotAssignable&) = delete;
  NotAssignable& operator=(NotAssignable&&) = delete;
};

constexpr bool test() {
  const std::ranges::single_view<NotAssignable> a;
  std::ranges::single_view<NotAssignable> b;
  b = a;
  b = std::move(a);

  return true;
}

int main(int, char**) {
  test();
  static_assert(test());

  return 0;
}
```

I suspect this is because of optional/copyable box weirdness during constexpr
evaluation. 

I noticed this bug when implementing single_view for libc++. The interesting
part is that this happens with both libstdc++ and libc++. That might help
narrow down the reproducer.

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

* [Bug c++/101663] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
@ 2021-08-03 12:35 ` marxin at gcc dot gnu.org
  2021-08-03 14:29 ` [Bug c++/101663] [11/12 Regression] " ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-03 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-03
             Status|UNCONFIRMED                 |NEW
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Likely started with r12-1606-g4b4f5666b4c2f3aa.

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

* [Bug c++/101663] [11/12 Regression] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
  2021-08-03 12:35 ` [Bug c++/101663] " marxin at gcc dot gnu.org
@ 2021-08-03 14:29 ` ppalka at gcc dot gnu.org
  2021-08-03 16:35 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-03 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |10.3.0
      Known to fail|                            |10.1.0, 10.2.0, 11.1.0,
                   |                            |11.2.0, 12.0
   Target Milestone|---                         |11.3
            Summary|GCC crashes when assigning  |[11/12 Regression] GCC
                   |one single_view to another. |crashes when assigning one
                   |                            |single_view to another.
           Keywords|                            |ice-on-valid-code

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced ICE-on-valid testcase:

#include <bits/stl_construct.h> // for std::construct_at

template <typename _Tp> struct __box {
  [[no_unique_address]] _Tp _M_value;
};

struct Empty { };

constexpr bool test() {
  __box<Empty> a;
  std::construct_at(&a._M_value);
  return true;
}

static_assert(test());


We went from rejecting to accepting this testcase with r11-3581 (which was also
backported to GCC 10.3).  We later went from accepting to ICEing with r11-6918.

So I suppose this is an 11/12 regression given that GCC 10.3 accepts the
testcase.

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

* [Bug c++/101663] [11/12 Regression] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
  2021-08-03 12:35 ` [Bug c++/101663] " marxin at gcc dot gnu.org
  2021-08-03 14:29 ` [Bug c++/101663] [11/12 Regression] " ppalka at gcc dot gnu.org
@ 2021-08-03 16:35 ` ppalka at gcc dot gnu.org
  2021-08-12  1:01 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-03 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

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

* [Bug c++/101663] [11/12 Regression] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
                   ` (2 preceding siblings ...)
  2021-08-03 16:35 ` ppalka at gcc dot gnu.org
@ 2021-08-12  1:01 ` cvs-commit at gcc dot gnu.org
  2021-08-12 12:18 ` cvs-commit at gcc dot gnu.org
  2021-08-12 12:20 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-12  1:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:21fd62e5ca9967bba8f97fd6244a8c6a564c2146

commit r12-2868-g21fd62e5ca9967bba8f97fd6244a8c6a564c2146
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 11 20:59:53 2021 -0400

    c++: constexpr std::construct_at on empty field [PR101663]

    Here during constexpr evaluation of

      std::construct_at(&a._M_value)

    we find ourselves in cxx_eval_store_expression where the target object
    is 'a._M_value' and the initializer is {}.  Since _M_value is an empty
    [[no_unique_address]] member we don't create a sub-CONSTRUCTOR for it,
    so we end up in the early exit code path for empty stores with mismatched
    types and trip over the assert therein

      gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval);

    because lval is true.  The reason it's true is because the INIT_EXPR in
    question is the LHS of a COMPOUND_EXPR, and evaluation of the LHS is
    always performed with lval=true (to indicate there's no lvalue-to-rvalue
    conversion).

    This patch makes the code path in question handle the lval=true case
    appropriately rather than asserting.  In passing, it also consolidates
    the duplicate implementations of std::construct_at/destroy_at in some
    of the C++20 constexpr tests into a common header file.

            PR c++/101663

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_store_expression): Handle the lval=true
            case in the early exit code path for empty stores with mismatched
            types.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/construct_at.h: New convenience header file that
            defines minimal implementations of std::construct_at/destroy_at,
            split out from ...
            * g++.dg/cpp2a/constexpr-new5.C: ... here.
            * g++.dg/cpp2a/constexpr-new6.C: Use the header.
            * g++.dg/cpp2a/constexpr-new14.C: Likewise.
            * g++.dg/cpp2a/constexpr-new20.C: New test.

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

* [Bug c++/101663] [11/12 Regression] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
                   ` (3 preceding siblings ...)
  2021-08-12  1:01 ` cvs-commit at gcc dot gnu.org
@ 2021-08-12 12:18 ` cvs-commit at gcc dot gnu.org
  2021-08-12 12:20 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-12 12:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:f65ae298d43b2dd280b6f3761d6f3ea8e572be61

commit r11-8857-gf65ae298d43b2dd280b6f3761d6f3ea8e572be61
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 11 20:59:53 2021 -0400

    c++: constexpr std::construct_at on empty field [PR101663]

    Here during constexpr evaluation of

      std::construct_at(&a._M_value)

    we find ourselves in cxx_eval_store_expression where the target object
    is 'a._M_value' and the initializer is {}.  Since _M_value is an empty
    [[no_unique_address]] member we don't create a sub-CONSTRUCTOR for it,
    so we end up in the early exit code path for empty stores with mismatched
    types and trip over the assert therein

      gcc_assert (is_empty_class (TREE_TYPE (init)) && !lval);

    because lval is true.  The reason it's true is because the INIT_EXPR in
    question is the LHS of a COMPOUND_EXPR, and evaluation of the LHS is
    always performed with lval=true (to indicate there's no lvalue-to-rvalue
    conversion).

    This patch makes the code path in question handle the lval=true case
    appropriately rather than asserting.  In passing, it also consolidates
    the duplicate implementations of std::construct_at/destroy_at in some
    of the C++20 constexpr tests into a common header file.

            PR c++/101663

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_store_expression): Handle the lval=true
            case in the early exit code path for empty stores with mismatched
            types.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/construct_at.h: New convenience header file that
            defines minimal implementations of std::construct_at/destroy_at,
            split out from ...
            * g++.dg/cpp2a/constexpr-new5.C: ... here.
            * g++.dg/cpp2a/constexpr-new6.C: Use the header.
            * g++.dg/cpp2a/constexpr-new14.C: Likewise.
            * g++.dg/cpp2a/constexpr-new20.C: New test.

    (cherry picked from commit 21fd62e5ca9967bba8f97fd6244a8c6a564c2146)

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

* [Bug c++/101663] [11/12 Regression] GCC crashes when assigning one single_view to another.
  2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
                   ` (4 preceding siblings ...)
  2021-08-12 12:18 ` cvs-commit at gcc dot gnu.org
@ 2021-08-12 12:20 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-12 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.3 and 12.

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

end of thread, other threads:[~2021-08-12 12:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28 22:09 [Bug c++/101663] New: GCC crashes when assigning one single_view to another gcc at zoecarver dot com
2021-08-03 12:35 ` [Bug c++/101663] " marxin at gcc dot gnu.org
2021-08-03 14:29 ` [Bug c++/101663] [11/12 Regression] " ppalka at gcc dot gnu.org
2021-08-03 16:35 ` ppalka at gcc dot gnu.org
2021-08-12  1:01 ` cvs-commit at gcc dot gnu.org
2021-08-12 12:18 ` cvs-commit at gcc dot gnu.org
2021-08-12 12:20 ` ppalka 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).