From patchwork Tue Mar 26 09:27:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 87656 Return-Path: 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 572BD385841F for ; Tue, 26 Mar 2024 09:27:52 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id C97543858D38 for ; Tue, 26 Mar 2024 09:27:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C97543858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C97543858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711445242; cv=none; b=bjXYKlnbNQFvTe/JZshPMbDiTpBp6386VynE4iLSoZs9LRU2/a7USqGpDHPb8mj7qxBTO9CxlQbH7hrnWQbWvzTswBaqqps0WYzseXVe1W5if+KMSl0zfglCh92B/kpXMJQLjYMnIex4ggQEbYqKKMGTPWqm7Oy5G5WPfxDxmxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711445242; c=relaxed/simple; bh=Ea47Bn4Ep5MwnvEZVp9/8AHadI8PrkebxHtDRP19fTQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=rleCMiNb2fYnT7h3qopwGAavgmBS4cCXuw6Nx5Uu9MIIVIWKIvmzOA5ClYE+o2Rl1qmXNYI20dHGwq+rALosymdyv2gXdrYtMKQM7PxvZv7UkEpt3nO5hSJRIZyP8JSvgf9Y4KnR98osdBlPmDwJo1xPjEjgOne/+99Yn8cA7n0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711445240; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=yP5TWPiujbnYLXd+hvGJSguDQYOmIUdRJEWJFJCeGoM=; b=URoOEIzctvHidE3/Q2avmnVcr09wjPlBCGk7b2G+ErW6S2esWUE/CjOZqZ9MiYiZhgYLI6 9dHGNdCe4XkpKhH9gTmrHVGt7DN2QKlYvnYDHsl5QSJb7idF0oTErYGZnILGe1Ovfkef7H T+0mJ1FGDjZFbGGv/NE+75uOhFWVvXg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-71LBKgAkPTyoD36LorJkPA-1; Tue, 26 Mar 2024 05:27:18 -0400 X-MC-Unique: 71LBKgAkPTyoD36LorJkPA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2306E101A595 for ; Tue, 26 Mar 2024 09:27:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB1C42166B33; Tue, 26 Mar 2024 09:27:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 42Q9RBd32910478 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 26 Mar 2024 10:27:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42Q9RBRa2910477; Tue, 26 Mar 2024 10:27:11 +0100 Date: Tue, 26 Mar 2024 10:27:10 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Don't maybe_constant_value fold dtor calls [PR114426] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following testcase ICEs on arm, because it is the only cdtor_returns_this target. Normally cp_fold never folds destructor calls because the calls have VOID_TYPE_P return and maybe_constant_value in that case does nothing, and cxx_eval_outermost_constant_expr does something for those only if it is a constructor (then initialized_type returns the type of the object being constructed) or if called with constexpr_dtor = true. Arm is the only exception because there the dtor returns the this pointer and so we attempt to fold it, and run into + for (; remapped; remapped = TREE_CHAIN (remapped)) + if (DECL_NAME (remapped) == in_charge_identifier) + { + /* FIXME destructors unnecessarily have in-charge parameters + even in classes without vbases, map it to 0 for now. */ + gcc_assert (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fun))); + ctx->global->put_value (remapped, integer_zero_node); assertion there. The following patch "fixes" it by trying to handle (not handle actually) the dtor calls on arm the same as on all other targets, but perhaps we instead want to constexpr evaluate them on all targets (with constexpr_dtor = true) and deal somehow with the above assertion. In any case, I think some consistency is desirable even when one target has a weird ABI requirement. Bootstrapped/regtested on x86_64-linux and i686-linux plus tested on the testcase in a cross to arm. 2024-03-26 Jakub Jelinek PR c++/114426 * cp-gimplify.cc (cp_fold): Don't call maybe_const_value on CALL_EXPRs to cdtors. * g++.dg/cpp2a/pr114426.C: New test. Jakub --- gcc/cp/cp-gimplify.cc.jj 2024-02-23 18:55:05.377594277 +0100 +++ gcc/cp/cp-gimplify.cc 2024-03-22 16:46:49.381442914 +0100 @@ -3395,7 +3395,13 @@ cp_fold (tree x, fold_flags_t flags) Do constexpr expansion of expressions where the call itself is not constant, but the call followed by an INDIRECT_REF is. */ if (callee && DECL_DECLARED_CONSTEXPR_P (callee) - && !flag_no_inline) + && !flag_no_inline + /* Don't invoke it on dtors. On + !targetm.cxx.cdtor_returns_this () it won't do anything as it + has void type, so don't do it on + targetm.cxx.cdtor_returns_this () targets either for + consistency. */ + && !DECL_DESTRUCTOR_P (callee)) { mce_value manifestly_const_eval = mce_unknown; if (flags & ff_mce_false) --- gcc/testsuite/g++.dg/cpp2a/pr114426.C.jj 2024-03-22 16:49:55.650882841 +0100 +++ gcc/testsuite/g++.dg/cpp2a/pr114426.C 2024-03-22 16:48:51.829759997 +0100 @@ -0,0 +1,6 @@ +// PR c++/114426 +// { dg-do compile } + +struct A { virtual ~A (); }; +struct B : virtual A { virtual void foo () = 0; }; +struct C : B { C () {} };