[flang-commits] [flang] [Flang][OpenMP] Fix negative array indexing with allocatable derived type array maps (PR #154193)

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Wed Aug 20 02:07:35 PDT 2025


================
@@ -331,10 +325,41 @@ mlir::Value createParentSymAndGenIntermediateMaps(
                              subscriptIndices, objectList[i]);
         assert(!subscriptIndices.empty() &&
                "missing expected indices for map clause");
-        curValue = fir::CoordinateOp::create(
-            firOpBuilder, clauseLocation,
-            firOpBuilder.getRefType(arrType.getEleTy()), curValue,
-            subscriptIndices);
+        if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(curValue.getType())) {
+          fir::ExtendedValue exv =
+              hlfir::translateToExtendedValue(clauseLocation, firOpBuilder,
+                                              hlfir::Entity{curValue},
+                                              /*contiguousHint=*/
+                                              true)
+                  .first;
+
+          mlir::Type idxTy = firOpBuilder.getIndexType();
+          llvm::SmallVector<mlir::Value> shiftOperands;
+          for (unsigned dim = 0; dim < exv.rank(); ++dim) {
----------------
mjklemm wrote:

Please document the maths behind the generated code in terms of a formula in a comment.

https://github.com/llvm/llvm-project/pull/154193


More information about the flang-commits mailing list