[flang][runtime] Fix runtime CSHIFT of rank>1 array case of negative shift count
authorPeter Klausler <pklausler@nvidia.com>
Tue, 7 Jun 2022 17:11:17 +0000 (10:11 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Mon, 13 Jun 2022 18:34:25 +0000 (11:34 -0700)
The calculation of the source index was incorrect when a CSHIFT shift
count value is negative, for the implementation of CSHIFT for arrays
with rank >= 2.  (The vector CSHIFT is fine.)

Differential Revision: https://reviews.llvm.org/D127424

flang/runtime/transformational.cpp

index ac12627..9a01681 100644 (file)
@@ -167,7 +167,7 @@ void RTNAME(Cshift)(Descriptor &result, const Descriptor &source,
     }
     SubscriptValue &sourceDim{sourceAt[dim - 1]};
     sourceDim = dimLB + shiftCount % dimExtent;
-    if (shiftCount < 0) {
+    if (sourceDim < dimLB) {
       sourceDim += dimExtent;
     }
     for (resDim = 1; resDim <= dimExtent; ++resDim) {