[flang] Centralize automatic deallocation code in lowering (#67003)
There are currently several places that automatically deallocate allocatble if they are allocated: - INTENT(OUT) allocatable are deallocated on entry in the callee - INTENT(OUT) allocatable are also deallocated on the caller side of BIND(C) function in case the implementation is in C. - Results of function returning allocatable are deallocated after usage. - OPENMP privatized allocatable are deallocated at the end of OPENMP region. Introduce genDeallocateIfAllocated that centralize all this code, except for the function return that use genFreememIfAllocated since finalization is done separately currently. `fir::factory::genFinalization` and `fir::factory::genInlinedDeallocation` are removed and replaced by genFreemem since their name were misleading: finalization was not called. There is a fallout in the tests because previous generated code did not check the allocated status when doing inline deallocation. This was OK since free(null) is guaranteed to be a no-op, but this makes compiler code more complex, is a bit surprising in the generated IR IMHO, and it relied on knowing when genDeallocateBox inserts runtime calls or uses inlined code.
Loading
Please sign in to comment