[flang-commits] [flang] [llvm] [flang][MIF] Adding lowering for EVENT POST/WAIT statements (PR #210283)
via flang-commits
flang-commits at lists.llvm.org
Wed Oct 21 19:02:18 PDT 2026
================
@@ -195,7 +195,16 @@ class AssignOpConversion : public mlir::OpRewritePattern<hlfir::AssignOp> {
// Use the runtime for simplicity. An optimization pass will be added to
// inline array assignment when profitable.
mlir::Value from = emboxRHS(rhsExv);
- mlir::Value to = fir::getBase(builder.createBox(loc, lhsExv));
+ mlir::Value to;
+ // A nonallocable coarray has an allocable descriptor and reallocation
+ // must not happen so we want to have a descriptor without the
+ // “allocatable” attribute
+ if (fir::getBoxCorank(lhs.getType()) > 0) {
+ fir::ExtendedValue readLhs =
+ fir::factory::readBoxValue(builder, loc, fir::getBase(lhsExv));
----------------
MattPD wrote:
This change makes the compiler crash on some assignments to allocatable or CONTIGUOUS array coarrays. Flang built with assertions now aborts with ``Assertion `verify()' failed`` in `fir::BoxValue::BoxValue` when it compiles this program with `-fcoarray`. Before 1d027b1c, the program printed `10 20`:
```fortran
program p
integer, allocatable :: c(:)[:]
allocate(c(2)[*])
c = [10, 20]
print *, c
end program
```
The same assertion fails in two other cases: `c = "x"` for `character(4), contiguous, save :: c(2)[*]`, and `c = "x"` for `character(4), allocatable :: c(:)[:]` compiled with `-fno-realloc-lhs`.
These variables are simply contiguous, so `translateToExtendedValue` returns their data address rather than a descriptor, and `fir::getBase(lhsExv)` is not a box.
Adding `&& lhsExv.getBoxOf<fir::BoxValue>()` to the condition `fir::getBoxCorank(lhs.getType()) > 0` fixed all three cases in my local build. With that change, `createBox(loc, lhsExv)` builds a descriptor without the allocatable attribute for these variables, as it did before 1d027b1c. In that build, the lit tests in `flang/test/HLFIR` and `flang/test/Lower` still pass.
Could `coarray-character-assign.f90` also include these three cases?
https://github.com/llvm/llvm-project/pull/210283
More information about the flang-commits
mailing list