tree-chkp.h (chkp_insert_retbnd_call): New.
authorIlya Enkovich <ilya.enkovich@intel.com>
Wed, 8 Apr 2015 10:44:59 +0000 (10:44 +0000)
committerIlya Enkovich <ienkovich@gcc.gnu.org>
Wed, 8 Apr 2015 10:44:59 +0000 (10:44 +0000)
gcc/

* tree-chkp.h (chkp_insert_retbnd_call): New.
* tree-chkp.c (chkp_insert_retbnd_call): New.
* ipa-split.c (insert_bndret_call_after): Remove.
(split_function): Use chkp_insert_retbnd_call.
* cgraphunit.c (cgraph_node::expand_thunk): Build returned
bounds for instrumented functions.

gcc/testsuite/

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

From-SVN: r221917

gcc/ChangeLog
gcc/cgraphunit.c
gcc/ipa-split.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/thunk-retbnd.c [new file with mode: 0644]
gcc/tree-chkp.c
gcc/tree-chkp.h

index 7de54510bd4fb31a71666e248264497f54a4ce94..4ab9dca77f53b8eef00e2af0b7b559abe5446d46 100644 (file)
@@ -1,3 +1,12 @@
+2015-04-08  Ilya Enkovich  <ilya.enkovich@intel.com>
+
+       * tree-chkp.h (chkp_insert_retbnd_call): New.
+       * tree-chkp.c (chkp_insert_retbnd_call): New.
+       * ipa-split.c (insert_bndret_call_after): Remove.
+       (split_function): Use chkp_insert_retbnd_call.
+       * cgraphunit.c (cgraph_node::expand_thunk): Build returned
+       bounds for instrumented functions.
+
 2015-04-07  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/65540
index 77ef9edba4ae14a544621ae41efdb759d23ecfaa..2315ba84bb7c779d8f1a64a15956adabc20d84f3 100644 (file)
@@ -1585,6 +1585,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;
@@ -1701,6 +1702,17 @@ 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))
+           {
+             resbnd = chkp_insert_retbnd_call (NULL, restmp, &bsi);
+             create_edge (get_create (gimple_call_fndecl (gsi_stmt (bsi))),
+                          as_a <gcall *> (gsi_stmt (bsi)),
+                          callees->count, callees->frequency);
+           }
+
          if (restmp && !this_adjusting
              && (fixed_offset || virtual_offset))
            {
@@ -1770,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);
        }
index a28f3a1ad921d4a356f5f78e5d586ff712469def..5d6763d102db715a876df7fb9b016eab08f4f660 100644 (file)
@@ -1230,20 +1230,6 @@ find_split_points (basic_block return_bb, int overall_time, int overall_size)
   BITMAP_FREE (current.ssa_names_to_pass);
 }
 
-/* Build and insert initialization of returned bounds RETBND
-   for returned value RETVAL.  Statements are inserted after
-   a statement pointed by GSI and GSI is modified to point to
-   the last inserted statement.  */
-
-static void
-insert_bndret_call_after (tree retbnd, tree retval, gimple_stmt_iterator *gsi)
-{
-  tree fndecl = targetm.builtin_chkp_function (BUILT_IN_CHKP_BNDRET);
-  gimple bndret = gimple_build_call (fndecl, 1, retval);
-  gimple_call_set_lhs (bndret, retbnd);
-  gsi_insert_after (gsi, bndret, GSI_CONTINUE_LINKING);
-}
-
 /* Split function at SPLIT_POINT.  */
 
 static void
@@ -1652,7 +1638,7 @@ split_function (basic_block return_bb, struct split_point *split_point,
                    }
                  /* Build bndret call to obtain returned bounds.  */
                  if (retbnd)
-                   insert_bndret_call_after (retbnd, retval, &gsi);
+                   chkp_insert_retbnd_call (retbnd, retval, &gsi);
                  gimple_call_set_lhs (call, retval);
                  update_stmt (call);
                }
@@ -1702,7 +1688,7 @@ split_function (basic_block return_bb, struct split_point *split_point,
           gsi_insert_after (&gsi, call, GSI_NEW_STMT);
          /* Build bndret call to obtain returned bounds.  */
          if (retbnd)
-           insert_bndret_call_after (retbnd, retval, &gsi);
+           chkp_insert_retbnd_call (retbnd, retval, &gsi);
          if (tsan_func_exit_call)
            gsi_insert_after (&gsi, tsan_func_exit_call, GSI_NEW_STMT);
          ret = gimple_build_return (retval);
index a6a7be318beaa0c71ff0726cd6d4cfc86dbb172a..c926f3d32ea57f7b7f39de0cb6307325db0329d8 100644 (file)
@@ -1,3 +1,7 @@
+2015-04-08  Ilya Enkovich  <ilya.enkovich@intel.com>
+
+       * gcc/testsuite/gcc.target/i386/thunk-retbnd.c: New.
+
 2015-04-08  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt48.adb: New test.
diff --git a/gcc/testsuite/gcc.target/i386/thunk-retbnd.c b/gcc/testsuite/gcc.target/i386/thunk-retbnd.c
new file mode 100644 (file)
index 0000000..d9bd031
--- /dev/null
@@ -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 ();
+}
index 03f75b35da84d209929d8f89112ab1e48e10abe6..541af29a48a0ac30bfe66604a63625ab81764163 100644 (file)
@@ -500,6 +500,35 @@ chkp_expand_bounds_reset_for_mem (tree mem, tree ptr)
   expand_normal (bndstx);
 }
 
+/* Build retbnd call for returned value RETVAL.
+
+   If BNDVAL is not NULL then result is stored
+   in it.  Otherwise a temporary is created to
+   hold returned value.
+
+   GSI points to a position for a retbnd call
+   and is set to created stmt.
+
+   Cgraph edge is created for a new call if
+   UPDATE_EDGE is 1.
+
+   Obtained bounds are returned.  */
+tree
+chkp_insert_retbnd_call (tree bndval, tree retval,
+                        gimple_stmt_iterator *gsi)
+{
+  gimple call;
+
+  if (!bndval)
+    bndval = create_tmp_reg (pointer_bounds_type_node, "retbnd");
+
+  call = gimple_build_call (chkp_ret_bnd_fndecl, 1, retval);
+  gimple_call_set_lhs (call, bndval);
+  gsi_insert_after (gsi, call, GSI_CONTINUE_LINKING);
+
+  return bndval;
+}
+
 /* Mark statement S to not be instrumented.  */
 static void
 chkp_mark_stmt (gimple s)
index 86f3618bd6ec86fab630bd4eaa53e64031a4a118..1bafe994da2213ac3297b3badea9abb904d1e6e5 100644 (file)
@@ -54,5 +54,7 @@ extern void chkp_copy_bounds_for_assign (gimple assign,
 extern bool chkp_gimple_call_builtin_p (gimple call,
                                        enum built_in_function code);
 extern void chkp_expand_bounds_reset_for_mem (tree mem, tree ptr);
+extern tree chkp_insert_retbnd_call (tree bndval, tree retval,
+                                    gimple_stmt_iterator *gsi);
 
 #endif /* GCC_TREE_CHKP_H */