From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: ICE with constexpr lambda [PR107280]
Date: Fri, 10 Mar 2023 11:17:13 -0500 [thread overview]
Message-ID: <20230310161713.124368-1-polacek@redhat.com> (raw)
We crash here since r10-3661, the store_init_value hunk in particular.
Before, we called cp_fully_fold_init, so e.g.
{.str=VIEW_CONVERT_EXPR<char[8]>("")}
was folded into
{.str=""}
but now we don't fold and keep the VCE around, and it causes trouble in
cxx_eval_store_expression: in the !refs->is_empty () loop we descend on
.str's initializer but since it's wrapped in a VCE, we skip the STRING_CST
check and then crash on the CONSTRUCTOR_NO_CLEARING.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12?
PR c++/107280
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_store_expression): Strip location wrappers.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1z/constexpr-lambda28.C: New test.
---
gcc/cp/constexpr.cc | 3 ++-
gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 8683c00596a..abf6ee560c5 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -6033,7 +6033,8 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,
*valp = build_constructor (type, NULL);
CONSTRUCTOR_NO_CLEARING (*valp) = no_zero_init;
}
- else if (TREE_CODE (*valp) == STRING_CST)
+ else if (STRIP_ANY_LOCATION_WRAPPER (*valp),
+ TREE_CODE (*valp) == STRING_CST)
{
/* An array was initialized with a string constant, and now
we're writing into one of its elements. Explode the
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
new file mode 100644
index 00000000000..aafbfddd8b9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C
@@ -0,0 +1,15 @@
+// PR c++/107280
+// { dg-do compile { target c++17 } }
+
+struct string {
+ char str[8] = "";
+};
+template <int, int> constexpr void
+test ()
+{
+ string str{};
+ auto append = [&](const char *s) { *str.str = *s; };
+ append("");
+}
+
+static_assert ((test<true, true>(), true), "");
base-commit: 2b2340e236c0bba8aaca358ea25a5accd8249fbd
--
2.39.2
next reply other threads:[~2023-03-10 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 16:17 Marek Polacek [this message]
2023-03-10 18:47 ` Jason Merrill
2023-03-15 14:37 ` [PATCH v2] " Marek Polacek
2023-03-15 16:48 ` Jason Merrill
2023-03-15 18:20 ` Marek Polacek
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=20230310161713.124368-1-polacek@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/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).