Issue 180374
Summary [flang] Incorrect `cshift` results under optimization for 2D arrays
Labels flang
Assignees
Reporter gha3mi
    Hi!
I’ve run into an issue with the intrinsic `cshift` in **flang 21.1.8** that only appears when optimization is enabled.

With `-g` (or `-O0`) the code behaves correctly, but with any `-O*` the results are incorrect.

**Compiler**

```
flang version 21.1.8
Target: x86_64-conda-linux-gnu
```

**Minimal reproducer**

```fortran
program cshift_bug
  implicit none
  integer :: a(0:6,3), b(0:6,3)

  a = reshape([ &
    1,2,3, 4,5,6, 7,8,9, 0,0,0, 9,8,7, 6,5,4, 3,2,1 ], &
    shape(a), order=[2,1])

  b = cshift(a, 7)   ! shift by extent → must be identity

  if (any(b /= a)) error stop "cshift(a,7) /= a"
end program
```

**Build/run**

```sh
flang -g  cshift_bug.f90 && ./a.out   # OK
flang -O3 cshift_bug.f90 && ./a.out   # FAIL
```

**Observed behavior**
With `-O*`, `cshift(a,7)` produces constant or undefined rows instead of returning the original array.

**Expected behavior**
Shifting by the extent of the dimension should return the input array unchanged.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to