[flang-commits] [flang] [flang][OpenMP] Implement copyin for pointers and allocatables. (PR #107425)

David Truby via flang-commits flang-commits at lists.llvm.org
Thu Sep 5 10:58:40 PDT 2024


================
@@ -619,9 +620,28 @@ bool ClauseProcessor::processCopyin() const {
               checkAndCopyHostAssociateVar(&*mem, &insPt);
             break;
           }
-          if (semantics::IsAllocatableOrObjectPointer(&sym->GetUltimate()))
-            TODO(converter.getCurrentLocation(),
-                 "pointer or allocatable variables in Copyin clause");
+          if (semantics::IsAllocatable(sym->GetUltimate())) {
+            // copyin should copy the association of the allocatable
+
+            fir::FirOpBuilder &builder = converter.getFirOpBuilder();
+            const Fortran::semantics::Symbol &hsym = sym->GetUltimate();
+
+            Fortran::lower::SymbolBox hsb =
+                converter.lookupOneLevelUpSymbol(hsym);
+            assert(hsb && "Host symbol box not found");
+
+            Fortran::lower::SymbolBox sb = converter.shallowLookupSymbol(*sym);
+            assert(sb && "Host-associated symbol box not found");
+            assert(hsb.getAddr() != sb.getAddr() &&
+                   "Host and associated symbol boxes are the same");
+
+            mlir::Location loc = converter.genLocation(sym->name());
+            mlir::OpBuilder::InsertionGuard ipGuard{builder};
+            builder.setInsertionPointAfter(sb.getAddr().getDefiningOp());
+            builder.create<hlfir::AssignOp>(loc, hsb.getAddr(), sb.getAddr(),
+                                            true, false, false);
+          }
----------------
DavidTruby wrote:

Are you saying, if we remove the todo and also add `|| flags.test(...::CopyIn` in the above place things should work?
When I _just_ removed the TODO it didn't work for me.

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


More information about the flang-commits mailing list