Message ID | ZBHYLmBGhgu3QDRa@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 01708385841C for <patchwork@sourceware.org>; Wed, 15 Mar 2023 14:38:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01708385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678891106; 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=Q4bwTaaTUw17V9W1/BWDt3LPlVW1vNCSs1srE+ZfK/fxZt+KAR1n0hhADLp9Djmvn ljNjGd/FPhW8P8XuDeNYiC13nwlkbswbucPB3xM6POrpU2W4iazOdHgCzHp7e7HSUR xBwqf7NImHJ4nTc6WaTZAF+ZJj1T+n36WkKJdYlE= 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <jason@redhat.com> Cc: GCC Patches <gcc-patches@gcc.gnu.org> Subject: [PATCH v2] c++: ICE with constexpr lambda [PR107280] Message-ID: <ZBHYLmBGhgu3QDRa@redhat.com> 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-Type: text/plain; charset=us-ascii 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Marek Polacek <polacek@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[v2] c++: ICE with constexpr lambda [PR107280]
|
|
Commit Message
Marek Polacek
March 15, 2023, 2:37 p.m. UTC
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<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. 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<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. 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
Comments
On 3/15/23 10:37, Marek Polacek wrote: > 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<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. > > 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? I guess I was thinking more around the time when the value is imported into constant evaluation, i.e. this chunk of cxx_eval_constant_expression: > if (tree init = DECL_INITIAL (r)) > { > init = cxx_eval_constant_expression (ctx, init, vc_prvalue, > non_constant_p, overflow_p); > /* Don't share a CONSTRUCTOR that might be changed. */ > init = unshare_constructor (init); > /* Remember that a constant object's constructor has already > run. */ > if (CLASS_TYPE_P (TREE_TYPE (r)) > && CP_TYPE_CONST_P (TREE_TYPE (r))) > TREE_READONLY (init) = true; > ctx->global->put_value (r, init); > } Feel free to pursue that approach or go ahead and push your first patch, whichever you prefer. Jason
On Wed, Mar 15, 2023 at 12:48:27PM -0400, Jason Merrill wrote: > On 3/15/23 10:37, Marek Polacek wrote: > > 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<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. > > > > 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? > > I guess I was thinking more around the time when the value is imported into > constant evaluation, i.e. this chunk of cxx_eval_constant_expression: > > > if (tree init = DECL_INITIAL (r)) > > { > > init = cxx_eval_constant_expression (ctx, init, vc_prvalue, > > non_constant_p, overflow_p); > > /* Don't share a CONSTRUCTOR that might be changed. */ > > init = unshare_constructor (init); > > /* Remember that a constant object's constructor has already > > run. */ > > if (CLASS_TYPE_P (TREE_TYPE (r)) > > && CP_TYPE_CONST_P (TREE_TYPE (r))) > > TREE_READONLY (init) = true; > > ctx->global->put_value (r, init); > > } Ah, that wouldn't fix the problem as far as I can tell -- here init is the whole constructor: {.str=VIEW_CONVERT_EXPR<char[8]>("")} so we'd not have a way to strip the inner init. > Feel free to pursue that approach or go ahead and push your first patch, > whichever you prefer. The original patch it is, then. Thanks. Marek
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 <int, int> constexpr void +test () +{ + string str{}; + auto append = [&](const char *s) { *str.str = *s; }; + append(""); +} + +static_assert ((test<true, true>(), true), "");