[flang-commits] [flang] [flang][hlfir] Lower Cray pointee references. (PR #65563)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Thu Sep 7 08:37:32 PDT 2023


================
@@ -1492,6 +1494,52 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter,
     auto name = converter.mangleName(sym);
     fir::FortranVariableFlagsAttr attributes =
         Fortran::lower::translateSymbolAttributes(builder.getContext(), sym);
+
+    if (isCrayPointee) {
+      mlir::Type baseType =
+          hlfir::getFortranElementOrSequenceType(base.getType());
+      if (auto seqType = mlir::dyn_cast<fir::SequenceType>(baseType)) {
+        // The pointer box's sequence type must be with unknown shape.
+        llvm::SmallVector<int64_t> shape(seqType.getDimension(),
+                                         fir::SequenceType::getUnknownExtent());
+        baseType = fir::SequenceType::get(shape, seqType.getEleTy());
+      }
+      fir::BoxType ptrBoxType =
+          fir::BoxType::get(fir::PointerType::get(baseType));
+      mlir::Value boxAlloc =
+          fir::factory::genNullBoxStorage(builder, loc, ptrBoxType);
----------------
vzakhari wrote:

I am not sure if moving the initialization code before hlfir.declare is necessary.  Do you have an example when this may matter?

Right now the IR looks like we have a regular local pointer with the missing initialization of the pointer into an unassociated status.  Since the following initialization happens before any possible use, I would say it does not matter whether it happens before or after hlfir.declare, but I may be missing something.

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


More information about the flang-commits mailing list