From: Ilya Enkovich <enkovich.gnu@gmail.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH, CHKP, PR middle-end/70877] Support instrumentation of direct calls with a type cast
Date: Tue, 10 May 2016 16:02:00 -0000 [thread overview]
Message-ID: <20160510160131.GC46462@msticlxl57.ims.intel.com> (raw)
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 <ilya.enkovich@intel.com>
* tree-chkp.c (chkp_add_bounds_to_call_stmt): Handle
calls with type casted fndecl.
gcc/testsuite/
2016-05-10 Ilya Enkovich <ilya.enkovich@intel.com>
* 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. */
reply other threads:[~2016-05-10 16:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160510160131.GC46462@msticlxl57.ims.intel.com \
--to=enkovich.gnu@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).