public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/101371] [9/10/11 Regression] constexpr expansions trigger internal Compiler Error
Date: Tue, 29 Mar 2022 01:44:19 +0000	[thread overview]
Message-ID: <bug-101371-4-9gQMGSSoa9@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101371-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

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

commit r11-9710-gda47a84e277c7fbeebbf9c1e7dc1e8ba3277fe53
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jul 13 17:16:54 2021 -0400

    c++: constexpr array reference and value-initialization [PR101371]

    This PR gave me a hard time: I saw multiple issues starting with
    different revisions.  But ultimately the root cause seems to be
    the following, and the attached patch fixes all issues I've found
    here.

    In cxx_eval_array_reference we create a new constexpr context for the
    CP_AGGREGATE_TYPE_P case, but we also have to create it for the
    non-aggregate case.  In this test, we are evaluating

      ((B *)this)->a = rhs->a

    which means that we set ctx.object to ((B *)this)->a.  Then we proceed
    to evaluate the initializer, rhs->a.  For *rhs, we eval rhs, a PARM_DECL,
    for which we have (const B &) &c.arr[0] in the hash table.  Then
    cxx_fold_indirect_ref gives us c.arr[0].  c is evaluated to {.arr={}} so
    c.arr is {}.  Now we want c.arr[0], so we end up in
cxx_eval_array_reference
    and since we're initializing from {}, we call build_value_init which
    gives us an AGGR_INIT_EXPR that calls 'constexpr B::B()'.  Then we
    evaluate this AGGR_INIT_EXPR and since its first argument is dummy,
    we take ctx.object instead.  But that is the wrong object, we're not
    initializing ((B *)this)->a here.  And so we wound up with an
    initializer for A, and then crash in cxx_eval_component_reference:

      gcc_assert (DECL_CONTEXT (part) == TYPE_MAIN_VARIANT (TREE_TYPE
(whole)));

    where DECL_CONTEXT (part) is B (as it should be) but the type of whole
    was A.

    So create a new object, if there already was one, and the element type
    is not a scalar.

            PR c++/101371

    gcc/cp/ChangeLog:

            * constexpr.c (cxx_eval_array_reference): Create a new .object
            and .ctor for the non-aggregate non-scalar case too when
            value-initializing.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/constexpr-101371-2.C: New test.
            * g++.dg/cpp1y/constexpr-101371.C: New test.

    (cherry picked from commit a42f8120442cf3ba25d621bed857b5be19019d0c)

  parent reply	other threads:[~2022-03-29  1:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08  5:44 [Bug c++/101371] New: " warren_graeme at yahoo dot co.uk
2021-07-08  7:42 ` [Bug c++/101371] " rguenth at gcc dot gnu.org
2021-07-08 13:50 ` mpolacek at gcc dot gnu.org
2021-07-08 14:30 ` mpolacek at gcc dot gnu.org
2021-07-09  0:33 ` mpolacek at gcc dot gnu.org
2021-07-09  0:38 ` [Bug c++/101371] [9/10/11/12 Regression] " mpolacek at gcc dot gnu.org
2021-07-09  0:38 ` mpolacek at gcc dot gnu.org
2021-07-10  2:40 ` mpolacek at gcc dot gnu.org
2021-07-14 15:56 ` [Bug c++/101371] [9/10/11 " mpolacek at gcc dot gnu.org
2022-03-29  1:44 ` cvs-commit at gcc dot gnu.org [this message]
2022-03-29  1:47 ` [Bug c++/101371] [9/10 " mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101371-4-9gQMGSSoa9@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).