diff options
author | Harald Anlauf <anlauf@gmx.de> | 2024-12-19 22:22:52 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2024-12-20 18:23:32 +0100 |
commit | aed4a2689dbc8ea7e60c1fab9e7f455d99e632b7 (patch) | |
tree | 1eb8b803a4ea2717f472746a4b49dccce097ef2e /gcc/fortran | |
parent | 219ddae16f9d724baeff86934f8981aa5ef7b95f (diff) | |
download | gcc-aed4a2689dbc8ea7e60c1fab9e7f455d99e632b7.zip gcc-aed4a2689dbc8ea7e60c1fab9e7f455d99e632b7.tar.gz gcc-aed4a2689dbc8ea7e60c1fab9e7f455d99e632b7.tar.bz2 |
Fortran: potential aliasing of complex pointer inquiry references [PR118120]
PR fortran/118120
PR fortran/113928
gcc/fortran/ChangeLog:
* trans-array.cc (symbols_could_alias): If one symbol refers to a
complex type and the other to a real type of the same kind, do not
a priori exclude the possibility of aliasing.
gcc/testsuite/ChangeLog:
* gfortran.dg/aliasing_complex_pointer.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/trans-array.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 82a2ae1..5281385 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -5344,15 +5344,20 @@ static bool symbols_could_alias (gfc_symbol *lsym, gfc_symbol *rsym, bool lsym_pointer, bool lsym_target, bool rsym_pointer, bool rsym_target) { - /* Aliasing isn't possible if the symbols have different base types. */ - if (gfc_compare_types (&lsym->ts, &rsym->ts) == 0) - return 0; + /* Aliasing isn't possible if the symbols have different base types, + except for complex types where an inquiry reference (%RE, %IM) could + alias with a real type with the same kind parameter. */ + if (!gfc_compare_types (&lsym->ts, &rsym->ts) + && !(((lsym->ts.type == BT_COMPLEX && rsym->ts.type == BT_REAL) + || (lsym->ts.type == BT_REAL && rsym->ts.type == BT_COMPLEX)) + && lsym->ts.kind == rsym->ts.kind)) + return false; /* Pointers can point to other pointers and target objects. */ if ((lsym_pointer && (rsym_pointer || rsym_target)) || (rsym_pointer && (lsym_pointer || lsym_target))) - return 1; + return true; /* Special case: Argument association, cf. F90 12.4.1.6, F2003 12.4.1.7 and F2008 12.5.2.13 items 3b and 4b. The pointer case (a) is already @@ -5363,9 +5368,9 @@ symbols_could_alias (gfc_symbol *lsym, gfc_symbol *rsym, bool lsym_pointer, || (rsym->attr.dummy && !rsym->attr.contiguous && (!rsym->attr.dimension || rsym->as->type == AS_ASSUMED_SHAPE)))) - return 1; + return true; - return 0; + return false; } |