From patchwork Wed Mar 15 14:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1757393 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LYvXRcmL; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PcCgJ3X0Xz246q for ; Thu, 16 Mar 2023 01:38:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0418A3858C83 for ; Wed, 15 Mar 2023 14:38:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0418A3858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678891097; bh=tcOHGrHucSzBEQS88/1DoqiCk6SzNCc378ELFlcw+q0=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=LYvXRcmLFzvChchq886/wFBnjtsbhqU5vzOhdzp5XEhgNKKlV/zpJdCN05Jg/X1FY IqTQjPm0mh2Pb1rnUD8vOvA7iM/Kfxl3yxynP40OiPa6R2Z3MrgE4wR2MBUF6Qsb1i lyFHuSkd8abxMzmC4ZZlH1rxiJPMVuLzj7VswYGU= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 80A513858D39 for ; Wed, 15 Mar 2023 14:37:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80A513858D39 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-92CQaijJNk2UnDTF5BLU9A-1; Wed, 15 Mar 2023 10:37:38 -0400 X-MC-Unique: 92CQaijJNk2UnDTF5BLU9A-1 Received: by mail-qt1-f200.google.com with SMTP id t22-20020ac86a16000000b003bd1c0f74cfso8472580qtr.20 for ; Wed, 15 Mar 2023 07:37:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678891057; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tcOHGrHucSzBEQS88/1DoqiCk6SzNCc378ELFlcw+q0=; b=bQSzILumpIRQo1NM6pQ2wBXLk/8C2eIi+VMijlDWuWIa6Cly24ssQKhNh2hFo1I/uj /65wAegsx64V25CLuAEqiMHcC0ajRDq91MzeF1kw8eWvBccQUZo0dsdcFPHD8BUHr7q2 FaA6yFSl7i17UPaFkPIaTFvstuAsTulOiaxApiBAyLRDO3iIutr+uBI/S6nAJXAJFih5 t7ytiUKCx+jsKMJxTAV7LjqMBPG5vYoHTRtpi2rJw0wOg+Cj6QIaIFkp/QnmTJx5Kbzo zKqMQZtpy3YOBAJc255tYxKiwqcrlf07fEAmGoQHi/w2QpH/3KCbb5WmbuzAhgwJWr/H YPTA== X-Gm-Message-State: AO0yUKUJ58HWt3kiqqqx5xCjvPuCXKSjvupzqtPYNQhc3wxIT2ucnKQI 1sXfZMADiAg1aH0D+0Hty1aIGi+XJHoz1rQEpgSchdirtVRnP5fHQnbsgtK2nLyG6i7IKqq0rL9 QBpmw9vz9lZIOTw/Rwg== X-Received: by 2002:a05:622a:11c8:b0:3bf:d8b6:4cc7 with SMTP id n8-20020a05622a11c800b003bfd8b64cc7mr70383296qtk.58.1678891057617; Wed, 15 Mar 2023 07:37:37 -0700 (PDT) X-Google-Smtp-Source: AK7set/EJy7HvDXO9GQCLnGOLHoh4t45AG+p5oNSTrbvQmq0O+DxrqlpGfhtepWz45BsQ2y4t+zVwQ== X-Received: by 2002:a05:622a:11c8:b0:3bf:d8b6:4cc7 with SMTP id n8-20020a05622a11c800b003bfd8b64cc7mr70383267qtk.58.1678891057308; Wed, 15 Mar 2023 07:37:37 -0700 (PDT) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id n188-20020a3740c5000000b00743a0096e8csm3824090qka.39.2023.03.15.07.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 07:37:36 -0700 (PDT) Date: Wed, 15 Mar 2023 10:37:34 -0400 To: Jason Merrill Cc: GCC Patches Subject: [PATCH v2] c++: ICE with constexpr lambda [PR107280] Message-ID: References: <20230310161713.124368-1-polacek@redhat.com> <3e280de2-3d3c-154e-2833-15cd85d0bcf9@redhat.com> MIME-Version: 1.0 In-Reply-To: <3e280de2-3d3c-154e-2833-15cd85d0bcf9@redhat.com> User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" On Fri, Mar 10, 2023 at 01:47:46PM -0500, Jason Merrill wrote: > 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("")} > > > > 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. Hmm, I suppose we don't want to do the stripping too early. I could have put it in get_nsdmi, for instance, but maybe here is good as well? Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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. PR c++/107280 gcc/cp/ChangeLog: * typeck2.cc (process_init_constructor_record): Strip location wrappers. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-lambda28.C: New test. --- gcc/cp/typeck2.cc | 1 + gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-lambda28.C base-commit: 40c1352c5a4530350012d6a922435cf491663daa diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index c56b69164e2..d0984910ce4 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -1889,6 +1889,7 @@ process_init_constructor_record (tree type, tree init, int nested, int flags, CONSTRUCTOR_PLACEHOLDER_BOUNDARY (init) = 1; CONSTRUCTOR_PLACEHOLDER_BOUNDARY (next) = 0; } + STRIP_ANY_LOCATION_WRAPPER (next); CONSTRUCTOR_APPEND_ELT (v, field, next); } 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), "");