diff mbox

[CHKP] Fix bounds return check for calls

Message ID 20150126164548.GA47190@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Jan. 26, 2015, 4:45 p.m. UTC
Hi,

Currently chkp_call_returns_bounds_p works incorrectly for bounds narrowing.  Also it doesn't reflect recent changes in calls instrumentation.  This patch fixes the problem.

Bootstrapped and checked on x86_64-unknown-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
2015-01-26  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-26  Ilya Enkovich  <ilya.enkovich@intel.com>

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

Comments

Jeff Law Jan. 26, 2015, 10:01 p.m. UTC | #1
On 01/26/15 09:45, Ilya Enkovich wrote:
> Hi,
>
> Currently chkp_call_returns_bounds_p works incorrectly for bounds narrowing.  Also it doesn't reflect recent changes in calls instrumentation.  This patch fixes the problem.
>
> Bootstrapped and checked on x86_64-unknown-linux-gnu.  OK for trunk?
>
> Thanks,
> Ilya
> --
> 2015-01-26  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-26  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* gcc.target/i386/chkp-narrow-bounds.c: New.
OK.
jeff
diff mbox

Patch

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
index 0000000..28bc622
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/chkp-narrow-bounds.c
@@ -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];
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index e7649ef..b0a3a15 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -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)