The gfortran.dg/lto/pr87689 test fails as a result of
a -Wstringop-overflow warning.  The warning is only enabled for
the C family of languages and LTO but it looks like LTO obviates
this distinction.  Last week's enhancement to compute_objsize
seems like the most likely culprit, although the root cause of
the problem -- assuming array indices begin with zero, was
probably latent before then.  In r279445 I have committed
the attached patch to remove the assumption that array indices
are zero-based to let the test pass again.

Martin
PR middle-end/92952 - gfortran.dg/lto/pr87689 FAILs

gcc/ChangeLog:

	PR middle-end/92952
	* builtins.c (compute_objsize): Adjust offset by the array low bound.

Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 279443)
+++ gcc/builtins.c	(working copy)
@@ -3999,6 +3999,16 @@ compute_objsize (tree dest, int ostype, tree *pdec
 	     above.  */
 	  if (TREE_CODE (dest) == ARRAY_REF)
 	    {
+	      tree lowbnd = array_ref_low_bound (dest);
+	      if (!integer_zerop (lowbnd) && tree_fits_uhwi_p (lowbnd))
+		{
+		  /* Adjust the offset by the low bound of the array
+		     domain (normally zero but 1 in Fortran).  */
+		  unsigned HOST_WIDE_INT lb = tree_to_uhwi (lowbnd);
+		  offrng[0] -= lb;
+		  offrng[1] -= lb;
+		}
+
 	      /* Convert the array index into a byte offset.  */
 	      tree eltype = TREE_TYPE (dest);
 	      tree tpsize = TYPE_SIZE_UNIT (eltype);

Reply via email to