From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@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 16:02:00 -0000 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-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00730.txt.bz2 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. */