re PR fortran/78758 (Warning: '__builtin_memcpy' ... overflows the destination for...
authorJakub Jelinek <jakub@redhat.com>
Sat, 10 Dec 2016 08:02:21 +0000 (09:02 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 10 Dec 2016 08:02:21 +0000 (09:02 +0100)
PR fortran/78758
* tree-object-size.c (compute_object_offset) <case ARRAY_REF>: 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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr38868.f
gcc/testsuite/gfortran.dg/pr78758.f90 [new file with mode: 0644]
gcc/tree-object-size.c

index 93f4556e39f2179de0a712a0e5bdf8c21a62bb95..883bf48b36ad00235f0eff947c911cb5a13a8895 100644 (file)
@@ -1,5 +1,9 @@
 2016-12-10  Jakub Jelinek  <jakub@redhat.com>
 
+       PR fortran/78758
+       * tree-object-size.c (compute_object_offset) <case ARRAY_REF>: 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
index 6c86182a8e570f5c340f9d0cb44e1800396d29a4..3760c66e1078d25c27f5417ace939f0abd950b5a 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/78758
+       * gfortran.dg/pr78758.f90: New test.
+       * gfortran.dg/pr38868.f: Remove again bogus warning.
+
 2016-12-09  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/77903
index 583bf901b4ef733867bece84e000dcfa22964775..a8c4469f089be53c4a3c89ce4415c0088ac21e95 100644 (file)
@@ -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 (file)
index 0000000..3fd3352
--- /dev/null
@@ -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
index 1317ad7ee9a768d296042806ae7afb37fccd2635..0fae183b330a33b86c544cf733a5a6447fca8369 100644 (file)
@@ -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: