[flang-commits] [flang] [llvm] [flang][MIF] Adding lowering for EVENT POST/WAIT statements (PR #210283)
Dan Bonachea via flang-commits
flang-commits at lists.llvm.org
Wed Oct 7 13:47:06 PDT 2026
================
@@ -1190,9 +1305,21 @@ struct MIFAllocCoarrayOpConversion
builder, loc, ftype, op.getLcobounds(), op.getUcobounds(), sizeInBytes,
finalFunc, coarrayHandle, allocMem, stat, errmsgArg, errmsgAllocArg);
fir::CallOp callOp = fir::CallOp::create(builder, loc, funcOp, args);
-
storeCoarrayHandle(builder, loc, coarrayHandle, op.getUniqName().str());
+ // Set new base_addr for the coarray descriptor
+ mlir::Value addrRef =
+ fir::factory::genCPtrOrCFunptrAddr(builder, loc, allocMem, ptrTy);
+ allocMem = fir::LoadOp::create(builder, loc, addrRef);
+ mlir::func::FuncOp sbaFunc =
+ fir::runtime::getRuntimeFunc<mkRTKey(AllocatableSetBaseAddr)>(loc,
+ builder);
+ llvm::SmallVector<mlir::Value> args2{fir::runtime::createArguments(
+ builder, loc, sbaFunc.getFunctionType(), op.getBox(), allocMem)};
+ fir::CallOp::create(builder, loc, sbaFunc, args2);
----------------
bonachea wrote:
Behavioral change confirmed using Caffeine. Thank you for finding this problem!
As suggested above it appears that both `main` and this PR call `prif_allocate_coarray` within the internal subroutine, **which is equally "wrong"** (in that it leaks memory, and would deadlock for a non-collective call). IIUC the primary change is that in `main` the leaked coarray memory is effectively discarded, whereas the PR erroneously uses it to replace the main program coarray. But the fundamental defect is the second call to `prif_allocate_coarray` should never happen at all; everything that happens after that is just fallout from that critical error.
This defect is important but seems somewhat orthogonal, since the behavior in main is also fundamentally broken. I'd suggest we open a dedicated issue for this defect and address it in a separate PR.
https://github.com/llvm/llvm-project/pull/210283
More information about the flang-commits
mailing list