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 02672385735F for ; Tue, 10 May 2022 04:13:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02672385735F Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-310-qjTBQzvjNv--3jROhSjzBA-1; Tue, 10 May 2022 00:13:53 -0400 X-MC-Unique: qjTBQzvjNv--3jROhSjzBA-1 Received: by mail-qt1-f198.google.com with SMTP id q13-20020a05622a04cd00b002f3c0e197afso10934444qtx.0 for ; Mon, 09 May 2022 21:13:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=rwW2NFMuDOHK9KkMspQuTD9Z9VJyibE2BGVYHR/I29E=; b=ZUN6UbezPbB7XDJyoGSQr8+wpJ8utgsdFeTa+LXnXbqOzSgwJ4RY3ib//Wk8onHEGz vzLRNWfzg39C316A2RsZ1lvHujkxJma41kAiYf09oyKpkuL9hf6DDD7ibkEuOge3FWGI AYtygoYtZDjdJo1x+AQZwe+ursTQQE9nIZgQj8PXIoAOOw8M4oq7kqtVNpx2JIDdlbOR zKtaxMV4W6jkVoakZ1cewbMdcVYtAzkUT+VNnulB/7hvdicc6vURoFRW9eVvBYmhi/+U OHMH+d6hQqxslCwMjTy/jHvPHVWYn+aLUyLnZtXBFR6RelhBOxW/f7P88RIyCrjUxVL9 GwJQ== X-Gm-Message-State: AOAM531BpDTZQTYB033RZB5qW6qJUeDZLvJyVmJ9qKH0PIYfZCvKBOYB sjBSZcRJqAu8DkIpH0E1GISG0fulI3R+F01/1HTaTedWgafCYqfeDEnl+xsPaBy1XQ8edHHPG5J WPAi3iZ/T4CaAwXdLCQ== X-Received: by 2002:a05:6214:8eb:b0:456:4fd4:6dd2 with SMTP id dr11-20020a05621408eb00b004564fd46dd2mr16327379qvb.75.1652156033101; Mon, 09 May 2022 21:13:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk9bIKpvuhUfL/XbQGDufjGcLlchyBB0btf4xcwCOSgWmZKJMugfqD1AxqXcit2Ui+nPADXg== X-Received: by 2002:a05:6214:8eb:b0:456:4fd4:6dd2 with SMTP id dr11-20020a05621408eb00b004564fd46dd2mr16327368qvb.75.1652156032808; Mon, 09 May 2022 21:13:52 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id j65-20020a37a044000000b0069fc13ce207sm8008917qke.56.2022.05.09.21.13.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 May 2022 21:13:51 -0700 (PDT) Message-ID: <51ee566a-6b41-09fe-cfef-e9cb44e53935@redhat.com> Date: Tue, 10 May 2022 00:13:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH] c++: ICE with constexpr dtor on ARM [PR105529] To: Marek Polacek , GCC Patches References: <20220509224107.483598-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20220509224107.483598-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 10 May 2022 04:13:57 -0000 On 5/9/22 18:41, Marek Polacek wrote: > When compiling this test on ARM with -O, we ICE in cxx_eval_store_expression > while evaluating a CALL_EXPR allocator::~allocator (&D.4529). Its body > has this store: > > = this > > The RHS is evaluated into &D.4529 of type allocator *. The object, > , is of type void *. Their types don't match That seems like the bug, which I have a patch for. > so we go into the new > > if (empty_base || !(same_type_ignoring_top_level_qualifiers_p > (TREE_TYPE (init), type))) > { > empty_base = true; > gcc_assert (is_empty_class (TREE_TYPE (init))); > > branch where we crash because is_empty_class will always say false for > a pointer type. It seems like the new branch expects code like > > D.2181 = {} > > where the type of the LHS is the derived type and the type of the RHS is > the base type. But it only expects to see actual class types, not > pointers to them. With this patch we will do what we did before the > empty bases cleanup patch: set *valp and return the initializer. It seems reasonable to expect that the initializer has the same type as the target; otherwise other things are likely to get confused. I'll incorporate your testcases in my patch, thanks. > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c++/105529 > > gcc/cp/ChangeLog: > > * constexpr.cc (cxx_eval_store_expression): Check CLASS_TYPE_P before > checking initialization of an empty base. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/constexpr-dtor13.C: New test. > * g++.dg/cpp2a/constexpr-dtor14.C: New test. > --- > gcc/cp/constexpr.cc | 5 +++-- > gcc/testsuite/g++.dg/cpp2a/constexpr-dtor13.C | 11 +++++++++++ > gcc/testsuite/g++.dg/cpp2a/constexpr-dtor14.C | 13 +++++++++++++ > 3 files changed, 27 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-dtor13.C > create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-dtor14.C > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index e560d842e8c..e4498c15f1e 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -5916,8 +5916,9 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, > > gcc_checking_assert (!*valp || (same_type_ignoring_top_level_qualifiers_p > (TREE_TYPE (*valp), type))); > - if (empty_base || !(same_type_ignoring_top_level_qualifiers_p > - (TREE_TYPE (init), type))) > + if (empty_base || (CLASS_TYPE_P (TREE_TYPE (init)) > + && !(same_type_ignoring_top_level_qualifiers_p > + (TREE_TYPE (init), type)))) > { > /* For initialization of an empty base, the original target will be > *(base*)this, evaluation of which resolves to the object > diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor13.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor13.C > new file mode 100644 > index 00000000000..7b289614fc1 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor13.C > @@ -0,0 +1,11 @@ > +// PR c++/105529 > +// { dg-do compile { target c++20 } } > +// { dg-options "-O" } > + > +struct allocator { > + constexpr ~allocator() {} > +}; > +struct S { > + S(int, int, allocator = allocator()); > +}; > +void to_string() { S(0, '\0'); } > diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor14.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor14.C > new file mode 100644 > index 00000000000..9c55121eb8a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor14.C > @@ -0,0 +1,13 @@ > +// PR c++/105529 > +// { dg-do compile { target c++20 } } > +// { dg-options "-O" } > +// Like constexpr-dtor13.C, except that allocator is not an empty class. > + > +struct allocator { > + constexpr ~allocator() {} > + int a; > +}; > +struct S { > + S(int, int, allocator = allocator()); > +}; > +void to_string() { S(0, '\0'); } > > base-commit: 8a39c7c128dbf4405821778724c5a1017ab12e06