From patchwork Fri Mar 10 16:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 66233 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03489385840E for ; Fri, 10 Mar 2023 16:18:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03489385840E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678465085; bh=RYS/STOTRSud9tUN47l6/hN/GGfZMrJ1AVMp6I8GgRo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=w3hP1d469g2Fh2AhTC55nZoYoFIKoZATLUlt5+hOaUwIX7s3BbEzQsQ+qgI38Npr8 DmwO9tdSxDpSZOyL1+oOHkr8YLY9wymYj8PltPfhI4xzVTH2vBUe/tT7eXT9RVv2Ui rIisBIC5RVqDlmXpjDsM8qoFgoDA0kjsTbA064HQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 91CF13858D38 for ; Fri, 10 Mar 2023 16:17:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 91CF13858D38 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-529-2I3q4Y8nPWWDdLFEeiNc-A-1; Fri, 10 Mar 2023 11:17:16 -0500 X-MC-Unique: 2I3q4Y8nPWWDdLFEeiNc-A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 525163C0E469 for ; Fri, 10 Mar 2023 16:17:16 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.9.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 365332166B26; Fri, 10 Mar 2023 16:17:16 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: ICE with constexpr lambda [PR107280] Date: Fri, 10 Mar 2023 11:17:13 -0500 Message-Id: <20230310161713.124368-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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("")} 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 base-commit: 2b2340e236c0bba8aaca358ea25a5accd8249fbd 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 constexpr void +test () +{ + string str{}; + auto append = [&](const char *s) { *str.str = *s; }; + append(""); +} + +static_assert ((test(), true), "");