[flang] [llvm] [Flang] Adding lowering for the allocation and deallocation of coarrays (PR #182110)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 06:36:38 PST 2026
================
@@ -884,13 +908,32 @@ genDeallocate(fir::FirOpBuilder &builder,
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
const fir::MutableBoxValue &box, ErrorManager &errorManager,
mlir::Value declaredTypeDesc = {},
- const Fortran::semantics::Symbol *symbol = nullptr) {
+ const Fortran::semantics::Symbol *symbol = nullptr,
+ const Fortran::lower::SomeExpr *allocExpr = nullptr) {
bool isCudaSymbol = symbol && Fortran::semantics::HasCUDAAttr(*symbol);
bool isCudaDeviceContext = cuf::isCUDADeviceContext(builder.getRegion());
bool inlineDeallocation =
!box.isDerived() && !box.isPolymorphic() && !box.hasAssumedRank() &&
!box.isUnlimitedPolymorphic() && !errorManager.hasStatSpec() &&
!useAllocateRuntime && !box.isPointer();
+
+ std::optional<Fortran::evaluate::DataRef> dataRef =
+ !allocExpr ? std::nullopt : Fortran::evaluate::ExtractDataRef(allocExpr);
+ bool isCoarraySymbol = symbol && Fortran::evaluate::IsCoarray(*symbol);
+
+ // Deallocate coarray
+ if (isCoarraySymbol) {
+ mlir::Value ret = builder.createTemporary(loc, builder.getI32Type());
----------------
jeanPerier wrote:
I think the handling of STAT here will cause the code to silently continue after an issue with coarray ALLOCATE when neither STAT/ERRMSG are present.
With the normal runtime, the runtime is provided a boolean telling it if STAT is present, and will terminate the program if an issue is met and this boolean is false and errmsg was not provided.
I would advise doing something similar, or passing the stat variable directly/ a nullptr if not present (but this last approach is made more difficult by the fact that stat may have any integer KIND, so you would need a descriptor, hence the approach of using a bool argument + i32 return of _FortranAAllocatableAllocate).
https://github.com/llvm/llvm-project/pull/182110
More information about the llvm-commits
mailing list