On 3/10/23 11:17, Marek Polacek wrote:
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)

Seems like this is stripping the location wrapper when we try to modify the string; I think we want to strip it earlier, when we first initialize the array member.

Jason

Reply via email to