Commit 7932311
committed
Do not assume pointers cannot alias arrays of different types
As added in the comment, the assumption that a pointer of a certain type
cannot alias an array of a different type is tricky.
First, it is wrong in general currently because equivalence uses
pointer aliasing for its aliasing, and the any type can alias any
other types.
Then, in the normal pointer case, it is at least possible to have
complex/real overlap starting with F2008 introduction of %RE/%IM,
and in general with derived types and there component types.
Although one should note that not all compilers are very carefully
here.
Complex/Real overlap example:
```
module m
contains
subroutine foo(p, x)
real, target :: x(:)
real, pointer :: p(:)
p => x
end subroutine
end module
use :: m
real, pointer :: real_pointer(:)
complex, target :: complex_target(4) = [(1., 1.), (2., 2.), (3., 3.), (4., 4.)]
call foo(real_pointer, complex_target%re)
real_pointer = abs(complex_target(4:1:-1))
print *, real_pointer
end
```
- ifort, gfortran (need >= 9.3 to support %re), and Nagfor all compile and
assume potential overlap printing `5.6568542 4.2426405 2.8284271 1.4142135`.
- nvfortran hits an ICE (probably caused by passing the complex_target%re).
- xlf ignore the overlap and prints `5.656854153 4.242640495 4.690415382 5.744562626`.
Derived/Part overlap example:
```
type t
integer :: i
end type
integer, pointer :: integer_pointer(:)
type(t), target :: derived_target(4) = [t(1), t(2), t(3), t(4)]
integer_pointer => derived_target%i
derived_target%i = integer_pointer(4:1:-1)
print *, integer_pointer
end
```
- Nvfortran and Nagfor assumes it can overlap and print `4 3 2 1`
- gfortran, xlf and ifort assume no overlap and prints `4 3 3 4`
Hence, once the equivalence aliasing is handled another way, we may want
to dig more into this and find the correct requirement here. For now,
assumes we need to be as strict as the stricter compilers out there.1 parent f08fa76 commit 7932311
File tree
2 files changed
+61
-6
lines changed- flang
- lib/Optimizer/Transforms
- test/Fir
2 files changed
+61
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
437 | | - | |
438 | | - | |
439 | 437 | | |
440 | 438 | | |
441 | 439 | | |
442 | | - | |
443 | | - | |
444 | 440 | | |
445 | 441 | | |
446 | 442 | | |
447 | 443 | | |
448 | 444 | | |
449 | 445 | | |
450 | 446 | | |
451 | | - | |
452 | | - | |
| 447 | + | |
453 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
454 | 457 | | |
455 | 458 | | |
456 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments