Skip to content

Commit 8870ce1

Browse files
[flang][docs] Add note about Cray pointers and the TARGET attribute (#137993)
We found some tests checking for loops assigning between Cray pointer handles and their pointees which produced "incorrect" results with optimizations enabled; this is because the compiler expects Cray pointers not to alias with any other entity. [The HPE documentation for Cray Fortran extensions specifies:](https://support.hpe.com/hpesc/public/docDisplay?docId=a00113911en_us&docLocale=en_US&page=Types.html#cray-poiter-type) > the compiler assumes that the storage of a pointee is > never overlaid on the storage of another variable Jean pointed out that if a user's code uses entities that alias via Cray pointers, they may add the TARGET attribute to inform Flang of this aliasing, but that Flang's behavior is in line with Cray's own documentation and we should not make any changes to our alias analysis to try and detect this case. Updating documentation so that users that encounter this situation have a way to allow their code to compile as they intend.
1 parent a7bff2a commit 8870ce1

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

flang/docs/Aliasing.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,30 @@ Fortran also has no rule against associating read-only data with a pointer.
264264
Cray pointers are, or were, an extension that attempted to provide
265265
some of the capabilities of modern pointers and allocatables before those
266266
features were standardized.
267-
They had some aliasing restrictions; in particular, Cray pointers were
268-
not allowed to alias each other.
269267

270-
They are now more or less obsolete and we have no plan in place to
271-
support them.
268+
They had some aliasing restrictions; in particular, Cray pointers were not
269+
allowed to alias each other.
270+
271+
In this example, `handle` aliases with `target`.
272+
273+
```
274+
integer(kind=8) :: target(10)
275+
integer(kind=8) :: ptr
276+
integer(kind=8) :: handle(10)
277+
pointer(ptr, handle)
278+
target = 1
279+
ptr = loc(target)
280+
print *, target
281+
end
282+
```
283+
284+
Optimizations assume that Cray pointers do not alias any other variables.
285+
In the above example, it is assumed that `handle` and `target` do not alias,
286+
and optimizations will treat them as separate entities.
287+
288+
In order to disable optimizations that assume that there is no aliasing between
289+
Cray pointer targets and entities they alias with, add the TARGET attribute to
290+
variables aliasing with a Cray pointer (the `target` variable in this example).
272291

273292
## Type considerations
274293

0 commit comments

Comments
 (0)