From patchwork Wed May 4 13:53:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 53455 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 DF3463856DFB for ; Wed, 4 May 2022 13:54:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF3463856DFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651672466; bh=BWxB36r6PYkjJznlwzdqOL6Qq5q6VoiRIT4qSjFrwlg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dAm6wSeIK2oGB1tBd6snUSmlhICQNrBleZ8lP+bQtsmtIZaBUQoPOU1qMgTIlD2m1 S1jCmbNzLQqJGGc/o21I+wdGcbDBdlD+O34wsrjLXK9UoTK08zqn+YXPL+mVgKE3Yy 5GYl/BEt8K6r763SxC9TkzabKWmHaZIg15tnlkIg= 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 F16143857831 for ; Wed, 4 May 2022 13:53:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F16143857831 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-654-_hbc815VPX-eOIbbABJaxQ-1; Wed, 04 May 2022 09:53:54 -0400 X-MC-Unique: _hbc815VPX-eOIbbABJaxQ-1 Received: by mail-qt1-f198.google.com with SMTP id s10-20020a05622a018a00b002f381134e2bso994462qtw.3 for ; Wed, 04 May 2022 06:53:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=BWxB36r6PYkjJznlwzdqOL6Qq5q6VoiRIT4qSjFrwlg=; b=wOsortw62azHhyXJfMJJvWWzwbcqoDTMYcwTWMM6pzxYnHr94/LWjNSyKcsn8CZdVe dYV7qAmuyXyl89GRRbxpnyf8kD0n7runVYDh6as+pO3FPC01HEcPIl5LLKJBkb2LCoOI CuVmtStRRz6+unfsaxzh032Qn+5XeFzOrHcO04aJYL0KyNtNG57UF7PiXj0uzHSj3GL5 ZrDtEjkwXJvbYPS/bwZML35AAHZMqXW97hSeoknk1F/6awiqv8vqc1aKiNxUBrZC7BTr lrocE0eLII37ZbY3NDXGKCy8/Aq8PzAz66mAUi5un0Co4beGuJerb6JkQvr+T/gm6ftd FLgw== X-Gm-Message-State: AOAM531zEx8S7H7KFObGAZuclLPSuYkDMsg+SMIcEfwNr3WPXiHjH0o0 3GXDtfw0yk/SpnnGoKsZ4cjqQdK3jrOCqoAItOMg5qYJ75s46fnSrzawm3pRzoHM+vmzs8U2Tht Oiw2lb1MPEHNC8EHtPBvwBg2hgxEXTkBBcEy/f9OJDNmgTYBW6CfBL7slmJDastqZ1w== X-Received: by 2002:a05:620a:2889:b0:699:bbc5:9b4b with SMTP id j9-20020a05620a288900b00699bbc59b4bmr15772807qkp.712.1651672433628; Wed, 04 May 2022 06:53:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKdY8Iid7S4Kns8PEy7WkpkV3e7IA3Ixp2WvIBnna03gjIWzaSdK4GxVafBaCKvctjzVlGSA== X-Received: by 2002:a05:620a:2889:b0:699:bbc5:9b4b with SMTP id j9-20020a05620a288900b00699bbc59b4bmr15772771qkp.712.1651672433082; Wed, 04 May 2022 06:53:53 -0700 (PDT) Received: from barrymore.redhat.com (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 z4-20020ac84544000000b002f39b99f69esm7593716qtn.56.2022.05.04.06.53.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 06:53:51 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: Remove cdtor_label Date: Wed, 4 May 2022 09:53:49 -0400 Message-Id: <20220504135349.2638068-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Jakub pointed out that cdtor_label is unnecessary, we should get all the desired semantics with a normal return. Tested x86_64-pc-linux-gnu and arm-eabi//arm-sim, applying to trunk. gcc/cp/ChangeLog: * cp-tree.h (struct language_function): Remove x_cdtor_label. (cdtor_label, LABEL_DECL_CDTOR): Remove. * constexpr.cc (returns): Don't check LABEL_DECL_CDTOR. (cxx_eval_constant_expression): Don't call returns. * decl.cc (check_goto): Don't check cdtor_label. (start_preparsed_function): And don't set it. (finish_constructor_body, finish_destructor_body): Remove. (finish_function_body): Don't call them. * typeck.cc (check_return_expr): Handle cdtor_returns_this here. * semantics.cc (finish_return_stmt): Not here. --- gcc/cp/cp-tree.h | 14 -------------- gcc/cp/constexpr.cc | 8 ++------ gcc/cp/decl.cc | 20 -------------------- gcc/cp/semantics.cc | 11 ----------- gcc/cp/typeck.cc | 12 ++++++++++-- 5 files changed, 12 insertions(+), 53 deletions(-) base-commit: 8afcd148103b0467126483151b6fb5ac68920e72 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8d7cf240b68..663fe7a20fc 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -543,7 +543,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; DECL_CONSTRAINT_VAR_P (in a PARM_DECL) TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL) DECL_INSTANTIATING_NSDMI_P (in a FIELD_DECL) - LABEL_DECL_CDTOR (in LABEL_DECL) USING_DECL_UNRELATED_P (in USING_DECL) 3: DECL_IN_AGGR_P. 4: DECL_C_BIT_FIELD (in a FIELD_DECL) @@ -2057,7 +2056,6 @@ struct named_label_hash : ggc_remove struct GTY(()) language_function { struct c_language_function base; - tree x_cdtor_label; tree x_current_class_ptr; tree x_current_class_ref; tree x_eh_spec_block; @@ -2091,13 +2089,6 @@ struct GTY(()) language_function { #define cp_function_chain (cfun->language) -/* In a constructor destructor, the point at which all derived class - destroying/construction has been done. I.e., just before a - constructor returns, or before any base class destroying will be done - in a destructor. */ - -#define cdtor_label cp_function_chain->x_cdtor_label - /* When we're processing a member function, current_class_ptr is the PARM_DECL for the `this' pointer. The current_class_ref is an expression for `*this'. */ @@ -4278,11 +4269,6 @@ get_vec_init_expr (tree t) #define DECL_LOCAL_DECL_ALIAS(NODE) \ DECL_ACCESS ((gcc_checking_assert (DECL_LOCAL_DECL_P (NODE)), NODE)) -/* Nonzero if NODE is the target for genericization of 'return' stmts - in constructors/destructors of targetm.cxx.cdtor_returns_this targets. */ -#define LABEL_DECL_CDTOR(NODE) \ - DECL_LANG_FLAG_2 (LABEL_DECL_CHECK (NODE)) - /* True if NODE was declared with auto in its return type, but it has started compilation and so the return type might have been changed by return type deduction; its declared return type should be found in diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index c40efa6cc4e..9b1e71857fc 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -6060,9 +6060,7 @@ static bool returns (tree *jump_target) { return *jump_target - && (TREE_CODE (*jump_target) == RETURN_EXPR - || (TREE_CODE (*jump_target) == LABEL_DECL - && LABEL_DECL_CDTOR (*jump_target))); + && TREE_CODE (*jump_target) == RETURN_EXPR; } static bool @@ -7473,9 +7471,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, case GOTO_EXPR: if (breaks (&TREE_OPERAND (t, 0)) - || continues (&TREE_OPERAND (t, 0)) - /* Allow for jumping to a cdtor_label. */ - || returns (&TREE_OPERAND (t, 0))) + || continues (&TREE_OPERAND (t, 0))) *jump_target = TREE_OPERAND (t, 0); else { diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 324498f399d..c9110db796a 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -3613,11 +3613,6 @@ check_goto (tree decl) if (TREE_CODE (decl) != LABEL_DECL) return; - /* We didn't record any information about this label when we created it, - and there's not much point since it's trivial to analyze as a return. */ - if (decl == cdtor_label) - return; - hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl)); named_label_entry **slot = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT); @@ -17325,14 +17320,6 @@ start_preparsed_function (tree decl1, tree attrs, int flags) ++function_depth; - if (DECL_DESTRUCTOR_P (decl1) - || (DECL_CONSTRUCTOR_P (decl1) - && targetm.cxx.cdtor_returns_this ())) - { - cdtor_label = create_artificial_label (input_location); - LABEL_DECL_CDTOR (cdtor_label) = true; - } - start_fname_decls (); store_parm_decls (current_function_parms); @@ -17503,9 +17490,6 @@ finish_constructor_body (void) if (targetm.cxx.cdtor_returns_this ()) { - /* Any return from a constructor will end up here. */ - add_stmt (build_stmt (input_location, LABEL_EXPR, cdtor_label)); - val = DECL_ARGUMENTS (current_function_decl); suppress_warning (val, OPT_Wuse_after_free); val = build2 (MODIFY_EXPR, TREE_TYPE (val), @@ -17592,10 +17576,6 @@ finish_destructor_body (void) { tree exprstmt; - /* Any return from a destructor will end up here; that way all base - and member cleanups will be run when the function returns. */ - add_stmt (build_stmt (input_location, LABEL_EXPR, cdtor_label)); - if (targetm.cxx.cdtor_returns_this ()) { tree val; diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index bfb737f665b..10478d1afeb 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -1238,17 +1238,6 @@ finish_return_stmt (tree expr) { if (warn_sequence_point) verify_sequence_points (expr); - - if (DECL_DESTRUCTOR_P (current_function_decl) - || (DECL_CONSTRUCTOR_P (current_function_decl) - && targetm.cxx.cdtor_returns_this ())) - { - /* Similarly, all destructors must run destructors for - base-classes before returning. So, all returns in a - destructor get sent to the DTOR_LABEL; finish_function emits - code to return a value there. */ - return finish_goto_stmt (cdtor_label); - } } r = build_stmt (input_location, RETURN_EXPR, expr); diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 0da6f2485d0..57e55ed48d1 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10447,7 +10447,11 @@ check_return_expr (tree retval, bool *no_warning) { if (retval) error_at (loc, "returning a value from a destructor"); - return NULL_TREE; + + if (targetm.cxx.cdtor_returns_this ()) + retval = current_class_ptr; + else + return NULL_TREE; } else if (DECL_CONSTRUCTOR_P (current_function_decl)) { @@ -10458,7 +10462,11 @@ check_return_expr (tree retval, bool *no_warning) else if (retval) /* You can't return a value from a constructor. */ error_at (loc, "returning a value from a constructor"); - return NULL_TREE; + + if (targetm.cxx.cdtor_returns_this ()) + retval = current_class_ptr; + else + return NULL_TREE; } const tree saved_retval = retval;