Hi!

This function accesses arguments of builtin call without checking
the right arguments are actually provided.  Fixed thusly,
bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

The is_gimple_call in there is meant as a performance thing, we could
call gimple_call_builtin_p first and then only check
gimple_call_with_bounds_p, but that would unnecessarily test compatibility
of arguments even for calls without bounds.

2017-02-21  Jakub Jelinek  <ja...@redhat.com>

        PR target/79633
        * tree-chkp-opt.c (chkp_optimize_string_function_calls): Use
        is_gimple_call instead of comparing gimple_code with GIMPLE_CALL.
        Use gimple_call_builtin_p.

        * gcc.target/i386/mpx/pr79633.c: New test.

--- gcc/tree-chkp-opt.c.jj      2017-01-01 12:45:37.000000000 +0100
+++ gcc/tree-chkp-opt.c 2017-02-21 12:06:44.163025698 +0100
@@ -964,15 +964,12 @@ chkp_optimize_string_function_calls (voi
          gimple *stmt = gsi_stmt (i);
          tree fndecl;
 
-         if (gimple_code (stmt) != GIMPLE_CALL
-             || !gimple_call_with_bounds_p (stmt))
+         if (!is_gimple_call (stmt)
+             || !gimple_call_with_bounds_p (stmt)
+             || !gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
            continue;
 
          fndecl = gimple_call_fndecl (stmt);
-
-         if (!fndecl || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
-           continue;
-
          if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMCPY_CHKP
              || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMPCPY_CHKP
              || DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MEMMOVE_CHKP
--- gcc/testsuite/gcc.target/i386/mpx/pr79633.c.jj      2017-02-21 
12:09:54.034537817 +0100
+++ gcc/testsuite/gcc.target/i386/mpx/pr79633.c 2017-02-21 12:09:29.000000000 
+0100
@@ -0,0 +1,11 @@
+/* PR target/79633 */
+/* { dg-do compile } */
+/* { dg-options "-fcheck-pointer-bounds -mmpx -w -O2" } */
+
+extern void *memcpy ();
+
+void
+foo ()
+{
+  memcpy ();
+}

        Jakub

Reply via email to