aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2018-11-04 19:51:09 +0000
committerBernd Edlinger <edlinger@gcc.gnu.org>2018-11-04 19:51:09 +0000
commite8bf3d5ed983791a658b86f4eae338e13b6fdc3f (patch)
treecbca26e118c1d2a7c2ab243b2d4405fbd561b565 /gcc/builtins.c
parent770fe3a36400fb03d0936cff86ffb76a136d5674 (diff)
downloadgcc-e8bf3d5ed983791a658b86f4eae338e13b6fdc3f.zip
gcc-e8bf3d5ed983791a658b86f4eae338e13b6fdc3f.tar.gz
gcc-e8bf3d5ed983791a658b86f4eae338e13b6fdc3f.tar.bz2
re PR tree-optimization/86572 (unsafe strlen folding of const arguments with non-const offset)
gcc: 2018-11-04 Bernd Edlinger <bernd.edlinger@hotmail.de> PR tree-optimization/86572 * builtins.c (c_strlen): Handle negative offsets in a safe way. testsuite: 2018-11-04 Bernd Edlinger <bernd.edlinger@hotmail.de> PR tree-optimization/86572 * gcc.dg/pr86572.c: New test. From-SVN: r265778
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index f64b3d4..9f2a90a 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -734,11 +734,14 @@ c_strlen (tree src, int only_value, c_strlen_data *data, unsigned eltsize)
of the string subtract the offset from the length of the string,
and return that. Otherwise the length is zero. Take care to
use SAVE_EXPR in case the OFFSET has side-effects. */
- tree offsave = TREE_SIDE_EFFECTS (byteoff) ? save_expr (byteoff) : byteoff;
- offsave = fold_convert (ssizetype, offsave);
+ tree offsave = TREE_SIDE_EFFECTS (byteoff) ? save_expr (byteoff)
+ : byteoff;
+ offsave = fold_convert_loc (loc, sizetype, offsave);
tree condexp = fold_build2_loc (loc, LE_EXPR, boolean_type_node, offsave,
- build_int_cst (ssizetype, len));
- tree lenexp = size_diffop_loc (loc, ssize_int (len), offsave);
+ size_int (len));
+ tree lenexp = fold_build2_loc (loc, MINUS_EXPR, sizetype, size_int (len),
+ offsave);
+ lenexp = fold_convert_loc (loc, ssizetype, lenexp);
return fold_build3_loc (loc, COND_EXPR, ssizetype, condexp, lenexp,
build_zero_cst (ssizetype));
}