From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678891068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tcOHGrHucSzBEQS88/1DoqiCk6SzNCc378ELFlcw+q0=; b=hD7aQsjH70DfQ+5Fa9eNJ2wEfwYEJB9UdgYWliLtqrr2cuGmmuMQiJT8BnBSKKYdkp76Oh uocsCVrQbC7G0ZRKhg35SvgEUeOekPODE5l4suCuBZdA7wgstPyrhoE5cb/FgK9T5YM1xE cKMbYX2TptiI3MtwBYQYNx4+hw4s9eM= 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 From: Marek Polacek 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-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 List-Id: 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 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), ""); base-commit: 40c1352c5a4530350012d6a922435cf491663daa -- 2.39.2