@@ -454,6 +454,19 @@ class AllocateStmtHelper {
454454 alloc.getSymbol ());
455455 }
456456
457+ void setPinnedToFalse () {
458+ if (!pinnedExpr)
459+ return ;
460+ Fortran::lower::StatementContext stmtCtx;
461+ mlir::Value pinned =
462+ fir::getBase (converter.genExprAddr (loc, *pinnedExpr, stmtCtx));
463+ mlir::Location loc = pinned.getLoc ();
464+ mlir::Value falseValue = builder.createBool (loc, false );
465+ mlir::Value falseConv = builder.createConvert (
466+ loc, fir::unwrapRefType (pinned.getType ()), falseValue);
467+ builder.create <fir::StoreOp>(loc, falseConv, pinned);
468+ }
469+
457470 void genSimpleAllocation (const Allocation &alloc,
458471 const fir::MutableBoxValue &box) {
459472 bool isCudaSymbol = Fortran::semantics::HasCUDAAttr (alloc.getSymbol ());
@@ -469,6 +482,7 @@ class AllocateStmtHelper {
469482 // can be validated.
470483 genInlinedAllocation (alloc, box);
471484 postAllocationAction (alloc);
485+ setPinnedToFalse ();
472486 return ;
473487 }
474488
@@ -482,11 +496,13 @@ class AllocateStmtHelper {
482496 genSetDeferredLengthParameters (alloc, box);
483497 genAllocateObjectBounds (alloc, box);
484498 mlir::Value stat;
485- if (!isCudaSymbol)
499+ if (!isCudaSymbol) {
486500 stat = genRuntimeAllocate (builder, loc, box, errorManager);
487- else
501+ setPinnedToFalse ();
502+ } else {
488503 stat =
489504 genCudaAllocate (builder, loc, box, errorManager, alloc.getSymbol ());
505+ }
490506 fir::factory::syncMutableBoxFromIRBox (builder, loc, box);
491507 postAllocationAction (alloc);
492508 errorManager.assignStat (builder, loc, stat);
@@ -616,13 +632,16 @@ class AllocateStmtHelper {
616632 genSetDeferredLengthParameters (alloc, box);
617633 genAllocateObjectBounds (alloc, box);
618634 mlir::Value stat;
619- if (Fortran::semantics::HasCUDAAttr (alloc.getSymbol ()))
635+ if (Fortran::semantics::HasCUDAAttr (alloc.getSymbol ())) {
620636 stat =
621637 genCudaAllocate (builder, loc, box, errorManager, alloc.getSymbol ());
622- else if (isSource)
623- stat = genRuntimeAllocateSource (builder, loc, box, exv, errorManager);
624- else
625- stat = genRuntimeAllocate (builder, loc, box, errorManager);
638+ } else {
639+ if (isSource)
640+ stat = genRuntimeAllocateSource (builder, loc, box, exv, errorManager);
641+ else
642+ stat = genRuntimeAllocate (builder, loc, box, errorManager);
643+ setPinnedToFalse ();
644+ }
626645 fir::factory::syncMutableBoxFromIRBox (builder, loc, box);
627646 postAllocationAction (alloc);
628647 errorManager.assignStat (builder, loc, stat);
0 commit comments