[flang-commits] [flang] [flang] Treat visible Cray pointer associations as aliasing for TBAA (PR #221350)

via flang-commits flang-commits at lists.llvm.org
Tue Sep 8 15:47:08 PDT 2026


junfengd-nv wrote:

Thanks Slava, Jean.
Why this is needed: with `-O2` and no extra flags, flang miscompiles this:
```
  subroutine s
    real :: var(10), array(20)
    pointer (ptr, var)
    ptr = loc(array)
    var(1) = 1.0
    if (array(1) /= 1.0) print *, 'err'
  end
```
Why `-funsafe-cray-pointers` is not the answer: it is not the same kind of flag as gfortran's `-fcray-pointer`. gfortran `-fcray-pointer` only enables the extension (the `pointer (p, x)` syntax). Once that is on, `[cray_pointers_10](https://gnu.googlesource.com/gcc/+/refs/heads/master/gcc/testsuite/gfortran.dg/cray_pointers_1.f90?autodive=0%2F%2F%2F%2F%2F)` is a run test with no extra aliasing flag. Flang already accepts that syntax. `-funsafe-cray-pointers` changes the optimization assumption: every Cray pointer may alias all data. These tests only need the visible pair to alias, and should not require a flag named "unsafe" for code other compilers get right by default.

Jean, agreed on the mechanism: TBAA-only leaves FIR alias analysis at NoAlias, so MLIR-level forwarding would reintroduce the bug. I'll rework this to add TARGET during lowering for symbols appearing in a visible `ptr = loc(x)`, so all FIR passes see the aliasing. 

https://github.com/llvm/llvm-project/pull/221350


More information about the flang-commits mailing list