tree-chkp.c (chkp_call_returns_bounds_p): Fix handling of bounds narrowing...
authorIlya Enkovich <ilya.enkovich@intel.com>
Tue, 27 Jan 2015 09:09:28 +0000 (09:09 +0000)
committerIlya Enkovich <ienkovich@gcc.gnu.org>
Tue, 27 Jan 2015 09:09:28 +0000 (09:09 +0000)
gcc/

* tree-chkp.c (chkp_call_returns_bounds_p): Fix handling of
bounds narrowing, already instrumented calls and calls to
not instrumentable functions.

gcc/testsuite/

* gcc.target/i386/chkp-narrow-bounds.c: New.

From-SVN: r220154

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c [new file with mode: 0644]
gcc/tree-chkp.c

index 05b5f74665cc925121a3e709dc62c27019320cb2..5597e32b3f9c2325505cf8c0c0124843c1de3267 100644 (file)
@@ -1,3 +1,9 @@
+2015-01-27  Ilya Enkovich  <ilya.enkovich@intel.com>
+
+       * tree-chkp.c (chkp_call_returns_bounds_p): Fix handling of
+       bounds narrowing, already instrumented calls and calls to
+       not instrumentable functions.
+
 2015-01-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/64807
index f148ca15ed1da3d6ec81ac6af97f0606bcb31948..0686fa7caaa4fc91bba94b1c2fea3938e90ce8ec 100644 (file)
@@ -1,3 +1,7 @@
+2015-01-27  Ilya Enkovich  <ilya.enkovich@intel.com>
+
+       * gcc.target/i386/chkp-narrow-bounds.c: New.
+
 2015-01-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/64807
diff --git a/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c b/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c
new file mode 100644 (file)
index 0000000..28bc622
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target mpx } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-chkp" } */
+/* { dg-final { scan-tree-dump "bndcl" "chkp" } } */
+/* { dg-final { scan-tree-dump "bndcu" "chkp" } } */
+/* { dg-final { cleanup-tree-dump "chkp" } } */
+
+int
+test (int *p)
+{
+  int *p1 = __bnd_narrow_ptr_bounds (p - 10, p, sizeof (int) * 20);
+  return p1[10];
+}
index e7649effd97f99e8c5e5b22f93fe3333401f9c42..b0a3a1547ffe965e59551e010129bb0ee5446e89 100644 (file)
@@ -2113,13 +2113,19 @@ chkp_call_returns_bounds_p (gcall *call)
   if (gimple_call_internal_p (call))
     return false;
 
+  if (gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW_PTR_BOUNDS)
+      || chkp_gimple_call_builtin_p (call, BUILT_IN_CHKP_NARROW))
+    return true;
+
+  if (gimple_call_with_bounds_p (call))
+    return true;
+
   tree fndecl = gimple_call_fndecl (call);
 
   if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
     return false;
 
-  if (fndecl
-      && lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (fndecl)))
+  if (fndecl && !chkp_instrumentable_p (fndecl))
     return false;
 
   if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)