This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: cray pointer behavior in 4.6 (bug?)
Ryan S. Elliott wrote:
I have observed some behavior in gfortran 4.6 that does not occur in
4.5 and earlier (as far as I know). The issue is associated with the
use of cray pointers.
The (technical) reason that 4.5 "works" and 4.6 doesn't is that GCC 4.6
does more optimizations than 4.5 (cf. -fwhole-file, which is the default
in 4.6).
The question is only whether the compiler has a bug by doing invalid
optimizations or the program a bug as it relies on invalid assumptions.
As Cray pointers are not formally defined, giving a definite statement
is difficult.
It seems that the compiler - at higher optimization levels - does not
see that the two "oh" and two "obj" alias.
In Fortran 90/95/2003/2008, one has to tell the compiler explicitly that
a certain variable can alias; one does so by marking those variables
with the TARGET attribute. If one does so for "oh", the program works.
(Target also requires an explicit interface, e.g. via a module.)
* * *
However, given that Cray pointers precede Fortran 90, the question is
how to solve the situation. I think marking automatically (internally)
the Cray-pointer target as target, could be a viable solution.
The following patch attempts to do so - at least for simple assignments
such as "cray_pointer = var", it won't work for "cray_pointer = var +
4", but I simply hope that that won't occur in practice. Alternatives
are to walk possibility is to properly walk expressions or - as brute
force method - to always assume aliasing with -fcray-pointer.
* * *
Early, completely untested draft patch. It probably won't work for the
example as it sets the normal target attribute. However, the target
attribute requires an explicit interface ...
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -9303,2 +9303,9 @@ resolve_ordinary_assign (gfc_code *code,
gfc_namespace *ns)
gfc_check_assign (lhs, rhs, 1);
+
+ if (lhs->expr_type == EXPR_VARIABLE && rhs->expr_type == EXPR_VARIABLE
+ && lhs->ref == NULL
+ && lhs->symtree->n.sym->attr.cray_pointer
+ && !rhs->symtree->n.sym->attr.cray_pointer)
+ lhs->symtree->n.sym->attr.target = 1;
+
return false;
Tobias