[Bug fortran/83650] [6/7/8 Regression] Wrong simplification in cshift with negative shifts
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jan 2 16:22:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83650
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|7.4 |6.5
--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Patch for gcc-7:
Index: fortran/simplify.c
===================================================================
--- fortran/simplify.c (Revision 256009)
+++ fortran/simplify.c (Arbeitskopie)
@@ -1991,7 +1991,9 @@ gfc_simplify_cshift (gfc_expr *array, gfc_expr *sh
mpz_clear (size);
/* Adjust shft to deal with right or left shifts. */
- shft = shft < 0 ? 1 - shft : shft;
+ shft = shft % sz;
+ if (shft < 0)
+ shft += sz;
/* Special case: Shift to the original order! */
if (sz == 0 || shft % sz == 0)
Index: testsuite/gfortran.dg/simplify_cshift_1.f90
===================================================================
--- testsuite/gfortran.dg/simplify_cshift_1.f90 (Revision 256009)
+++ testsuite/gfortran.dg/simplify_cshift_1.f90 (Arbeitskopie)
@@ -23,12 +23,12 @@ program foo
v = cshift(c, 2)
if (any(b /= v)) call abort
- ! Special cases shift = 0, size(a), 1-size(a)
+ ! Special cases shift = 0, size(a), size(a)
b = cshift([1, 2, 3, 4, 5], 0)
if (any(b /= a)) call abort
b = cshift([1, 2, 3, 4, 5], size(a))
if (any(b /= a)) call abort
- b = cshift([1, 2, 3, 4, 5], 1-size(a))
+ b = cshift([1, 2, 3, 4, 5], -size(a))
if (any(b /= a)) call abort
! simplification of array arg.
More information about the Gcc-bugs
mailing list