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.129.124]) by sourceware.org (Postfix) with ESMTPS id 36FF23858CD1 for ; Thu, 20 Jul 2023 19:51:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36FF23858CD1 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=1689882696; 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=uimUjlxxcJzFQoRwZkUbGqS/EZE+nt1w+/jmvfSajPs=; b=ZYtCAz91rANISgeuoXr/ryQja8nkUV3nS63bp+1F9r2GE2lCRYnzQRsguLfPsCx+2tHG+6 L0et1nTS38eOTzJpZGG+Tx+RebsrIUeMd4sy6znlDzQfZvakVnWx6eRYIijBx9PGB4GKFy rOc/w6Xy6xDLHzUss/hcReqeiACcMhc= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-er7TpuVbPPa9dS5Dxt_8Pw-1; Thu, 20 Jul 2023 15:51:35 -0400 X-MC-Unique: er7TpuVbPPa9dS5Dxt_8Pw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-63ccbef84eeso12736136d6.3 for ; Thu, 20 Jul 2023 12:51:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689882695; x=1690487495; 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=uimUjlxxcJzFQoRwZkUbGqS/EZE+nt1w+/jmvfSajPs=; b=RPBgTKj+TnPK5IR2puE4w1e6dWOqiZ3VvUDgfWdrFilx1y1kNO3zjgC+OMnZ319/w9 yHwTMvwL2sIHksssZ3v91iINtHFzVdAdGHKQUw56x52Aw3qqZnyG7tgvTwH0uuMAuSTW LA9zKQ+mBeCcVxeUng8H1JlEbthyulu48GUp4RZ3dI03SB8gpdYNQEyZxau0wzInXMrD 5MmyAr6KubssxZkR1y4vFh4dppowmtzANZU93W2hi58F5PI786aeIUJHfh0FoN10JCaV m5oV74QtzBxaFox02u3jKdKr//46xJOVoe9r4CkZIEDljTf2SP/QGyPk3RfE5NjCwCW1 NLIg== X-Gm-Message-State: ABy/qLZ3fN0RBLPZ2psNiWDWAV1nLlvm7Wu+mY+v8Bfvndo7wVJLvG8p lsjKwlBHCS83kuj4g9ud7Ie15pGu9wI8kaeXL02euToLu2dy32ZEHzc7PJfp4gQ73EAJHkUl6OE /kYIcflCcMiMZgvjgWw== X-Received: by 2002:a0c:b257:0:b0:63c:627b:9ac6 with SMTP id k23-20020a0cb257000000b0063c627b9ac6mr38456qve.59.1689882694739; Thu, 20 Jul 2023 12:51:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlErGhuV9kkNXafLVJed8GBxIqjWgMc/UrAZgopy2LnTGK6JWKgCX/EEacQHPA0rJuxXzYgjiQ== X-Received: by 2002:a0c:b257:0:b0:63c:627b:9ac6 with SMTP id k23-20020a0cb257000000b0063c627b9ac6mr38444qve.59.1689882694404; Thu, 20 Jul 2023 12:51:34 -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 i10-20020a0cf10a000000b006301ec0d16fsm703233qvl.0.2023.07.20.12.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 12:51:33 -0700 (PDT) Date: Thu, 20 Jul 2023 15:51:32 -0400 From: Marek Polacek To: Jason Merrill Cc: Patrick Palka , GCC Patches Subject: Re: [PATCH] c++: fix ICE with is_really_empty_class [PR110106] Message-ID: References: <20230718211458.858343-1-polacek@redhat.com> <7007162f-c356-cbde-575e-1cbbd545323d@idea> <03d798a6-0951-1d11-5ae4-476e85f5636e@redhat.com> MIME-Version: 1.0 In-Reply-To: <03d798a6-0951-1d11-5ae4-476e85f5636e@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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 Thu, Jul 20, 2023 at 02:37:07PM -0400, Jason Merrill wrote: > On 7/20/23 14:13, Marek Polacek wrote: > > On Wed, Jul 19, 2023 at 10:11:27AM -0400, Patrick Palka wrote: > > > On Tue, 18 Jul 2023, Marek Polacek via Gcc-patches wrote: > > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk and branches? > > > > > > Looks reasonable to me. > > > > Thanks. > > > Though I wonder if we could also fix this by not checking potentiality > > > at all in this case? The problematic call to is_rvalue_constant_expression > > > happens from cp_parser_constant_expression with 'allow_non_constant' != 0 > > > and with 'non_constant_p' being a dummy out argument that comes from > > > cp_parser_functional_cast, so the result of is_rvalue_constant_expression > > > is effectively unused in this case, and we should be able to safely elide > > > it when 'allow_non_constant && non_constant_p == nullptr'. > > > > Sounds plausible. I think my patch could be applied first since it > > removes a tiny bit of code, then I can hopefully remove the flag below, > > then maybe go back and optimize the call to is_rvalue_constant_expression. > > Does that sound sensible? > > > > > Relatedly, ISTM the member cp_parser::non_integral_constant_expression_p > > > is also effectively unused and could be removed? > > > > It looks that way. Seems it's only used in cp_parser_constant_expression: > > 10806 if (allow_non_constant_p) > > 10807 *non_constant_p = parser->non_integral_constant_expression_p; > > but that could be easily replaced by a local var. I'd be happy to see if > > we can actually do away with it. (I wonder why it was introduced and when > > it actually stopped being useful.) > > It was for the C++98 notion of constant-expression, which was more of a > parser-level notion, and has been supplanted by the C++11 version. I'm > happy to remove it, and therefore remove the is_rvalue_constant_expression > call. Wonderful. I'll do that next. > > > > -- >8 -- > > > > > > > > is_really_empty_class is liable to crash when it gets an incomplete > > > > or dependent type. Since r11-557, we pass the yet-uninstantiated > > > > class type S<0> of the PARM_DECL s to is_really_empty_class -- because > > > > of the potential_rvalue_constant_expression -> is_rvalue_constant_expression > > > > change in cp_parser_constant_expression. Here we're not parsing > > > > a template so we did not check COMPLETE_TYPE_P as we should. > > > > > > > > PR c++/110106 > > > > > > > > gcc/cp/ChangeLog: > > > > > > > > * constexpr.cc (potential_constant_expression_1): Check COMPLETE_TYPE_P > > > > even when !processing_template_decl. > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > * g++.dg/cpp0x/noexcept80.C: New test. > > > > --- > > > > gcc/cp/constexpr.cc | 2 +- > > > > gcc/testsuite/g++.dg/cpp0x/noexcept80.C | 12 ++++++++++++ > > > > 2 files changed, 13 insertions(+), 1 deletion(-) > > > > create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept80.C > > > > > > > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > > > > index 6e8f1c2b61e..1f59c5472fb 100644 > > > > --- a/gcc/cp/constexpr.cc > > > > +++ b/gcc/cp/constexpr.cc > > > > @@ -9116,7 +9116,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, > > > > if (now && want_rval) > > > > { > > > > tree type = TREE_TYPE (t); > > > > - if ((processing_template_decl && !COMPLETE_TYPE_P (type)) > > > > + if (!COMPLETE_TYPE_P (type) > > > > || dependent_type_p (type) > > There shouldn't be a problem completing the type here, so it seems to me > that we're missing a call to complete_type_p, at least when > !processing_template_decl. Probably need to move the dependent_type_p check > up as a result. Like so? Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- is_really_empty_class is liable to crash when it gets an incomplete or dependent type. Since r11-557, we pass the yet-uninstantiated class type S<0> of the PARM_DECL s to is_really_empty_class -- because of the potential_rvalue_constant_expression -> is_rvalue_constant_expression change in cp_parser_constant_expression. Here we're not parsing a template so we did not check COMPLETE_TYPE_P as we should. It should work to complete the type before checking COMPLETE_TYPE_P. PR c++/110106 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Try to complete the type when !processing_template_decl. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept80.C: New test. --- gcc/cp/constexpr.cc | 5 +++-- gcc/testsuite/g++.dg/cpp0x/noexcept80.C | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept80.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 6e8f1c2b61e..fb94f3cefcb 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9116,8 +9116,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, if (now && want_rval) { tree type = TREE_TYPE (t); - if ((processing_template_decl && !COMPLETE_TYPE_P (type)) - || dependent_type_p (type) + if (dependent_type_p (type) + || !COMPLETE_TYPE_P (processing_template_decl + ? type : complete_type (type)) || is_really_empty_class (type, /*ignore_vptr*/false)) /* An empty class has no data to read. */ return true; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept80.C b/gcc/testsuite/g++.dg/cpp0x/noexcept80.C new file mode 100644 index 00000000000..3e90af747e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept80.C @@ -0,0 +1,12 @@ +// PR c++/110106 +// { dg-do compile { target c++11 } } + +template struct S +{ +}; + +struct G { + G(S<0>); +}; + +void y(S<0> s) noexcept(noexcept(G{s})); base-commit: 4b8878fbf7b74ea5c3405c9f558df0517036f131 -- 2.41.0