[flang-commits] [flang] [llvm] [flang] Check allocation status in inlined ALLOCATE lowering (PR #223287)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 15 06:58:00 PDT 2026
jeanPerier wrote:
> > @jeanPerier Since cf.assert does not support the NoMemoryEffect attribute, are you proposing the creation of a new fir.assert dialect that would be used similarly to cf.assert?
Yes, that is what I am proposing. The reason I think we need a fir.assert is that I think we want to delegate the error printing and aborting to the Fortran runtime so that the formatting and abort actions are consistent with abort from within the Fortran runtime.
I see that cf.assert is registering memory effects. I would rather be able to model it in a way where we can still assume that if you have:
```
fir.store %something to %x
fir.if (%cdt) {
fir.assert %cdt "fatal error"
}
%y = fir.load %x
```
You can deduce that it is OK to replace `%y` by `%something`.
But we still do not want operation that are not speculatable to be moved before it (e.g., if the assert is guarding a nullptr check for an POINTER dereference, we should not allow moving the fir.load before it).
Also, it should not be csed, and I think MLIR will CSE will delete any operation without memory effects whose result is not used.
So, this is not as straightforward as I thought at first. I think the best path is probably to indicate that the operation has potential impact on a non addressable memory resource for the Fortran runtime (a bit like fir.declare_value is impacting the DebuggingResource).
The next point is, if we take the example of something like arith.remsi that is only non speculatable, or fir.load, that has a read effect on an a precise value, how do we ensure that MLIR passes do not have the right to move them before the fir.assert (that may be guarding them) when they belong to the same block given I believe MLIR model assumes every op in a same block as the same reachability. I do not have a good answer to that issue, I am happy if you can investigate a bit here.
https://github.com/llvm/llvm-project/pull/223287
More information about the flang-commits
mailing list