Commit f5fc4a04 by Ilya Enkovich Committed by Ilya Enkovich

tree-ssa-strlen.c: include ipa-chkp.h, cgraph.h, ipa-ref.h, plugin-api.h.

gcc/

	* tree-ssa-strlen.c: include ipa-chkp.h, cgraph.h,
	ipa-ref.h, plugin-api.h.
	(get_string_length): Handle calls with bounds.
	(adjust_last_stmt): Likewise.
	(handle_builtin_strchr): Likewise.
	(handle_builtin_strcpy): Likewise.
	(handle_builtin_memcpy): Likewise.
	(handle_builtin_strcat): Likewise.

gcc/testsuite/

	* gcc.target/i386/chkp-strlen-1.c: New.
	* gcc.target/i386/chkp-strlen-2.c: New.
	* gcc.target/i386/chkp-strlen-3.c: New.
	* gcc.target/i386/chkp-strlen-4.c: New.
	* gcc.target/i386/chkp-strlen-5.c: New.

From-SVN: r217657
parent e4727812
2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com> 2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com>
* tree-ssa-strlen.c: include ipa-chkp.h, cgraph.h,
ipa-ref.h, plugin-api.h.
(get_string_length): Handle calls with bounds.
(adjust_last_stmt): Likewise.
(handle_builtin_strchr): Likewise.
(handle_builtin_strcpy): Likewise.
(handle_builtin_memcpy): Likewise.
(handle_builtin_strcat): Likewise.
2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com>
* tree-chkp-opt.c (chkp_get_nobnd_fndecl): New. * tree-chkp-opt.c (chkp_get_nobnd_fndecl): New.
(chkp_get_nochk_fndecl): New. (chkp_get_nochk_fndecl): New.
(chkp_optimize_string_function_calls): New. (chkp_optimize_string_function_calls): New.
2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com> 2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com>
* gcc.target/i386/chkp-strlen-1.c: New.
* gcc.target/i386/chkp-strlen-2.c: New.
* gcc.target/i386/chkp-strlen-3.c: New.
* gcc.target/i386/chkp-strlen-4.c: New.
* gcc.target/i386/chkp-strlen-5.c: New.
2014-11-17 Ilya Enkovich <ilya.enkovich@intel.com>
* gcc.target/i386/chkp-stropt-1.c: New. * gcc.target/i386/chkp-stropt-1.c: New.
* gcc.target/i386/chkp-stropt-2.c: New. * gcc.target/i386/chkp-stropt-2.c: New.
* gcc.target/i386/chkp-stropt-3.c: New. * gcc.target/i386/chkp-stropt-3.c: New.
......
/* { dg-do compile } */
/* { dg-require-effective-target mpx } */
/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-strlen" } */
/* { dg-final { scan-tree-dump "memcpy.chkp" "strlen" } } */
/* { dg-final { cleanup-tree-dump "strlen" } } */
#include "string.h"
char *test (char *str1, char *str2)
{
size_t len = strlen (str2);
strcpy (str1, str2);
return str1 + len;
}
/* { dg-do compile } */
/* { dg-require-effective-target mpx } */
/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-strlen" } */
/* { dg-final { scan-tree-dump-not "strlen" "strlen" } } */
/* { dg-final { cleanup-tree-dump "strlen" } } */
#include "string.h"
char *test (char *str1, char *str2)
{
char *p = stpcpy (str1, str2);
size_t len = strlen (str1);
return p + len;
}
/* { dg-do compile } */
/* { dg-require-effective-target mpx } */
/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-strlen" } */
/* { dg-final { scan-tree-dump-times "strlen" 1 "strlen" } } */
/* { dg-final { cleanup-tree-dump "strlen" } } */
#include "string.h"
size_t test (char *str1, char *str2)
{
size_t len = strlen (str2);
memcpy (str1, str2, len + 1);
return len + strlen (str1);
}
/* { dg-do compile } */
/* { dg-require-effective-target mpx } */
/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-strlen -D_GNU_SOURCE" } */
/* { dg-final { scan-tree-dump-times "strlen" 1 "strlen" } } */
/* { dg-final { cleanup-tree-dump "strlen" } } */
#include "string.h"
char * test (char *str1, char *str2)
{
size_t len = strlen (str2);
char *p = (char *)mempcpy (str1, str2, len + 1);
return p + len + strlen (str1);
}
/* { dg-do compile } */
/* { dg-require-effective-target mpx } */
/* { dg-options "-fcheck-pointer-bounds -mmpx -O2 -fdump-tree-strlen" } */
/* { dg-final { scan-tree-dump-times "strlen" 2 "strlen" } } */
/* { dg-final { scan-tree-dump "memcpy" "strlen" } } */
/* { dg-final { cleanup-tree-dump "strlen" } } */
#include "string.h"
size_t test (char *str1, char *str2)
{
size_t len1 = strlen (str1);
size_t len2 = strlen (str2);
strcat (str1, str2);
return len1 + len2 + strlen (str1);
}
...@@ -62,6 +62,10 @@ along with GCC; see the file COPYING3. If not see ...@@ -62,6 +62,10 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-pretty-print.h" #include "gimple-pretty-print.h"
#include "params.h" #include "params.h"
#include "expr.h" #include "expr.h"
#include "plugin-api.h"
#include "ipa-ref.h"
#include "cgraph.h"
#include "ipa-chkp.h"
/* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value /* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value
is an index into strinfo vector, negative value stands for is an index into strinfo vector, negative value stands for
...@@ -417,6 +421,7 @@ get_string_length (strinfo si) ...@@ -417,6 +421,7 @@ get_string_length (strinfo si)
if (si->stmt) if (si->stmt)
{ {
gimple stmt = si->stmt, lenstmt; gimple stmt = si->stmt, lenstmt;
bool with_bounds = gimple_call_with_bounds_p (stmt);
tree callee, lhs, fn, tem; tree callee, lhs, fn, tem;
location_t loc; location_t loc;
gimple_stmt_iterator gsi; gimple_stmt_iterator gsi;
...@@ -436,10 +441,19 @@ get_string_length (strinfo si) ...@@ -436,10 +441,19 @@ get_string_length (strinfo si)
{ {
case BUILT_IN_STRCAT: case BUILT_IN_STRCAT:
case BUILT_IN_STRCAT_CHK: case BUILT_IN_STRCAT_CHK:
case BUILT_IN_STRCAT_CHKP:
case BUILT_IN_STRCAT_CHK_CHKP:
gsi = gsi_for_stmt (stmt); gsi = gsi_for_stmt (stmt);
fn = builtin_decl_implicit (BUILT_IN_STRLEN); fn = builtin_decl_implicit (BUILT_IN_STRLEN);
gcc_assert (lhs == NULL_TREE); gcc_assert (lhs == NULL_TREE);
tem = unshare_expr (gimple_call_arg (stmt, 0)); tem = unshare_expr (gimple_call_arg (stmt, 0));
if (with_bounds)
{
lenstmt = gimple_build_call (chkp_maybe_create_clone (fn)->decl,
2, tem, gimple_call_arg (stmt, 1));
gimple_call_set_with_bounds (lenstmt, true);
}
else
lenstmt = gimple_build_call (fn, 1, tem); lenstmt = gimple_build_call (fn, 1, tem);
lhs = make_ssa_name (TREE_TYPE (TREE_TYPE (fn)), lenstmt); lhs = make_ssa_name (TREE_TYPE (TREE_TYPE (fn)), lenstmt);
gimple_call_set_lhs (lenstmt, lhs); gimple_call_set_lhs (lenstmt, lhs);
...@@ -463,10 +477,14 @@ get_string_length (strinfo si) ...@@ -463,10 +477,14 @@ get_string_length (strinfo si)
/* FALLTHRU */ /* FALLTHRU */
case BUILT_IN_STRCPY: case BUILT_IN_STRCPY:
case BUILT_IN_STRCPY_CHK: case BUILT_IN_STRCPY_CHK:
if (gimple_call_num_args (stmt) == 2) case BUILT_IN_STRCPY_CHKP:
case BUILT_IN_STRCPY_CHK_CHKP:
if (gimple_call_num_args (stmt) == (with_bounds ? 4 : 2))
fn = builtin_decl_implicit (BUILT_IN_STPCPY); fn = builtin_decl_implicit (BUILT_IN_STPCPY);
else else
fn = builtin_decl_explicit (BUILT_IN_STPCPY_CHK); fn = builtin_decl_explicit (BUILT_IN_STPCPY_CHK);
if (with_bounds)
fn = chkp_maybe_create_clone (fn)->decl;
gcc_assert (lhs == NULL_TREE); gcc_assert (lhs == NULL_TREE);
if (dump_file && (dump_flags & TDF_DETAILS) != 0) if (dump_file && (dump_flags & TDF_DETAILS) != 0)
{ {
...@@ -485,6 +503,8 @@ get_string_length (strinfo si) ...@@ -485,6 +503,8 @@ get_string_length (strinfo si)
/* FALLTHRU */ /* FALLTHRU */
case BUILT_IN_STPCPY: case BUILT_IN_STPCPY:
case BUILT_IN_STPCPY_CHK: case BUILT_IN_STPCPY_CHK:
case BUILT_IN_STPCPY_CHKP:
case BUILT_IN_STPCPY_CHK_CHKP:
gcc_assert (lhs != NULL_TREE); gcc_assert (lhs != NULL_TREE);
loc = gimple_location (stmt); loc = gimple_location (stmt);
si->endptr = lhs; si->endptr = lhs;
...@@ -775,6 +795,7 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat) ...@@ -775,6 +795,7 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat)
tree vuse, callee, len; tree vuse, callee, len;
struct laststmt_struct last = laststmt; struct laststmt_struct last = laststmt;
strinfo lastsi, firstsi; strinfo lastsi, firstsi;
unsigned len_arg_no = 2;
laststmt.stmt = NULL; laststmt.stmt = NULL;
laststmt.len = NULL_TREE; laststmt.len = NULL_TREE;
...@@ -846,11 +867,15 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat) ...@@ -846,11 +867,15 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat)
case BUILT_IN_MEMCPY: case BUILT_IN_MEMCPY:
case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMCPY_CHK:
break; break;
case BUILT_IN_MEMCPY_CHKP:
case BUILT_IN_MEMCPY_CHK_CHKP:
len_arg_no = 4;
break;
default: default:
return; return;
} }
len = gimple_call_arg (last.stmt, 2); len = gimple_call_arg (last.stmt, len_arg_no);
if (tree_fits_uhwi_p (len)) if (tree_fits_uhwi_p (len))
{ {
if (!tree_fits_uhwi_p (last.len) if (!tree_fits_uhwi_p (last.len)
...@@ -874,7 +899,7 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat) ...@@ -874,7 +899,7 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat)
else else
return; return;
gimple_call_set_arg (last.stmt, 2, last.len); gimple_call_set_arg (last.stmt, len_arg_no, last.len);
update_stmt (last.stmt); update_stmt (last.stmt);
} }
...@@ -965,11 +990,12 @@ handle_builtin_strchr (gimple_stmt_iterator *gsi) ...@@ -965,11 +990,12 @@ handle_builtin_strchr (gimple_stmt_iterator *gsi)
tree src; tree src;
gimple stmt = gsi_stmt (*gsi); gimple stmt = gsi_stmt (*gsi);
tree lhs = gimple_call_lhs (stmt); tree lhs = gimple_call_lhs (stmt);
bool with_bounds = gimple_call_with_bounds_p (stmt);
if (lhs == NULL_TREE) if (lhs == NULL_TREE)
return; return;
if (!integer_zerop (gimple_call_arg (stmt, 1))) if (!integer_zerop (gimple_call_arg (stmt, with_bounds ? 2 : 1)))
return; return;
src = gimple_call_arg (stmt, 0); src = gimple_call_arg (stmt, 0);
...@@ -1076,8 +1102,9 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1076,8 +1102,9 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
gimple stmt = gsi_stmt (*gsi); gimple stmt = gsi_stmt (*gsi);
strinfo si, dsi, olddsi, zsi; strinfo si, dsi, olddsi, zsi;
location_t loc; location_t loc;
bool with_bounds = gimple_call_with_bounds_p (stmt);
src = gimple_call_arg (stmt, 1); src = gimple_call_arg (stmt, with_bounds ? 2 : 1);
dst = gimple_call_arg (stmt, 0); dst = gimple_call_arg (stmt, 0);
lhs = gimple_call_lhs (stmt); lhs = gimple_call_lhs (stmt);
idx = get_stridx (src); idx = get_stridx (src);
...@@ -1108,11 +1135,15 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1108,11 +1135,15 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
{ {
case BUILT_IN_STRCPY: case BUILT_IN_STRCPY:
case BUILT_IN_STRCPY_CHK: case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STRCPY_CHKP:
case BUILT_IN_STRCPY_CHK_CHKP:
if (lhs != NULL_TREE || !builtin_decl_implicit_p (BUILT_IN_STPCPY)) if (lhs != NULL_TREE || !builtin_decl_implicit_p (BUILT_IN_STPCPY))
return; return;
break; break;
case BUILT_IN_STPCPY: case BUILT_IN_STPCPY:
case BUILT_IN_STPCPY_CHK: case BUILT_IN_STPCPY_CHK:
case BUILT_IN_STPCPY_CHKP:
case BUILT_IN_STPCPY_CHK_CHKP:
if (lhs == NULL_TREE) if (lhs == NULL_TREE)
return; return;
else else
...@@ -1211,16 +1242,19 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1211,16 +1242,19 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
switch (bcode) switch (bcode)
{ {
case BUILT_IN_STRCPY: case BUILT_IN_STRCPY:
case BUILT_IN_STRCPY_CHKP:
fn = builtin_decl_implicit (BUILT_IN_MEMCPY); fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
if (lhs) if (lhs)
ssa_ver_to_stridx[SSA_NAME_VERSION (lhs)] = didx; ssa_ver_to_stridx[SSA_NAME_VERSION (lhs)] = didx;
break; break;
case BUILT_IN_STRCPY_CHK: case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STRCPY_CHK_CHKP:
fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK); fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK);
if (lhs) if (lhs)
ssa_ver_to_stridx[SSA_NAME_VERSION (lhs)] = didx; ssa_ver_to_stridx[SSA_NAME_VERSION (lhs)] = didx;
break; break;
case BUILT_IN_STPCPY: case BUILT_IN_STPCPY:
case BUILT_IN_STPCPY_CHKP:
/* This would need adjustment of the lhs (subtract one), /* This would need adjustment of the lhs (subtract one),
or detection that the trailing '\0' doesn't need to be or detection that the trailing '\0' doesn't need to be
written, if it will be immediately overwritten. written, if it will be immediately overwritten.
...@@ -1232,6 +1266,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1232,6 +1266,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
} }
break; break;
case BUILT_IN_STPCPY_CHK: case BUILT_IN_STPCPY_CHK:
case BUILT_IN_STPCPY_CHK_CHKP:
/* This would need adjustment of the lhs (subtract one), /* This would need adjustment of the lhs (subtract one),
or detection that the trailing '\0' doesn't need to be or detection that the trailing '\0' doesn't need to be
written, if it will be immediately overwritten. written, if it will be immediately overwritten.
...@@ -1263,6 +1298,24 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1263,6 +1298,24 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
fprintf (dump_file, "Optimizing: "); fprintf (dump_file, "Optimizing: ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
} }
if (with_bounds)
{
fn = chkp_maybe_create_clone (fn)->decl;
if (gimple_call_num_args (stmt) == 4)
success = update_gimple_call (gsi, fn, 5, dst,
gimple_call_arg (stmt, 1),
src,
gimple_call_arg (stmt, 3),
len);
else
success = update_gimple_call (gsi, fn, 6, dst,
gimple_call_arg (stmt, 1),
src,
gimple_call_arg (stmt, 3),
len,
gimple_call_arg (stmt, 4));
}
else
if (gimple_call_num_args (stmt) == 2) if (gimple_call_num_args (stmt) == 2)
success = update_gimple_call (gsi, fn, 3, dst, src, len); success = update_gimple_call (gsi, fn, 3, dst, src, len);
else else
...@@ -1271,6 +1324,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1271,6 +1324,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
if (success) if (success)
{ {
stmt = gsi_stmt (*gsi); stmt = gsi_stmt (*gsi);
gimple_call_set_with_bounds (stmt, with_bounds);
update_stmt (stmt); update_stmt (stmt);
if (dump_file && (dump_flags & TDF_DETAILS) != 0) if (dump_file && (dump_flags & TDF_DETAILS) != 0)
{ {
...@@ -1298,9 +1352,10 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1298,9 +1352,10 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
tree src, dst, len, lhs, oldlen, newlen; tree src, dst, len, lhs, oldlen, newlen;
gimple stmt = gsi_stmt (*gsi); gimple stmt = gsi_stmt (*gsi);
strinfo si, dsi, olddsi; strinfo si, dsi, olddsi;
bool with_bounds = gimple_call_with_bounds_p (stmt);
len = gimple_call_arg (stmt, 2); len = gimple_call_arg (stmt, with_bounds ? 4 : 2);
src = gimple_call_arg (stmt, 1); src = gimple_call_arg (stmt, with_bounds ? 2 : 1);
dst = gimple_call_arg (stmt, 0); dst = gimple_call_arg (stmt, 0);
idx = get_stridx (src); idx = get_stridx (src);
if (idx == 0) if (idx == 0)
...@@ -1407,6 +1462,8 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1407,6 +1462,8 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
{ {
case BUILT_IN_MEMCPY: case BUILT_IN_MEMCPY:
case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMCPY_CHK:
case BUILT_IN_MEMCPY_CHKP:
case BUILT_IN_MEMCPY_CHK_CHKP:
/* Allow adjust_last_stmt to decrease this memcpy's size. */ /* Allow adjust_last_stmt to decrease this memcpy's size. */
laststmt.stmt = stmt; laststmt.stmt = stmt;
laststmt.len = dsi->length; laststmt.len = dsi->length;
...@@ -1416,6 +1473,8 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1416,6 +1473,8 @@ handle_builtin_memcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
break; break;
case BUILT_IN_MEMPCPY: case BUILT_IN_MEMPCPY:
case BUILT_IN_MEMPCPY_CHK: case BUILT_IN_MEMPCPY_CHK:
case BUILT_IN_MEMPCPY_CHKP:
case BUILT_IN_MEMPCPY_CHK_CHKP:
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1437,8 +1496,9 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1437,8 +1496,9 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
gimple stmt = gsi_stmt (*gsi); gimple stmt = gsi_stmt (*gsi);
strinfo si, dsi; strinfo si, dsi;
location_t loc; location_t loc;
bool with_bounds = gimple_call_with_bounds_p (stmt);
src = gimple_call_arg (stmt, 1); src = gimple_call_arg (stmt, with_bounds ? 2 : 1);
dst = gimple_call_arg (stmt, 0); dst = gimple_call_arg (stmt, 0);
lhs = gimple_call_lhs (stmt); lhs = gimple_call_lhs (stmt);
...@@ -1534,17 +1594,19 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1534,17 +1594,19 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
switch (bcode) switch (bcode)
{ {
case BUILT_IN_STRCAT: case BUILT_IN_STRCAT:
case BUILT_IN_STRCAT_CHKP:
if (srclen != NULL_TREE) if (srclen != NULL_TREE)
fn = builtin_decl_implicit (BUILT_IN_MEMCPY); fn = builtin_decl_implicit (BUILT_IN_MEMCPY);
else else
fn = builtin_decl_implicit (BUILT_IN_STRCPY); fn = builtin_decl_implicit (BUILT_IN_STRCPY);
break; break;
case BUILT_IN_STRCAT_CHK: case BUILT_IN_STRCAT_CHK:
case BUILT_IN_STRCAT_CHK_CHKP:
if (srclen != NULL_TREE) if (srclen != NULL_TREE)
fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK); fn = builtin_decl_explicit (BUILT_IN_MEMCPY_CHK);
else else
fn = builtin_decl_explicit (BUILT_IN_STRCPY_CHK); fn = builtin_decl_explicit (BUILT_IN_STRCPY_CHK);
objsz = gimple_call_arg (stmt, 2); objsz = gimple_call_arg (stmt, with_bounds ? 4 : 2);
break; break;
default: default:
gcc_unreachable (); gcc_unreachable ();
...@@ -1579,6 +1641,25 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1579,6 +1641,25 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
fprintf (dump_file, "Optimizing: "); fprintf (dump_file, "Optimizing: ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
} }
if (with_bounds)
{
fn = chkp_maybe_create_clone (fn)->decl;
if (srclen != NULL_TREE)
success = update_gimple_call (gsi, fn, 5 + (objsz != NULL_TREE),
dst,
gimple_call_arg (stmt, 1),
src,
gimple_call_arg (stmt, 3),
len, objsz);
else
success = update_gimple_call (gsi, fn, 4 + (objsz != NULL_TREE),
dst,
gimple_call_arg (stmt, 1),
src,
gimple_call_arg (stmt, 3),
objsz);
}
else
if (srclen != NULL_TREE) if (srclen != NULL_TREE)
success = update_gimple_call (gsi, fn, 3 + (objsz != NULL_TREE), success = update_gimple_call (gsi, fn, 3 + (objsz != NULL_TREE),
dst, src, len, objsz); dst, src, len, objsz);
...@@ -1588,6 +1669,7 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi) ...@@ -1588,6 +1669,7 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
if (success) if (success)
{ {
stmt = gsi_stmt (*gsi); stmt = gsi_stmt (*gsi);
gimple_call_set_with_bounds (stmt, with_bounds);
update_stmt (stmt); update_stmt (stmt);
if (dump_file && (dump_flags & TDF_DETAILS) != 0) if (dump_file && (dump_flags & TDF_DETAILS) != 0)
{ {
...@@ -1901,25 +1983,37 @@ strlen_optimize_stmt (gimple_stmt_iterator *gsi) ...@@ -1901,25 +1983,37 @@ strlen_optimize_stmt (gimple_stmt_iterator *gsi)
switch (DECL_FUNCTION_CODE (callee)) switch (DECL_FUNCTION_CODE (callee))
{ {
case BUILT_IN_STRLEN: case BUILT_IN_STRLEN:
case BUILT_IN_STRLEN_CHKP:
handle_builtin_strlen (gsi); handle_builtin_strlen (gsi);
break; break;
case BUILT_IN_STRCHR: case BUILT_IN_STRCHR:
case BUILT_IN_STRCHR_CHKP:
handle_builtin_strchr (gsi); handle_builtin_strchr (gsi);
break; break;
case BUILT_IN_STRCPY: case BUILT_IN_STRCPY:
case BUILT_IN_STRCPY_CHK: case BUILT_IN_STRCPY_CHK:
case BUILT_IN_STPCPY: case BUILT_IN_STPCPY:
case BUILT_IN_STPCPY_CHK: case BUILT_IN_STPCPY_CHK:
case BUILT_IN_STRCPY_CHKP:
case BUILT_IN_STRCPY_CHK_CHKP:
case BUILT_IN_STPCPY_CHKP:
case BUILT_IN_STPCPY_CHK_CHKP:
handle_builtin_strcpy (DECL_FUNCTION_CODE (callee), gsi); handle_builtin_strcpy (DECL_FUNCTION_CODE (callee), gsi);
break; break;
case BUILT_IN_MEMCPY: case BUILT_IN_MEMCPY:
case BUILT_IN_MEMCPY_CHK: case BUILT_IN_MEMCPY_CHK:
case BUILT_IN_MEMPCPY: case BUILT_IN_MEMPCPY:
case BUILT_IN_MEMPCPY_CHK: case BUILT_IN_MEMPCPY_CHK:
case BUILT_IN_MEMCPY_CHKP:
case BUILT_IN_MEMCPY_CHK_CHKP:
case BUILT_IN_MEMPCPY_CHKP:
case BUILT_IN_MEMPCPY_CHK_CHKP:
handle_builtin_memcpy (DECL_FUNCTION_CODE (callee), gsi); handle_builtin_memcpy (DECL_FUNCTION_CODE (callee), gsi);
break; break;
case BUILT_IN_STRCAT: case BUILT_IN_STRCAT:
case BUILT_IN_STRCAT_CHK: case BUILT_IN_STRCAT_CHK:
case BUILT_IN_STRCAT_CHKP:
case BUILT_IN_STRCAT_CHK_CHKP:
handle_builtin_strcat (DECL_FUNCTION_CODE (callee), gsi); handle_builtin_strcat (DECL_FUNCTION_CODE (callee), gsi);
break; break;
case BUILT_IN_MALLOC: case BUILT_IN_MALLOC:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment