From patchwork Thu Mar 24 10:16:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 52300 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 01C9D3842435 for ; Thu, 24 Mar 2022 10:16:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01C9D3842435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648116994; bh=kMfkZMG9kLXWZ/8+hV5ohrfHtRAmrtYbOr0WfpyIk2Y=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cYzlxSl9n51Qj+bCSeSl/9g4FAPw+Hg5IG+e1uBQF3ooEcZdbI5qeRxnihWG5cmK3 OEWjzI28Cg2mNTAtfCeXtMjG0fpJ+AORY3OllF40Nh8pU+OeORfPsyaSD5InGbNLYd 1ffUg7rfAspCaNU0t1FcTM0qQ0pTJ4/WQOmI0Pzk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id B52C53858C2C for ; Thu, 24 Mar 2022 10:16:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B52C53858C2C Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CD6751F38D for ; Thu, 24 Mar 2022 10:16:02 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BB2AB13B2F for ; Thu, 24 Mar 2022 10:16:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0m+oLOJEPGKzFAAAMHmgww (envelope-from ) for ; Thu, 24 Mar 2022 10:16:02 +0000 Date: Thu, 24 Mar 2022 11:16:02 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix memory leaks MIME-Version: 1.0 Message-Id: <20220324101602.BB2AB13B2F@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When changing the predcom pass to use auto_vec leaks were introduced by failing to replace deallocation with C++ delete. The following does this. It also fixes leaks in vectorization and range folding. Boostrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-03-24 Richard Biener * tree-predcom.cc (chain::chain): Add CTOR. (component::component): Likewise. (pcom_worker::release_chain): Use delete. (release_components): Likewise. (pcom_worker::filter_suitable_components): Likewise. (pcom_worker::split_data_refs_to_components): Use new. (make_invariant_chain): Likewise. (make_rooted_chain): Likewise. (pcom_worker::combine_chains): Likewise. * tree-vect-loop.cc (vect_create_epilog_for_reduction): Make sure to release previously constructed scalar_results. * tree-vect-stmts.cc (vectorizable_load): Use auto_vec for vec_offsets. * vr-values.cc (simplify_using_ranges::~simplify_using_ranges): Release m_flag_set_edges. --- gcc/tree-predcom.cc | 28 +++++++++++++++------------- gcc/tree-vect-loop.cc | 3 ++- gcc/tree-vect-stmts.cc | 2 +- gcc/vr-values.cc | 1 + 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gcc/tree-predcom.cc b/gcc/tree-predcom.cc index 1d8121c4d80..e4aea7cdcb4 100644 --- a/gcc/tree-predcom.cc +++ b/gcc/tree-predcom.cc @@ -297,6 +297,11 @@ enum chain_type typedef struct chain { + chain (chain_type t) : type (t), op (ERROR_MARK), rslt_type (NULL_TREE), + ch1 (NULL), ch2 (NULL), length (0), init_seq (NULL), fini_seq (NULL), + has_max_use_after (false), all_always_accessed (false), combined (false), + inv_store_elimination (false) {} + /* Type of the chain. */ enum chain_type type; @@ -362,6 +367,8 @@ enum ref_step_type struct component { + component (bool es) : eliminate_store_p (es), next (NULL) {} + /* The references in the component. */ auto_vec refs; @@ -698,7 +705,7 @@ pcom_worker::release_chain (chain_p chain) if (chain->fini_seq) gimple_seq_discard (chain->fini_seq); - free (chain); + delete chain; } /* Frees CHAINS. */ @@ -723,7 +730,7 @@ release_components (struct component *comps) for (act = comps; act; act = next) { next = act->next; - XDELETE (act); + delete act; } } @@ -1023,9 +1030,8 @@ pcom_worker::split_data_refs_to_components () comp = comps[ca]; if (!comp) { - comp = XCNEW (struct component); - comp->refs.create (comp_size[ca]); - comp->eliminate_store_p = eliminate_store_p; + comp = new component (eliminate_store_p); + comp->refs.reserve_exact (comp_size[ca]); comps[ca] = comp; } @@ -1142,7 +1148,7 @@ pcom_worker::filter_suitable_components (struct component *comps) *comp = act->next; FOR_EACH_VEC_ELT (act->refs, i, ref) free (ref); - XDELETE (act); + delete act; } } @@ -1255,12 +1261,10 @@ add_ref_to_chain (chain_p chain, dref ref) static chain_p make_invariant_chain (struct component *comp) { - chain_p chain = XCNEW (struct chain); + chain_p chain = new struct chain (CT_INVARIANT); unsigned i; dref ref; - chain->type = CT_INVARIANT; - chain->all_always_accessed = true; FOR_EACH_VEC_ELT (comp->refs, i, ref) @@ -1280,9 +1284,8 @@ make_invariant_chain (struct component *comp) static chain_p make_rooted_chain (dref ref, enum chain_type type) { - chain_p chain = XCNEW (struct chain); + chain_p chain = new struct chain (type); - chain->type = type; chain->refs.safe_push (ref); chain->all_always_accessed = ref->always_accessed; ref->distance = 0; @@ -2873,8 +2876,7 @@ pcom_worker::combine_chains (chain_p ch1, chain_p ch2) if (swap) std::swap (ch1, ch2); - new_chain = XCNEW (struct chain); - new_chain->type = CT_COMBINATION; + new_chain = new struct chain (CT_COMBINATION); new_chain->op = op; new_chain->ch1 = ch1; new_chain->ch2 = ch2; diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 7fcec12a3e9..7a74633e0b4 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -5466,7 +5466,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, scalar_dest = gimple_get_lhs (orig_stmt_info->stmt); scalar_type = TREE_TYPE (scalar_dest); - scalar_results.create (group_size); + scalar_results.truncate (0); + scalar_results.reserve_exact (group_size); new_scalar_dest = vect_create_destination_var (scalar_dest, NULL); bitsize = TYPE_SIZE (scalar_type); diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 5c9e8cfefa5..f7449a79d1c 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -9480,7 +9480,7 @@ vectorizable_load (vec_info *vinfo, memory_access_type); } - vec vec_offsets = vNULL; + auto_vec vec_offsets; auto_vec vec_masks; if (mask) { diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index 0414020876a..f94da3130e3 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -4221,6 +4221,7 @@ simplify_using_ranges::simplify_using_ranges (range_query *query, simplify_using_ranges::~simplify_using_ranges () { cleanup_edges_and_switches (); + m_flag_set_edges.release (); } /* Simplify STMT using ranges if possible. */