From: Jakub Jelinek Date: Sat, 10 Dec 2016 08:02:21 +0000 (+0100) Subject: re PR fortran/78758 (Warning: '__builtin_memcpy' ... overflows the destination for... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2d4102c5cbe74a27b7ec64e3d90404e3d3707b6f;p=gcc.git re PR fortran/78758 (Warning: '__builtin_memcpy' ... overflows the destination for string assignment) PR fortran/78758 * tree-object-size.c (compute_object_offset) : Handle non-zero low bound or non-standard element sizes. * gfortran.dg/pr78758.f90: New test. * gfortran.dg/pr38868.f: Remove again bogus warning. From-SVN: r243515 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 93f4556e39f..883bf48b36a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2016-12-10 Jakub Jelinek + PR fortran/78758 + * tree-object-size.c (compute_object_offset) : Handle + non-zero low bound or non-standard element sizes. + PR sanitizer/78708 * lto-streamer-in.c (input_function): In addition to debug stmts without -g, remove IFN_*SAN_* calls if corresponding flag_sanitize diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c86182a8e5..3760c66e107 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-12-10 Jakub Jelinek + + PR fortran/78758 + * gfortran.dg/pr78758.f90: New test. + * gfortran.dg/pr38868.f: Remove again bogus warning. + 2016-12-09 Paul Thomas PR fortran/77903 diff --git a/gcc/testsuite/gfortran.dg/pr38868.f b/gcc/testsuite/gfortran.dg/pr38868.f index 583bf901b4e..a8c4469f089 100644 --- a/gcc/testsuite/gfortran.dg/pr38868.f +++ b/gcc/testsuite/gfortran.dg/pr38868.f @@ -9,7 +9,7 @@ ANER(1)='A ' ANER(2)=' ' LINE=' ' - LINE(78:80)='xyz' ! { dg-warning "writing 3 bytes into a region of size 2" } + LINE(78:80)='xyz' WRITE(*,'(A82)') "'"//LINE//"'" END diff --git a/gcc/testsuite/gfortran.dg/pr78758.f90 b/gcc/testsuite/gfortran.dg/pr78758.f90 new file mode 100644 index 00000000000..3fd335287e9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr78758.f90 @@ -0,0 +1,11 @@ +! PR fortran/78758 +! { dg-do compile } +! { dg-options "-O2 -Wall" } + +integer function pr78758 (x) + character(len=*), intent(in) :: x + character(len=16) :: y + integer, external :: z + y(2:) = " " // adjustl (x(2:)) + pr78758 = z (y) +end function pr78758 diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 1317ad7ee9a..0fae183b330 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -138,13 +138,18 @@ compute_object_offset (const_tree expr, const_tree var) return base; t = TREE_OPERAND (expr, 1); + tree low_bound, unit_size; + low_bound = array_ref_low_bound (CONST_CAST_TREE (expr)); + unit_size = array_ref_element_size (CONST_CAST_TREE (expr)); + if (! integer_zerop (low_bound)) + t = fold_build2 (MINUS_EXPR, TREE_TYPE (t), t, low_bound); if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) < 0) { code = MINUS_EXPR; t = fold_build1 (NEGATE_EXPR, TREE_TYPE (t), t); } t = fold_convert (sizetype, t); - off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t); + off = size_binop (MULT_EXPR, unit_size, t); break; case MEM_REF: