@@ -475,6 +475,7 @@ class AllocateStmtHelper {
475475 !alloc.type .IsPolymorphic () &&
476476 !alloc.hasCoarraySpec () && !useAllocateRuntime &&
477477 !box.isPointer ();
478+ unsigned allocatorIdx = Fortran::lower::getAllocatorIdx (alloc.getSymbol ());
478479
479480 if (inlineAllocation &&
480481 ((isCudaSymbol && isCudaDeviceContext) || !isCudaSymbol)) {
@@ -488,7 +489,7 @@ class AllocateStmtHelper {
488489
489490 // Generate a sequence of runtime calls.
490491 errorManager.genStatCheck (builder, loc);
491- genAllocateObjectInit (box);
492+ genAllocateObjectInit (box, allocatorIdx );
492493 if (alloc.hasCoarraySpec ())
493494 TODO (loc, " coarray: allocation of a coarray object" );
494495 if (alloc.type .IsPolymorphic ())
@@ -549,14 +550,15 @@ class AllocateStmtHelper {
549550 TODO (loc, " derived type length parameters in allocate" );
550551 }
551552
552- void genAllocateObjectInit (const fir::MutableBoxValue &box) {
553+ void genAllocateObjectInit (const fir::MutableBoxValue &box, unsigned allocatorIdx ) {
553554 if (box.isPointer ()) {
554555 // For pointers, the descriptor may still be uninitialized (see Fortran
555556 // 2018 19.5.2.2). The allocation runtime needs to be given a descriptor
556557 // with initialized rank, types and attributes. Initialize the descriptor
557558 // here to ensure these constraints are fulfilled.
558559 mlir::Value nullPointer = fir::factory::createUnallocatedBox (
559- builder, loc, box.getBoxTy (), box.nonDeferredLenParams ());
560+ builder, loc, box.getBoxTy (), box.nonDeferredLenParams (),
561+ /* typeSourceBox=*/ {}, allocatorIdx);
560562 builder.create <fir::StoreOp>(loc, nullPointer, box.getAddr ());
561563 } else {
562564 assert (box.isAllocatable () && " must be an allocatable" );
@@ -612,11 +614,12 @@ class AllocateStmtHelper {
612614
613615 void genSourceMoldAllocation (const Allocation &alloc,
614616 const fir::MutableBoxValue &box, bool isSource) {
617+ unsigned allocatorIdx = Fortran::lower::getAllocatorIdx (alloc.getSymbol ());
615618 fir::ExtendedValue exv = isSource ? sourceExv : moldExv;
616- ;
619+
617620 // Generate a sequence of runtime calls.
618621 errorManager.genStatCheck (builder, loc);
619- genAllocateObjectInit (box);
622+ genAllocateObjectInit (box, allocatorIdx );
620623 if (alloc.hasCoarraySpec ())
621624 TODO (loc, " coarray: allocation of a coarray object" );
622625 // Set length of the allocate object if it has. Otherwise, get the length
0 commit comments