From patchwork Mon May 9 22:41:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1628846 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Z3UDXaaX; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kxx443p90z9sCq for ; Tue, 10 May 2022 08:41:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DDD6385736A for ; Mon, 9 May 2022 22:41:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DDD6385736A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652136094; bh=tjVehjDudxS08dRtXNyO9AZWSjh69+X+pPeTfqRx+74=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Z3UDXaaXk1phtbKCJHAi/hupUPFhd59hxst3CXxEKjszy0qOmmCVfrehyrZsX2NQ3 GEMg1NiCE6vg/9zIOUm6AVaOs4uJ7AAAUdx/sDgjKVY14Nv2RGzEuBcY+D0+6Y+TxL 70TXbESNLd2qivNWgWgffN0Y9BQYj23FwPfmctHo= 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 E6D28385840F for ; Mon, 9 May 2022 22:41:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6D28385840F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22--A3j6gAxOR6ZM0PU_w4JSw-1; Mon, 09 May 2022 18:41:11 -0400 X-MC-Unique: -A3j6gAxOR6ZM0PU_w4JSw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F4DA185A794 for ; Mon, 9 May 2022 22:41:11 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.34.165]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8240C15228D8; Mon, 9 May 2022 22:41:11 +0000 (UTC) To: Jason Merrill , GCC Patches Subject: [PATCH] c++: ICE with constexpr dtor on ARM [PR105529] Date: Mon, 9 May 2022 18:41:07 -0400 Message-Id: <20220509224107.483598-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 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_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-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" 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 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. 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 base-commit: 8a39c7c128dbf4405821778724c5a1017ab12e06 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'); }