https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128761

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu.org
          Component|ipa                         |fortran

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
I got tired of seeing the failure show up and used Claude to analyze it.

Why pr49213 fails (changing component):

The real cause is a latent gfortran wrong-code bug. r17-6276-ga08d0e9eeaa only
exposed it.

- gfortran builds separate class container types for one declared type:
__class_S_a (allocatable), __class_S_p (pointer) and __class_S_t (neither).
Each is a distinct RECORD_TYPE with its own alias set.

- The frontend freely casts between them. In pass_it, SELECT TYPE emits x =
(struct __class_main_S_p *) &foo->x, where foo->x is really an _a container. _p
and struct t
share no alias set, so under TBAA the callee's loads of x->_vptr and x->_data
cannot
alias the caller's stores.

- DSE1 in MAIN__ then uses pass_it's modref summary to delete the stores that
build T(Sobj) ("call to pass_it/3 does not use ref"). pass_it reads
uninitialized memory and hits STOPĀ 7.

- Before a08d0e9eeaa, the memcpy from the literal "S " inside pass_it was
treated as an unknown load, so modref collapsed the loads to "Every base". The
commit makes refs_local_or_readonly_memory_p accept constants, so the loads
stay precise.

- GCC 16.2 is also affected. Without the string literal, the same reproducer
fails with /usr/bin/gfortran -O2. So does a plain class(S), intent(in) :: x
dummy with select type (y => x), called as pass_it(S(1)).

Fix

In gcc/fortran/trans-types.cc, the _a, _p and _t containers of one declared
type, rank
and corank now share a TYPE_CANONICAL, and therefore one alias set. The
containers are found by their name without the variant letter. They are only
unified when their field types have matching canonical types, which keeps
coarray containers with different
coranks apart. This is the same idea as the existing target/nontarget array
descriptor handling, and it matches what LTO's structural canonicalization
already does.

Reply via email to