]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/83650 (Wrong simplification in cshift with negative shifts)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 2 Jan 2018 23:03:11 +0000 (23:03 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Tue, 2 Jan 2018 23:03:11 +0000 (23:03 +0000)
2018-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from 7-branch
PR fortran/83650
* simplify.c (gfc_simplify_cshift): Correct contition for
negative shifts.

2018-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from 7-branch
PR fortran/83650
* gfortran.dg/simplify_cshift_1.f90: Correct condition.

From-SVN: r256113

gcc/fortran/ChangeLog
gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/simplify_cshift_1.f90

index f278002b90a215c5f3885c1e04c71290bcb32569..18d014e02937c88805017993d95370809f1db6c3 100644 (file)
@@ -1,3 +1,10 @@
+2018-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from 7-branch
+       PR fortran/83650
+       * simplify.c (gfc_simplify_cshift): Correct contition for
+       negative shifts.
+
 2017-11-13  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from trunk
index 37c04e9bf27d34e89e442118a81281653f3206e3..ea7a7464421387201d60bd4869f36aa053eac5c1 100644 (file)
@@ -1839,7 +1839,9 @@ gfc_simplify_cshift (gfc_expr *array, gfc_expr *shift, gfc_expr *dim)
       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 9cd07f37dd9e680eaa3102bca2a03352120fc5fe..89d3c776dff4e9a8f24add4fadf6e15aee8e80a6 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from 7-branch
+       PR fortran/83650
+       * gfortran.dg/simplify_cshift_1.f90: Correct condition.
+
 2017-12-14  Peter Bergner  <bergner@vnet.ibm.com>
 
        Backport from mainline
index dbe67f4c8e9a032890b3a260fab07b77f77da423..3eb5adb49c81769e0a5632992acb775025e57807 100644 (file)
@@ -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.