https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128954
Bug ID: 128954
Summary: [17 Regression] gfortran.dg/pr49213.f90 fails at -O2
with STOP 7 (dse1 deletes initialization of CLASS
argument before call)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: danglin at gcc dot gnu.org
CC: hubicka at gcc dot gnu.org, jvdelisle at gcc dot gnu.org,
rguenth at gcc dot gnu.org
Target Milestone: ---
Host: hppa64-hp-hpux11.11
Target: hppa64-hp-hpux11.11
Build: hppa64-hp-hpux11.11
Description
gfortran.dg/pr49213.f90 regressed between r17-6187-gb154458ecbb and
r17-6531-g728d0bebb85, failing at -O2, -O3, and -Os with STOP 7 on
hppa64-hp-hpux11.11 (and also visible on powerpc64-unknown-linux-gnu in
gnu.org).
Cause
In MAIN__, call pass_it (T(S2obj)) passes a temporary struct t (D.1366) by
reference to the nested subroutine pass_it (&D.1366).
Following r17-6306-g303400bda9e (fortran: [PR82173] Free LEN components of PDTs
in CLASS(*) objects), gfc_trans_assignment_1 emits cleanup stores
D.1366.x._data = 0B; D.1366.x._vptr = &__vtab_main_S; after the call to pass_it
(&D.1366):
MEM <struct s *> [(struct t *)&D.1366] = _40;
MEM <struct __vtype_main_S * {ref-all}> [(struct t *)&D.1366 + 8B] =
&__vtab_main_S2;
pass_it (&D.1366); [static-chain: &FRAME.44]
D.1366.x._data = 0B;
D.1366.x._vptr = &__vtab_main_S;
D.1366 ={v} {CLOBBER(eos)};
In 048t.dse1, DSE queries ipa-modref to see whether pass_it (&D.1366) reads
D.1366. Because pass_it accesses foo->_vptr by casting foo (struct t &
restrict, alias set 25) to struct __class_main_S_p * (_1 = MEM[(struct
__class_main_S_p *)foo_13(D)]._vptr;), ipa-modref reports that pass_it does not
read the struct t reference (TBAA alias set mismatch between struct t /
__class_main_S_a and __class_main_S_p), causing dse1 to delete both
initialization stores to D.1366 (and D.1363):
ipa-modref: call stmt pass_it (&D.1366); [static-chain: &FRAME.44]
ipa-modref: call to pass_it/11 does not use ref: MEM <struct __vtype_main_S *
{ref-all}> [(struct t *)&D.1366 + 8B] alias sets: 25->25
Deleted dead store: MEM <struct __vtype_main_S * {ref-all}> [(struct t
*)&D.1366 + 8B] = &__vtab_main_S2;
ipa-modref: call stmt pass_it (&D.1366); [static-chain: &FRAME.44]
ipa-modref: call to pass_it/11 does not use ref: MEM <struct s *> [(struct t
*)&D.1366] alias sets: 25->25
Deleted dead store: MEM <struct s *> [(struct t *)&D.1366] = _40;
As a result, pass_it (&D.1366) reads an uninitialized _vptr on the stack, fails
both select type branches, and hits stop 7.
FAIL: gfortran.dg/pr49213.f90 -O2 execution test
FAIL: gfortran.dg/pr49213.f90 -O3 -fomit-frame-pointer -funroll-loops
-fpeel-loops -ftracer -finline-functions execution test
FAIL: gfortran.dg/pr49213.f90 -O3 -g execution test
FAIL: gfortran.dg/pr49213.f90 -Os execution test