@@ -791,7 +791,7 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
791
791
792
792
return Fortran::lower::omp::internal::createMapInfoOp (
793
793
rewriter, liveIn.getLoc (), rawAddr,
794
- /* varPtrPtr=*/ {}, declareOp. getUniqName () .str (), boundsOps,
794
+ /* varPtrPtr=*/ {}, name .str (), boundsOps,
795
795
/* members=*/ {},
796
796
/* membersIndex=*/ mlir::ArrayAttr{},
797
797
static_cast <
@@ -814,8 +814,8 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
814
814
llvm::SmallVector<mlir::Type> regionArgTypes;
815
815
llvm::SmallVector<mlir::Location> regionArgLocs;
816
816
817
- for (auto var :
818
- llvm::concat< const mlir::Value>( clauseOps.hostEvalVars , mappedVars )) {
817
+ for (auto var : llvm::concat< const mlir::Value>(clauseOps. hostEvalVars ,
818
+ clauseOps.mapVars )) {
819
819
regionArgTypes.push_back (var.getType ());
820
820
regionArgLocs.push_back (var.getLoc ());
821
821
}
@@ -825,11 +825,19 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
825
825
rewriter,
826
826
fir::getKindMapping (targetOp->getParentOfType <mlir::ModuleOp>()));
827
827
828
- for (auto [arg, mapInfoOp, mappedVar] : llvm::zip_equal (
829
- argIface.getMapBlockArgs (), clauseOps.mapVars , mappedVars)) {
828
+ // Within the loop, it possible that we discover other values that need to
829
+ // mapped to the target region (the shape info values for arrays, for
830
+ // example). Therefore, the map block args might be extended and resized.
831
+ // Hence, we invoke `argIface.getMapBlockArgs()` every iteration to make
832
+ // sure we access the proper vector of data.
833
+ int idx = 0 ;
834
+ for (auto [mapInfoOp, mappedVar] :
835
+ llvm::zip_equal (clauseOps.mapVars , mappedVars)) {
830
836
auto miOp = mlir::cast<mlir::omp::MapInfoOp>(mapInfoOp.getDefiningOp ());
831
- hlfir::DeclareOp liveInDeclare = genLiveInDeclare (
832
- builder, targetOp, arg, miOp, liveInShapeInfoMap.at (mappedVar));
837
+ hlfir::DeclareOp liveInDeclare =
838
+ genLiveInDeclare (builder, targetOp, argIface.getMapBlockArgs ()[idx],
839
+ miOp, liveInShapeInfoMap.at (mappedVar));
840
+ ++idx;
833
841
834
842
// TODO If `mappedVar.getDefiningOp()` is a `fir::BoxAddrOp`, we probably
835
843
// need to "unpack" the box by getting the defining op of it's value.
0 commit comments