public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [CHKP] Support returned bounds in thunks expand
@ 2015-03-10 10:13 Ilya Enkovich
  2015-04-02 14:49 ` Ilya Enkovich
  0 siblings, 1 reply; 10+ messages in thread
From: Ilya Enkovich @ 2015-03-10 10:13 UTC (permalink / raw)
  To: gcc-patches

Hi,

Currentl we loose returned bounds when functions are merged.  This patch fixes it by adding returne bounds support for cgraph_node::expand_thunk.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

2015-03-06  Ilya Enkovich  <ilya.enkovich@intel.com>

	* cgraphunit.c (cgraph_node::expand_thunk): Build returned
	bounds for instrumented functions.

gcc/testsuite/

2015-03-06  Ilya Enkovich  <ilya.enkovich@intel.com>

	* gcc/testsuite/gcc.target/i386/thunk-retbnd.c: New.


diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index e640907..fc38e67 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -1581,6 +1581,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
       int i;
       tree resdecl;
       tree restmp = NULL;
+      tree resbnd = NULL;
 
       gcall *call;
       greturn *ret;
@@ -1697,6 +1698,21 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
       gsi_insert_after (&bsi, call, GSI_NEW_STMT);
       if (!alias_is_noreturn)
 	{
+	  if (instrumentation_clone
+	      && !DECL_BY_REFERENCE (resdecl)
+	      && restmp
+	      && BOUNDED_P (restmp))
+	    {
+	      tree fn = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET);
+	      gcall *retbnd = gimple_build_call (fn, 1, restmp);
+
+	      resbnd = create_tmp_reg (pointer_bounds_type_node, "retbnd");
+	      gimple_call_set_lhs (retbnd, resbnd);
+
+	      gsi_insert_after (&bsi, retbnd, GSI_NEW_STMT);
+	      create_edge (get_create (fn), retbnd, callees->count, callees->frequency);
+	    }
+
 	  if (restmp && !this_adjusting
 	      && (fixed_offset || virtual_offset))
 	    {
@@ -1766,6 +1782,7 @@ cgraph_node::expand_thunk (bool output_asm_thunks, bool force_gimple_thunk)
 	    ret = gimple_build_return (restmp);
 	  else
 	    ret = gimple_build_return (resdecl);
+	  gimple_return_set_retbnd (ret, resbnd);
 
 	  gsi_insert_after (&bsi, ret, GSI_NEW_STMT);
 	}
diff --git a/gcc/testsuite/gcc.target/i386/thunk-retbnd.c b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c
new file mode 100644
index 0000000..d9bd031
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target mpx } */
+/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "return &glob," 2 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
+int glob;
+
+int *
+test1 (void)
+{
+  return &glob;
+}
+
+int *
+test2 (void)
+{
+  return test1 ();
+}

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-04-07 23:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-10 10:13 [CHKP] Support returned bounds in thunks expand Ilya Enkovich
2015-04-02 14:49 ` Ilya Enkovich
2015-04-02 19:42   ` Jeff Law
2015-04-03  8:38     ` Ilya Enkovich
2015-04-02 20:55   ` Jan Hubicka
2015-04-03  8:46     ` Ilya Enkovich
2015-04-03 17:05       ` Jan Hubicka
2015-04-07 14:12         ` Ilya Enkovich
2015-04-07 20:33           ` Jan Hubicka
2015-04-07 23:28             ` Ilya Enkovich

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).