From patchwork Tue May 10 16:01:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 620717 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 3r43tk6wXWz9t3V for ; Wed, 11 May 2016 02:02:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=KN6K8Cgk; dkim-atps=neutral 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=Jp8MaUO5TN9z28jLyGxoSbUkiBo/XBpLwQkpyi2sG5i8RkUK/0+Af d1lv5rtdcrRUMz/ZTop7qQqVDIBt6g48XCmfVWARkcJTwX3GJ7APo3YPTlnwaTNp NyzTkWOGqKOf3aSxjSS98FLPhhhplNxX5/Q8YiKrlk+QNYoKopjt4M= 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=zs1jvCyVDUFTGIK8GXbybkQJ4DQ=; b=KN6K8Cgk0EoWfb6Nn94o nO36kAzPXJx+HM9U6EHrzSML4Rd6z6X+lsVvFOQDY78HTSd2Azxde5Y3X/t4z8Iz Iq7Xrloy3B2QgOeTXop97Bl5t8N4aTN5gBSDNnwfp3oa8iKmoOyxMLd4+7cKOiMI lE/TIyL+MWOPNcZVqx5pU3k= Received: (qmail 44321 invoked by alias); 10 May 2016 16:02:42 -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 44303 invoked by uid 89); 10 May 2016 16:02:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=ilya.enkovich@intel.com, ilyaenkovichintelcom, Hx-languages-length:2376 X-HELO: mail-ig0-f194.google.com Received: from mail-ig0-f194.google.com (HELO mail-ig0-f194.google.com) (209.85.213.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 10 May 2016 16:02:31 +0000 Received: by mail-ig0-f194.google.com with SMTP id rc4so1603651igc.0 for ; Tue, 10 May 2016 09:02:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=90/4Qnd2XIMvaGs/dMyplhNOnYCCMyI9ZP/SSvNDO9Y=; b=nNEOa1OMnK9S9UP6rM5ldgX+zjLZXqJjVO8YA/b0bVcG7HkplhWB8nhGNmO1osgZ3K b+Mv9ft7w/SjaDstOkTbvGTlb9MNn/pwA5vn9LDt8MmpIR17+8wpyBiTe0SZ5IVkDVdn 9ktLpeFypIFZDppNzaCyXabVcCAajJI9RUQZU8T6KA9ZmCCvtzuBaEmY5DkICqd/mbW9 twXgOMG4Q5DttbJ9O0AZERgTmIDa+kmAstsExw+Adh+34KbQX3FBqIwE7TF6F3EwJpvw ywBMjYDGcfG4KiGzhZs1GQIPiOFjprqwYSx9FjNlTDCBSVdb6yVM7HxHBRBZtZff4Mpc uD5Q== X-Gm-Message-State: AOPr4FU2gAHO/YzvyMxCW8ZdYN4A965njplOY/9DZLyw1TqxKnbMnSgH1B0xovIqOSgBbQ== X-Received: by 10.50.142.97 with SMTP id rv1mr17601550igb.74.1462896149061; Tue, 10 May 2016 09:02:29 -0700 (PDT) Received: from msticlxl57.ims.intel.com (irdmzpr02-ext.ir.intel.com. [192.198.151.37]) by smtp.gmail.com with ESMTPSA id o187sm779492itd.21.2016.05.10.09.02.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 May 2016 09:02:28 -0700 (PDT) Date: Tue, 10 May 2016 19:01:31 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, CHKP, PR middle-end/70877] Support instrumentation of direct calls with a type cast Message-ID: <20160510160131.GC46462@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, Currently instrumentation ignores call type for direct calls. This patch fixes it to enable direct calls where function is casted to another function type. Bootstrapped and regtested on x86_64-unknown-linux-gnu on MPX enabled hardware. I'm going to port this patch to gcc-6-branch. Thanks, Ilya --- gcc/ 2016-05-10 Ilya Enkovich * tree-chkp.c (chkp_add_bounds_to_call_stmt): Handle calls with type casted fndecl. gcc/testsuite/ 2016-05-10 Ilya Enkovich * gcc.target/i386/pr70877.c: New test. diff --git a/gcc/testsuite/gcc.target/i386/pr70877.c b/gcc/testsuite/gcc.target/i386/pr70877.c new file mode 100644 index 0000000..4269e84 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr70877.c @@ -0,0 +1,14 @@ +/* { dg-do compile { target { ! x32 } } } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */ + +int foo(int); + +typedef struct { + double d; + int a; +} str_t; + +void bar(double d, int i, str_t s) +{ + d = ((double (*) (int)) foo) (i); /* { dg-warning "function called through a non-compatible type" } */ +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 3fba12c..960391f 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -1853,7 +1853,9 @@ chkp_add_bounds_to_call_stmt (gimple_stmt_iterator *gsi) /* If function decl is available then use it for formal arguments list. Otherwise use function type. */ - if (fndecl && DECL_ARGUMENTS (fndecl)) + if (fndecl + && DECL_ARGUMENTS (fndecl) + && gimple_call_fntype (call) == TREE_TYPE (fndecl)) first_formal_arg = DECL_ARGUMENTS (fndecl); else { @@ -1929,7 +1931,16 @@ chkp_add_bounds_to_call_stmt (gimple_stmt_iterator *gsi) { tree new_decl = chkp_maybe_create_clone (fndecl)->decl; gimple_call_set_fndecl (new_call, new_decl); - gimple_call_set_fntype (new_call, TREE_TYPE (new_decl)); + /* In case of a type cast we should modify used function + type instead of using type of new fndecl. */ + if (gimple_call_fntype (call) != TREE_TYPE (fndecl)) + { + tree type = gimple_call_fntype (call); + type = chkp_copy_function_type_adding_bounds (type); + gimple_call_set_fntype (new_call, type); + } + else + gimple_call_set_fntype (new_call, TREE_TYPE (new_decl)); } /* For indirect call we should fix function pointer type if pass some bounds. */