| Issue |
239382
|
| Summary |
[flang] fir.boxchar and fir.box_addr lose the volatile attribute
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
cenewcombe
|
`fir.ref`, `fir.box`, and `fir.class` carry an `isVolatile` type parameter, but `fir.boxchar` does not, and `fir.box_addr` builds its result from the box's element type without propagating the box's volatility (`BoxAddrOp::build` in `FIROps.cpp`). As a result, a volatile CHARACTER variable passed as a boxchar, or a volatile POINTER/ALLOCATABLE CHARACTER after `fir.box_addr`, looks like a plain reference once the `hlfir.declare` is out of sight. A pass that inlines accesses, for example the TRIM inlining in `SimplifyHLFIRIntrinsics` (#235086), has to trace the operand back to its declaration to find out, and must treat any producer it cannot trace as volatile.
```fortran
subroutine s(p)
character(:), pointer, volatile :: p
call sub(trim(p))
end subroutine
```
The `fir.box_addr` of `p`'s descriptor has type `!fir.ptr<!fir.char<1,?>>`, not a volatile reference.
Proposed fix: add an `isVolatile` parameter to `fir.boxchar`, set it in `fir.emboxchar` from the operand's reference type, and have `fir.box_addr` produce a volatile reference when its operand is a volatile box or boxchar. The `mayBeVolatileCharacter` workaround in the TRIM inlining can then be removed.
Assisted-by: Copilot
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs