From: Jakub Jelinek Date: Tue, 19 Jul 2016 17:30:05 +0000 (+0200) Subject: re PR middle-end/71874 (memmove works wrong) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4fda19ef2b56cd04d557e44e742984e8318b5c3c;p=gcc.git re PR middle-end/71874 (memmove works wrong) PR middle-end/71874 * gimple-fold.c (fold_builtin_memory_op): Use get_addr_base_and_unit_offset instead of get_ref_base_and_extent. * g++.dg/torture/pr71874.C: New test. From-SVN: r238484 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 66657798607..a59b4b3f40e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-07-19 Jakub Jelinek + + PR middle-end/71874 + * gimple-fold.c (fold_builtin_memory_op): Use + get_addr_base_and_unit_offset instead of get_ref_base_and_extent. + 2016-07-19 Uros Bizjak * builtins.c: Use HOST_WIDE_INT_1 instead of (HOST_WIDE_INT) 1, diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 3a5008839a5..73c231445fb 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -796,22 +796,21 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, { tree src_base, dest_base, fn; HOST_WIDE_INT src_offset = 0, dest_offset = 0; - HOST_WIDE_INT size = -1; - HOST_WIDE_INT maxsize = -1; - bool reverse; + HOST_WIDE_INT maxsize; srcvar = TREE_OPERAND (src, 0); - src_base = get_ref_base_and_extent (srcvar, &src_offset, - &size, &maxsize, &reverse); + src_base = get_addr_base_and_unit_offset (srcvar, &src_offset); + if (src_base == NULL) + src_base = srcvar; destvar = TREE_OPERAND (dest, 0); - dest_base = get_ref_base_and_extent (destvar, &dest_offset, - &size, &maxsize, &reverse); + dest_base = get_addr_base_and_unit_offset (destvar, + &dest_offset); + if (dest_base == NULL) + dest_base = destvar; if (tree_fits_uhwi_p (len)) maxsize = tree_to_uhwi (len); else maxsize = -1; - src_offset /= BITS_PER_UNIT; - dest_offset /= BITS_PER_UNIT; if (SSA_VAR_P (src_base) && SSA_VAR_P (dest_base)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 00f0274a018..17fcb00d1c8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2016-07-19 Jakub Jelinek + PR middle-end/71874 + * g++.dg/torture/pr71874.C: New test. + PR middle-end/71734 * g++.dg/vect/pr70729.cc: Don't include string.h or xmmintrin.h. (my_alloc): Rewritten to use __builtin_posix_memalign and diff --git a/gcc/testsuite/g++.dg/torture/pr71874.C b/gcc/testsuite/g++.dg/torture/pr71874.C new file mode 100644 index 00000000000..d9b4e2f8849 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr71874.C @@ -0,0 +1,12 @@ +// PR middle-end/71874 +// { dg-do run } + +int +main () +{ + char str[] = "abcdefghijklmnopqrstuvwxyzABCDEF"; + __builtin_memmove (str + 20, str + 15, 11); + if (__builtin_strcmp (str, "abcdefghijklmnopqrstpqrstuvwxyzF") != 0) + __builtin_abort (); + return 0; +}