]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/68337 ([MPX] memcpy() for arrays with function pointers results in huge resou...
authorIlya Enkovich <enkovich.gnu@gmail.com>
Tue, 24 Nov 2015 09:45:20 +0000 (09:45 +0000)
committerIlya Enkovich <ienkovich@gcc.gnu.org>
Tue, 24 Nov 2015 09:45:20 +0000 (09:45 +0000)
gcc/

PR c/68337
* gimple-fold.c: Include ipa-chkp.h.
(gimple_fold_builtin_memory_op): Don't fold call if we
are going to instrument it and it may copy pointers.

gcc/testsuite/

PR c/68337
* gcc.target/i386/mpx/pr68337-1.c: New test.
* gcc.target/i386/mpx/pr68337-2.c: New test.

From-SVN: r230796

gcc/ChangeLog
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c [new file with mode: 0644]

index 323c4a87426f2649244e1c565c8de23453f29603..d8a58721eb5a63dc18cfe9bd3ae47a0d72a86493 100644 (file)
@@ -1,3 +1,10 @@
+2015-11-24  Ilya Enkovich  <enkovich.gnu@gmail.com>
+
+       PR c/68337
+       * gimple-fold.c: Include ipa-chkp.h.
+       (gimple_fold_builtin_memory_op): Don't fold call if we
+       are going to instrument it and it may copy pointers.
+
 2015-11-24  Bernd Schmidt <bschmidt@redhat.com>
             Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
index 1ab20d11fa76fc1642411e53f339f1ee6ff2181f..6ff5e266d420a94b80cf1db12d45784b3fc26214 100644 (file)
@@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gomp-constants.h"
 #include "optabs-query.h"
 #include "omp-low.h"
+#include "ipa-chkp.h"
 
 
 /* Return true when DECL can be referenced from current unit.
@@ -664,6 +665,18 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
       unsigned int src_align, dest_align;
       tree off0;
 
+      /* Inlining of memcpy/memmove may cause bounds lost (if we copy
+        pointers as wide integer) and also may result in huge function
+        size because of inlined bounds copy.  Thus don't inline for
+        functions we want to instrument.  */
+      if (flag_check_pointer_bounds
+         && chkp_instrumentable_p (cfun->decl)
+         /* Even if data may contain pointers we can inline if copy
+            less than a pointer size.  */
+         && (!tree_fits_uhwi_p (len)
+             || compare_tree_int (len, POINTER_SIZE_UNITS) >= 0))
+       return false;
+
       /* Build accesses at offset zero with a ref-all character type.  */
       off0 = build_int_cst (build_pointer_type_for_mode (char_type_node,
                                                         ptr_mode, true), 0);
index 522b24bc0581d9cab7594304b9f61b0515b94e79..6c98a6fe51fc1a527bf9ca445faed39072396a5a 100644 (file)
@@ -1,3 +1,9 @@
+2015-11-24  Ilya Enkovich  <enkovich.gnu@gmail.com>
+
+       PR c/68337
+       * gcc.target/i386/mpx/pr68337-1.c: New test.
+       * gcc.target/i386/mpx/pr68337-2.c: New test.
+
 2015-11-24  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
        PR rtl-optimization/68194
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c b/gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c
new file mode 100644 (file)
index 0000000..3f8d79d
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
+
+#include "mpx-check.h"
+
+#define N 2
+
+extern void abort ();
+
+static int
+mpx_test (int argc, const char **argv)
+{
+  char ** src = (char **)malloc (sizeof (char *) * N);
+  char ** dst = (char **)malloc (sizeof (char *) * N);
+  int i;
+
+  for (i = 0; i < N; i++)
+    src[i] = __bnd_set_ptr_bounds (argv[0] + i, i + 1);
+
+  __builtin_memcpy(dst, src, sizeof (char *) * N);
+
+  for (i = 0; i < N; i++)
+    {
+      char *p = dst[i];
+      if (p != argv[0] + i
+         || __bnd_get_ptr_lbound (p) != p
+         || __bnd_get_ptr_ubound (p) != p + i)
+       abort ();
+    }
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c b/gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c
new file mode 100644 (file)
index 0000000..8845cca
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
+/* { dg-final { scan-assembler-not "memcpy" } } */
+
+void
+test (void *dst, void *src)
+{
+  __builtin_memcpy (dst, src, sizeof (char *) / 2);
+}