public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-103662-4-l3IRnpVKRn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103662-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
>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_types
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 == NULL
      && !derived->attr.use_assoc
      && !derived->attr.used_in_submodule
      && gfc_global_ns_list)
    {
      for (ns = gfc_global_ns_list;
           ns->translated && !got_canonical;
           ns = ns->sibling)
        {
          if (ns->derived_types)
            {
              for (gfc_symbol *dt = ns->derived_types; dt && !got_canonical;
                   dt = dt->dt_next)
                {
                  gfc_copy_dt_decls_ifequal (dt, derived, true);
                  if (derived->backend_decl)
                    got_canonical = true;
                  if (dt->dt_next == 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 == NULL)
    {
      /* Fix up incomplete CLASS symbols.  */
      gfc_component *data = gfc_find_component (sym, "_data", true, true,
NULL);
      gfc_component *vptr = 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 never
call add_dt_to_dt_list for __class__STAR_p
and so gfc_get_derived_type for those will always set TYPE_CANONICAL to itself,
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 == NULL)
        {
          gfc_symbol *vtab = 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_types
considers them unequal.

  parent reply	other threads:[~2022-03-22 11:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-11 19:25 [Bug fortran/103662] New: " hubicka at gcc dot gnu.org
2021-12-12  8:32 ` [Bug fortran/103662] " hubicka at gcc dot gnu.org
2021-12-14 15:51 ` cvs-commit at gcc dot gnu.org
2021-12-14 18:27 ` anlauf at gcc dot gnu.org
2021-12-14 18:34 ` hubicka at kam dot mff.cuni.cz
2021-12-14 21:53 ` seurer at gcc dot gnu.org
2021-12-15  9:08 ` clyon at gcc dot gnu.org
2022-01-04  9:32 ` rguenth at gcc dot gnu.org
2022-01-04  9:33 ` [Bug fortran/103662] [12 Regression] " rguenth at gcc dot gnu.org
2022-01-17 12:48 ` rguenth at gcc dot gnu.org
2022-01-17 17:36 ` hubicka at kam dot mff.cuni.cz
2022-01-18 14:09 ` rguenth at gcc dot gnu.org
2022-03-22 11:50 ` jakub at gcc dot gnu.org [this message]
2022-03-24 14:48 ` jakub at gcc dot gnu.org
2022-04-18 18:21 ` mikael at gcc dot gnu.org
2022-04-18 18:23 ` mikael at gcc dot gnu.org
2022-04-19 13:46 ` jakub at gcc dot gnu.org
2022-04-19 14:07 ` jakub at gcc dot gnu.org
2022-04-19 15:27 ` rguenth at gcc dot gnu.org
2022-04-19 16:12 ` mikael at gcc dot gnu.org
2022-04-19 16:51 ` jakub at gcc dot gnu.org
2022-04-20 10:16 ` hubicka at kam dot mff.cuni.cz
2022-04-24 13:32 ` cvs-commit at gcc dot gnu.org
2022-04-25  7:50 ` rguenth at gcc dot gnu.org
2022-04-25 11:32 ` cvs-commit at gcc dot gnu.org
2022-04-26  7:18 ` cvs-commit at gcc dot gnu.org
2022-04-26 14:57 ` hubicka at kam dot mff.cuni.cz
2022-04-27  9:36 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103662-4-l3IRnpVKRn@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).