1313#include " flang/Lower/Allocatable.h"
1414#include " flang/Evaluate/tools.h"
1515#include " flang/Lower/AbstractConverter.h"
16+ #include " flang/Lower/CUDA.h"
1617#include " flang/Lower/ConvertType.h"
1718#include " flang/Lower/ConvertVariable.h"
18- #include " flang/Lower/Cuda.h"
1919#include " flang/Lower/IterationSpace.h"
2020#include " flang/Lower/Mangler.h"
2121#include " flang/Lower/OpenACC.h"
@@ -445,10 +445,14 @@ class AllocateStmtHelper {
445445 /* mustBeHeap=*/ true );
446446 }
447447
448- void postAllocationAction (const Allocation &alloc) {
448+ void postAllocationAction (const Allocation &alloc,
449+ const fir::MutableBoxValue &box) {
449450 if (alloc.getSymbol ().test (Fortran::semantics::Symbol::Flag::AccDeclare))
450451 Fortran::lower::attachDeclarePostAllocAction (converter, builder,
451452 alloc.getSymbol ());
453+ if (Fortran::semantics::HasCUDAComponent (alloc.getSymbol ()))
454+ Fortran::lower::initializeDeviceComponentAllocator (
455+ converter, alloc.getSymbol (), box);
452456 }
453457
454458 void setPinnedToFalse () {
@@ -481,7 +485,7 @@ class AllocateStmtHelper {
481485 // Pointers must use PointerAllocate so that their deallocations
482486 // can be validated.
483487 genInlinedAllocation (alloc, box);
484- postAllocationAction (alloc);
488+ postAllocationAction (alloc, box );
485489 setPinnedToFalse ();
486490 return ;
487491 }
@@ -504,7 +508,7 @@ class AllocateStmtHelper {
504508 genCudaAllocate (builder, loc, box, errorManager, alloc.getSymbol ());
505509 }
506510 fir::factory::syncMutableBoxFromIRBox (builder, loc, box);
507- postAllocationAction (alloc);
511+ postAllocationAction (alloc, box );
508512 errorManager.assignStat (builder, loc, stat);
509513 }
510514
@@ -647,7 +651,7 @@ class AllocateStmtHelper {
647651 setPinnedToFalse ();
648652 }
649653 fir::factory::syncMutableBoxFromIRBox (builder, loc, box);
650- postAllocationAction (alloc);
654+ postAllocationAction (alloc, box );
651655 errorManager.assignStat (builder, loc, stat);
652656 }
653657
0 commit comments