From patchwork Wed May 1 19:00:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1930340 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NtIRUf9i; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VV5y55rvnz1ymc for ; Thu, 2 May 2024 05:01:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C69B384AB47 for ; Wed, 1 May 2024 19:01:16 +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 B9D773858D20 for ; Wed, 1 May 2024 19:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9D773858D20 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 B9D773858D20 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=1714590045; cv=none; b=qSlyEfOMtuU4UpgKJifiR5QA3H2vgpjDaTcmMp3BkNvDDmTvehKnZgMepV11qaLTzM6S3pxCzXTR/nviQEgjYKpZHbePhFaycmSdUz7kfGTt0qOQeyDsBefbJu3zZ6ina/DId9Qa6V28Ir25I5sNFOdGE190qukoF+OBoA26GCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714590045; c=relaxed/simple; bh=yBFQXxjTNVuf5L6xUC8uEEDvy6VkAN+VdGRXneHdk9c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OBE+JUrrUal2F/wJreGBHcRxSqo20toffD+hyANGyNlNzVXvbmZj0WD9BrAVH9r93dozanbVEm2eQzkhwphjaD9UGgTDFOlK3FScJ3KYI6LAIQz8AQbTHmybGgtDx5hDJRGhO/dG9oBqp+d4HqyK6oT95GC3RR86/n6FxqP5gL4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714590043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lDnwOg5n0N/GCZfIzQMjgt9iulUIZyPX//epog4F8io=; b=NtIRUf9iZJPjmd2XT34IPclBp8E27uJsHUb9D0fkkCGCxYR7ff+2ESftqJDpfovYHI7gPR cZrwnsSo7IkMU3t7xoTmsXknKV9oFB8MVFNaAegerAP7TdUG6SVTj6NJvMNtxgp6ZZLhA5 XUaTdB+FHRQ+C2CliqTWZxttdneITkA= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-2MZmOWBWNBSBJosuZ13mMQ-1; Wed, 01 May 2024 15:00:41 -0400 X-MC-Unique: 2MZmOWBWNBSBJosuZ13mMQ-1 Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-6ed4298be66so5053743b3a.0 for ; Wed, 01 May 2024 12:00:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714590040; x=1715194840; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lDnwOg5n0N/GCZfIzQMjgt9iulUIZyPX//epog4F8io=; b=fHGdOAPpGo8goU48ennsxyRAWWjLd0zZ7ap/P28++srp8Pc/q4CQkMyZf/d0UvDNfN 5tcB5DsJmVu4UHRyGdrs0gfTpdNhsU4rFI61CH4vvrIkcG8bi7xA8TYeohnZItwQjN1p uwXNGm4l0lss5x2nLixhABFdYF/TBpe8bWWSHFx6U/I1Xuw0H8B1F8qV8P7/Hx+N7UaQ WCGoGBJS9vYkI70c2z3zri642wnn9c1a4hJiDq4stuTp/CJEN/sR5nFtUMXPnv2Uh069 1P6ohVBT7AkQi3A69qhi0agBpxbmhfyAWPXRUcfhm9qqmea/fxLMGD1Ykk/m5osZ29jA gk9g== X-Gm-Message-State: AOJu0YxczX27HaqtHGGomyydst+zTMv2mr9wZaCShj+Bvs5xndpy12TN /0cOsz8c/1FXjmQglyvSen2X91Mfc9bMY+VbCVkGN4zYnR+Y4glIM9P2sV/xqjnJR+qMpyWH50d W9BtIElWpAdPb/agO8ctxDzgNXFG4lyOMNLHZEVhwBh1Bhipya5OekJxh5cug4cIzL7nuT7IfZH 5EinETKHmOvtM8ht1rplvU/Uj16KkwnL8Y5AU= X-Received: by 2002:a05:6a00:140c:b0:6ec:ff1b:aa0b with SMTP id l12-20020a056a00140c00b006ecff1baa0bmr3537537pfu.18.1714590039624; Wed, 01 May 2024 12:00:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGij0ruMUWhqZoJdZbTm/+jAI5izukWurUTqMEHXkRaDt4qjAlNfEo2jGz6S8/ffLIL0ljKbA== X-Received: by 2002:a05:6a00:140c:b0:6ec:ff1b:aa0b with SMTP id l12-20020a056a00140c00b006ecff1baa0bmr3537486pfu.18.1714590038769; Wed, 01 May 2024 12:00:38 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id e15-20020a62aa0f000000b006ece85910edsm22992553pff.152.2024.05.01.12.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 12:00:38 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: drop in-charge for dtors without vbases Date: Wed, 1 May 2024 15:00:28 -0400 Message-ID: <20240501190035.539437-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 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_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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Constructors and destructors use the in-charge parameter to decide whether they're responsible for recursing into virtual bases. Historically all destructors had this parameter in order to also distinguish the deleting destructor. But r151673 in GCC 4.5 changed the deleting destructor to just call the complete destructor and then operator delete, making the in-charge parameter no longer relevant for destructors in classes without virtual bases. Having it causes confusion in constexpr evaluation, which assumes that clones will have the same parameters as the cloned 'tor. gcc/cp/ChangeLog: * cp-tree.h (base_ctor_identifier): Adjust comment. * call.cc (in_charge_arg_for_name): Abort on deleting dtor. * decl2.cc (maybe_retrofit_in_chrg): Don't add it for destructors without vbases, either. * constexpr.cc (cxx_eval_call_expression): Remove workaround. gcc/testsuite/ChangeLog: * g++.dg/debug/dwarf2/array-3.C: No more 'int' for in-chrg parm. * g++.dg/debug/dwarf2/array-4.C: Likewise. --- gcc/cp/cp-tree.h | 3 +-- gcc/cp/call.cc | 4 +++- gcc/cp/constexpr.cc | 20 +++++++------------- gcc/cp/decl2.cc | 12 ++++-------- gcc/testsuite/g++.dg/debug/dwarf2/array-3.C | 6 +++--- gcc/testsuite/g++.dg/debug/dwarf2/array-4.C | 2 +- 6 files changed, 19 insertions(+), 28 deletions(-) base-commit: 76ca6e1f8b1524b82a871ce29cf58c79e5e77e2b diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1938ada0268..5d1bd6ba493 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -289,8 +289,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; /* The name of a constructor that does not construct virtual base classes. */ #define base_ctor_identifier cp_global_trees[CPTI_BASE_CTOR_IDENTIFIER] /* The name of a destructor that takes an in-charge parameter to - decide whether or not to destroy virtual base classes and whether - or not to delete the object. */ + decide whether or not to destroy virtual base classes. */ #define dtor_identifier cp_global_trees[CPTI_DTOR_IDENTIFIER] /* The name of a destructor that destroys virtual base classes. */ #define complete_dtor_identifier cp_global_trees[CPTI_COMPLETE_DTOR_IDENTIFIER] diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index dbdd7c29fe8..7c4ecf08c4b 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -11167,7 +11167,9 @@ in_charge_arg_for_name (tree name) if (name == complete_dtor_identifier) return integer_two_node; else if (name == deleting_dtor_identifier) - return integer_three_node; + /* The deleting dtor should now be handled by + build_delete_destructor_body. */ + gcc_unreachable (); gcc_checking_assert (name == base_dtor_identifier); } diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8078b31544d..50f799d7ff7 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -3243,19 +3243,13 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, ctx->global->put_value (remapped, arg); remapped = DECL_CHAIN (remapped); } - 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); - } - else - { - gcc_assert (seen_error ()); - *non_constant_p = true; - } + if (remapped) + { + /* We shouldn't have any parms without args, but fail gracefully + in error recovery. */ + gcc_checking_assert (seen_error ()); + *non_constant_p = true; + } /* Add the RESULT_DECL to the values map, too. */ gcc_assert (!DECL_BY_REFERENCE (res)); ctx->global->put_value (res, NULL_TREE); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 806a2a4bc69..b8dc55b51d9 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -275,11 +275,8 @@ build_artificial_parm (tree fn, tree name, tree type) return parm; } -/* Constructors for types with virtual baseclasses need an "in-charge" flag - saying whether this constructor is responsible for initialization of - virtual baseclasses or not. All destructors also need this "in-charge" - flag, which additionally determines whether or not the destructor should - free the memory for the object. +/* 'structors for types with virtual baseclasses need an "in-charge" flag + saying whether this function is responsible for virtual baseclasses or not. This function adds the "in-charge" flag to member function FN if appropriate. It is called from grokclassfn and tsubst. @@ -302,10 +299,9 @@ maybe_retrofit_in_chrg (tree fn) if (processing_template_decl) return; - /* We don't need an in-charge parameter for constructors that don't + /* We don't need an in-charge parameter for 'structors that don't have virtual bases. */ - if (DECL_CONSTRUCTOR_P (fn) - && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn))) + if (!CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn))) return; arg_types = TYPE_ARG_TYPES (TREE_TYPE (fn)); diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/array-3.C b/gcc/testsuite/g++.dg/debug/dwarf2/array-3.C index 8db6133b765..ae04b217e28 100644 --- a/gcc/testsuite/g++.dg/debug/dwarf2/array-3.C +++ b/gcc/testsuite/g++.dg/debug/dwarf2/array-3.C @@ -12,9 +12,9 @@ const S S::array[2] = { S(), S() }; /* Verify that we get only one DW_TAG_subrange_type (plus the abbrev), and one DW_AT_upper_bound (non-abbrev), because the array definition loses the readonly wrapper for the array type because of - the dynamic initializers. The const types are 4: S, S*, int, and - S[4], plus the abbrev. A const version of S[4] doesn't make sense, + the dynamic initializers. The const types are 3: S, S*, and + S[2], plus the abbrev. A const version of S[2] doesn't make sense, but we output it. */ -/* { dg-final { scan-assembler-times " DW_TAG_const_type" 5 } } */ +/* { dg-final { scan-assembler-times " DW_TAG_const_type" 4 } } */ /* { dg-final { scan-assembler-times " DW_TAG_subrange_type" 2 } } */ /* { dg-final { scan-assembler-times " DW_AT_upper_bound" 1 } } */ diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/array-4.C b/gcc/testsuite/g++.dg/debug/dwarf2/array-4.C index 6b3f546c1b5..6133234181a 100644 --- a/gcc/testsuite/g++.dg/debug/dwarf2/array-4.C +++ b/gcc/testsuite/g++.dg/debug/dwarf2/array-4.C @@ -11,6 +11,6 @@ const S array[2] = { S(), S() }; /* Like array-3, but with a non-member array without a separate declaration, to check that we don't issue the nonsensical DW_TAG_const_type used by the member array declaration there. */ -/* { dg-final { scan-assembler-times " DW_TAG_const_type" 4 } } */ +/* { dg-final { scan-assembler-times " DW_TAG_const_type" 3 } } */ /* { dg-final { scan-assembler-times " DW_TAG_subrange_type" 2 } } */ /* { dg-final { scan-assembler-times " DW_AT_upper_bound" 1 } } */