From patchwork Mon Aug 18 15:03:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 381031 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 B95DE14010C for ; Tue, 19 Aug 2014 01:04:02 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=gUIctr4xdS6bBWW51OoGLT9naJRGILzlIFSrY50rW5RERcFAr93ro DQGIGIj0Dulrtz8teJ4++bF34ZLussqp8ADuHyD6pRAqj7NLmTUz5ZcA5Q5tBOJH N+dKRkpGRTCU4dBuyQDeqDVNvJwBGunxBOJo/BxCIiB+3OUvZ3s2r4= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=Z4gqBK6lkutVWgPk1bCF7YwFSTE=; b=vKKO4ARwkyrPnD913J0d slqldhvWv+ZYmuOeTIB2O3dZxdO8zFMLsMFneQ9ne40yIGKQW4+tDbdn2GVpK8XD jr/ucDz4/uvGsaV/PQm/0upryZWmzRiH5n3mIPltcoOZdlhy5I3AgNzx8QnS7Js2 BbFJaSVioOQdjjs1Q2VqjDo= Received: (qmail 20896 invoked by alias); 18 Aug 2014 15:03:22 -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 20851 invoked by uid 89); 18 Aug 2014 15:03:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f42.google.com Received: from mail-pa0-f42.google.com (HELO mail-pa0-f42.google.com) (209.85.220.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 18 Aug 2014 15:03:19 +0000 Received: by mail-pa0-f42.google.com with SMTP id lf10so8049413pab.29 for ; Mon, 18 Aug 2014 08:03:17 -0700 (PDT) X-Received: by 10.66.65.230 with SMTP id a6mr36027080pat.18.1408374197453; Mon, 18 Aug 2014 08:03:17 -0700 (PDT) Received: from msticlxl57.ims.intel.com ([192.55.54.42]) by mx.google.com with ESMTPSA id gb1sm16450235pbd.76.2014.08.18.08.03.15 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Aug 2014 08:03:17 -0700 (PDT) Date: Mon, 18 Aug 2014 19:03:10 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, Pointer Bounds Checker 37/x] Support va_arg_pack and va_arg_pack_len Message-ID: <20140818145639.GD29976@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, This patch adds support for va_arg_pack and va_arg_pack_len for instrumented functions into inliner. There are two things to do: 1) ignore bounds args when computing va_arg_pack_len 2) remove bounds args when expanding va_arg_pack in not instrumented call. Thanks, Ilya --- 2014-08-15 Ilya Enkovich * tree-inline.c (copy_bb): Properly handle bounds in va_arg_pack and va_arg_pack_len. diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 6ec1a81..03e7e2f 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1767,13 +1767,29 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale, gimple new_call; vec argarray; size_t nargs = gimple_call_num_args (id->gimple_call); - size_t n; + size_t n, i, nargs_to_copy; + bool remove_bounds = false; for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) nargs--; + /* Bounds should be removed from arg pack in case + we handle not instrumented call in instrumented + function. */ + nargs_to_copy = nargs; + if (gimple_call_with_bounds_p (id->gimple_call) + && !gimple_call_with_bounds_p (stmt)) + { + for (i = gimple_call_num_args (id->gimple_call) - nargs; + i < gimple_call_num_args (id->gimple_call); + i++) + if (POINTER_BOUNDS_P (gimple_call_arg (id->gimple_call, i))) + nargs_to_copy--; + remove_bounds = true; + } + /* Create the new array of arguments. */ - n = nargs + gimple_call_num_args (stmt); + n = nargs_to_copy + gimple_call_num_args (stmt); argarray.create (n); argarray.safe_grow_cleared (n); @@ -1782,11 +1798,26 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale, gimple_call_arg_ptr (stmt, 0), gimple_call_num_args (stmt) * sizeof (tree)); - /* Append the arguments passed in '...' */ - memcpy (argarray.address () + gimple_call_num_args (stmt), - gimple_call_arg_ptr (id->gimple_call, 0) - + (gimple_call_num_args (id->gimple_call) - nargs), - nargs * sizeof (tree)); + if (remove_bounds) + { + /* Append the rest of arguments removing bounds. */ + unsigned cur = gimple_call_num_args (stmt); + i = gimple_call_num_args (id->gimple_call) - nargs; + for (i = gimple_call_num_args (id->gimple_call) - nargs; + i < gimple_call_num_args (id->gimple_call); + i++) + if (!POINTER_BOUNDS_P (gimple_call_arg (id->gimple_call, i))) + argarray[cur++] = gimple_call_arg (id->gimple_call, i); + gcc_assert (cur == n); + } + else + { + /* Append the arguments passed in '...' */ + memcpy (argarray.address () + gimple_call_num_args (stmt), + gimple_call_arg_ptr (id->gimple_call, 0) + + (gimple_call_num_args (id->gimple_call) - nargs), + nargs * sizeof (tree)); + } new_call = gimple_build_call_vec (gimple_call_fn (stmt), argarray); @@ -1812,13 +1843,20 @@ copy_bb (copy_body_data *id, basic_block bb, int frequency_scale, { /* __builtin_va_arg_pack_len () should be replaced by the number of anonymous arguments. */ - size_t nargs = gimple_call_num_args (id->gimple_call); + size_t nargs = gimple_call_num_args (id->gimple_call), i; tree count, p; gimple new_stmt; for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) nargs--; + /* For instrumented calls we should ignore bounds. */ + for (i = gimple_call_num_args (id->gimple_call) - nargs; + i < gimple_call_num_args (id->gimple_call); + i++) + if (POINTER_BOUNDS_P (gimple_call_arg (id->gimple_call, i))) + nargs--; + count = build_int_cst (integer_type_node, nargs); new_stmt = gimple_build_assign (gimple_call_lhs (stmt), count); gsi_replace (©_gsi, new_stmt, false);