From patchwork Wed Nov 26 01:39:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 414943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6C39B140139 for ; Wed, 26 Nov 2014 12:32:22 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=fbe/5iMDXtYJUd+bydjVLFYh4Nz3ShRl7iVHYa64Edzxr7dX0tLI1 A8tSl21Rs+J+4L6kI+JfUl+8Dd0hH5fYQwLVMbNXYO/CoXGiFQ2xssVFk3G1WNqG HG8geqGPegH8nbgJk7HzezPI+qXioIjCyKTn1bedhtqeHzGYpLtUeA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=/15G2OYTT6BZpI1jhlpcsapNMDY=; b=URWdlATCHuJ8vmMpa+Z6 DhFuLaUxjZ7IXQmNJEgNIXEQQCjTBErE6vtx/SStbZyiT1QBS9UxXHlehgPCa1p0 fi8yCkKi/ZUk2TIFrzvfM7FmdUxH4iYxOvdAyHEPkWiyYtnA/QvUBKUqnTzyLW3H Rusj8UYPZv1BLbiSFmgq82E= Received: (qmail 25379 invoked by alias); 26 Nov 2014 01:32:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25211 invoked by uid 89); 26 Nov 2014 01:31:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 26 Nov 2014 01:31:58 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAQ1Vv7u015500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 25 Nov 2014 20:31:57 -0500 Received: from c64.redhat.com (vpn-239-49.phx2.redhat.com [10.3.239.49]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sAQ1Vtks020323; Tue, 25 Nov 2014 20:31:56 -0500 From: David Malcolm To: gcc-patches@gcc.gnu.org, jit@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 01/08] PR jit/63854: Fix leak in tree-ssa-math-opts.c Date: Tue, 25 Nov 2014 20:39:31 -0500 Message-Id: <1416965978-15582-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1416965978-15582-1-git-send-email-dmalcolm@redhat.com> References: <1416965978-15582-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes Running testsuite/jit.dg/test-functions.c under valgrind showed this leak (amongst others): 400 bytes in 10 blocks are definitely lost in loss record 142 of 181 at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5DCDF2F: xrealloc (xmalloc.c:177) by 0x53726CE: void va_heap::reserve(vec*&, unsigned int, bool) (vec.h:310) by 0x5371BB1: vec::reserve(unsigned int, bool) (vec.h:1428) by 0x5370F5D: vec::safe_push(gimple_statement_base* const&) (vec.h:1537) by 0x5523E71: maybe_record_sincos(vec*, basic_block_def**, gimple_statement_base*) (tree-ssa-math-opts.c:718) by 0x552403E: execute_cse_sincos_1(tree_node*) (tree-ssa-math-opts.c:760) by 0x5526224: (anonymous namespace)::pass_cse_sincos::execute(function*) (tree-ssa-math-opts.c:1497) by 0x5250095: execute_one_pass(opt_pass*) (passes.c:2311) by 0x525030C: execute_pass_list_1(opt_pass*) (passes.c:2363) by 0x525033D: execute_pass_list_1(opt_pass*) (passes.c:2364) by 0x525037A: execute_pass_list(function*, opt_pass*) (passes.c:2374) For some reason (which I've filed for myself as PR jit/64020), this code was bailing out: fndecl = mathfn_built_in (type, BUILT_IN_CEXPI); if (!fndecl) return false; That exit path is missing a: stmts.release (); and thus is leaking the buffer of stmts on the way out. Fix it by converting stmts from vec<> to auto_vec<>, to avoid the need to have handwritten release calls on every exit path. gcc/ChangeLog: PR jit/63854 * tree-ssa-math-opts.c (execute_cse_sincos_1): Fix a missing release of stmts by converting it to an auto_vec. --- gcc/tree-ssa-math-opts.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index f9c30bf..5e08c7ee 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -740,7 +740,7 @@ execute_cse_sincos_1 (tree name) tree fndecl, res, type; gimple def_stmt, use_stmt, stmt; int seen_cos = 0, seen_sin = 0, seen_cexpi = 0; - vec stmts = vNULL; + auto_vec stmts; basic_block top_bb = NULL; int i; bool cfg_changed = false; @@ -773,10 +773,7 @@ execute_cse_sincos_1 (tree name) } if (seen_cos + seen_sin + seen_cexpi <= 1) - { - stmts.release (); - return false; - } + return false; /* Simply insert cexpi at the beginning of top_bb but not earlier than the name def statement. */ @@ -835,8 +832,6 @@ execute_cse_sincos_1 (tree name) cfg_changed = true; } - stmts.release (); - return cfg_changed; }