From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 74C84385842E; Tue, 22 Mar 2022 11:50:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74C84385842E From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/103662] [12 Regression] TBAA problem in Fortran FE triggering in gfortran.dg/unlimited_polymorphic_3.f03 Date: Tue, 22 Mar 2022 11:50:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: alias, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2022 11:50:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103662 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org, | |jakub at gcc dot gnu.org --- Comment #10 from Jakub Jelinek --- >>From what I can see, for normal derived types resolve_symbol calls resolve_fl_derived -> resolve_fl_derived0 -> add_dt_to_dt_list which ensures that the derived type eventually makes it into ns->derived_ty= pes and then gfc_get_derived_type will do: /* The derived types from an earlier namespace can be used as the canonical type. */ if (derived->backend_decl =3D=3D NULL && !derived->attr.use_assoc && !derived->attr.used_in_submodule && gfc_global_ns_list) { for (ns =3D gfc_global_ns_list; ns->translated && !got_canonical; ns =3D ns->sibling) { if (ns->derived_types) { for (gfc_symbol *dt =3D ns->derived_types; dt && !got_canonic= al; dt =3D dt->dt_next) { gfc_copy_dt_decls_ifequal (dt, derived, true); if (derived->backend_decl) got_canonical =3D true; if (dt->dt_next =3D=3D ns->derived_types) break; } } } } (ugh, linear walk of all namespaces and all derived types in them! A hash table would be much better) will find matching derived type in some other namespace and if it has backend_decl, will use it as TYPE_CANONICAL. All of resolve_symbol and resolve_fl_derived and resolve_fl_derived0 have an early exit for sym->attr.unlimited_polymorphic, so add_dt_to_dt_list isn't done for it but that isn't a big deal because gfc_get_derived_type for derived->attr.unlimited_polymorphic just returns ptr_type_node (the same in all namespaces). But __class__STAR_p symbol isn't unlimited_polymorphic, but in resolve_fl_derive we trigger: if (sym->attr.is_class && sym->ts.u.derived =3D=3D NULL) { /* Fix up incomplete CLASS symbols. */ gfc_component *data =3D gfc_find_component (sym, "_data", true, true, NULL); gfc_component *vptr =3D gfc_find_component (sym, "_vptr", true, true, NULL); /* Nothing more to do for unlimited polymorphic entities. */ if (data->ts.u.derived->attr.unlimited_polymorphic) return true; and so don't call resolve_fl_derived0, neither for sym nor for vptr, so nev= er call add_dt_to_dt_list for __class__STAR_p and so gfc_get_derived_type for those will always set TYPE_CANONICAL to its= elf, so each namespace's __class__STAR_p is considered to be private for TBAA purposes. --- gcc/fortran/resolve.cc.jj 2022-03-21 11:00:06.447824689 +0100 +++ gcc/fortran/resolve.cc 2022-03-22 12:35:38.381250338 +0100 @@ -15138,7 +15138,10 @@ resolve_fl_derived (gfc_symbol *sym) /* Nothing more to do for unlimited polymorphic entities. */ if (data->ts.u.derived->attr.unlimited_polymorphic) - return true; + { + add_dt_to_dt_list (sym); + return true; + } else if (vptr->ts.u.derived =3D=3D NULL) { gfc_symbol *vtab =3D gfc_find_derived_vtab (data->ts.u.derived); doesn't help much though, while it registers __class_STAR_p, gfc_get_derived_type -> gfc_copy_dt_decls_ifequal -> gfc_compare_derived_ty= pes considers them unequal.=