public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/40873] -fwhole-file -fwhole-program: Wrong decls cause too much to be optimized away
Date: Mon, 26 Jul 2010 17:04:00 -0000	[thread overview]
Message-ID: <20100726170342.7200.qmail@sourceware.org> (raw)
In-Reply-To: <bug-40873-13404@http.gcc.gnu.org/bugzilla/>



------- Comment #25 from burnus at gcc dot gnu dot org  2010-07-26 17:03 -------
(In reply to comment #23)
> Created an attachment (id=21315)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21315&action=view) [edit]
> New trans-decl.c patch - seems to work well

Dominique has found a failure (segfault) with PR 31867 comment 6.

If one generates in gfc_get_extern_function_decl the code for "lensum", one
finds that its argument "words" has locally the correct type:
  (gdb) p sym->formal->sym->as->type
  $4 = AS_ASSUMED_SHAPE
but the gsym has the wrong type
  (gdb) p gsym->ns->proc_name->formal->sym->as->type
  $10 = AS_DEFERRED
Thus, one enters the code path for descriptor-free arrays and crashes as UBOUND
is NULL.

In principle, this should get fixed in resolve_formal_arglist. One problem is
that if one enters find_arglists sym->ns != gfc_current_ns it fails.

But the actual problems seems to be in resolve_global_procedure. One has:

(gdb) p sym->attr.if_source
$27 = IFSRC_IFBODY
(gdb) p sym->formal->sym->as->type
$28 = AS_ASSUMED_SHAPE

That is: The symbol in the interface block of the module is resolved. But the
gsym is not:

(gdb) p gsym->ns->resolved
$29 = 0
(gdb) p gsym->ns->proc_name->formal->sym->as->type
$30 = AS_DEFERRED

The following patch fixes the program. (Side remark, one could do more argument
checking, cf. PR 45086.)

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 162538)
+++ gcc/fortran/resolve.c       (working copy)
@@ -1816,7 +1816,8 @@ resolve_global_procedure (gfc_symbol *sy
     gfc_global_used (gsym, where);

   if (gfc_option.flag_whole_file
-       && sym->attr.if_source == IFSRC_UNKNOWN
+       && (sym->attr.if_source == IFSRC_UNKNOWN
+           || sym->attr.if_source == IFSRC_IFBODY)
        && gsym->type != GSYM_UNKNOWN
        && gsym->ns
        && gsym->ns->resolved != -1
@@ -1902,7 +1903,7 @@ resolve_global_procedure (gfc_symbol *sy
                   sym->name, &sym->declared_at, gfc_typename (&sym->ts),
                   gfc_typename (&def_sym->ts));

-      if (def_sym->formal)
+      if (def_sym->formal && sym->attr.if_source != IFSRC_IFBODY)
        {
          gfc_formal_arglist *arg = def_sym->formal;
          for ( ; arg; arg = arg->next)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40873


  parent reply	other threads:[~2010-07-26 17:04 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27 13:57 [Bug fortran/40873] New: " burnus at gcc dot gnu dot org
2009-07-27 14:47 ` [Bug fortran/40873] " burnus at gcc dot gnu dot org
2009-07-28 13:12 ` rguenth at gcc dot gnu dot org
2009-09-22 15:34 ` rguenth at gcc dot gnu dot org
2009-09-22 15:42 ` rguenth at gcc dot gnu dot org
2010-05-15 19:54 ` dominiq at lps dot ens dot fr
2010-05-16 10:53 ` rguenth at gcc dot gnu dot org
2010-05-16 11:01 ` dominiq at lps dot ens dot fr
2010-05-16 11:04 ` rguenther at suse dot de
2010-05-16 11:17 ` dominiq at lps dot ens dot fr
2010-05-16 11:21 ` rguenther at suse dot de
2010-05-20 13:51 ` pault at gcc dot gnu dot org
2010-05-24 12:32 ` pault at gcc dot gnu dot org
2010-05-26 14:28 ` burnus at gcc dot gnu dot org
2010-05-26 14:41 ` dominiq at lps dot ens dot fr
2010-05-26 14:46 ` burnus at gcc dot gnu dot org
2010-06-09 22:10 ` fxcoudert at gcc dot gnu dot org
2010-07-24 18:15 ` jv244 at cam dot ac dot uk
2010-07-24 19:13 ` burnus at gcc dot gnu dot org
2010-07-24 20:16 ` burnus at gcc dot gnu dot org
2010-07-24 22:05 ` burnus at gcc dot gnu dot org
2010-07-25 10:03 ` dominiq at lps dot ens dot fr
2010-07-25 10:14 ` burnus at gcc dot gnu dot org
2010-07-26 13:25 ` burnus at gcc dot gnu dot org
2010-07-26 17:02 ` dominiq at lps dot ens dot fr
2010-07-26 17:04 ` burnus at gcc dot gnu dot org [this message]
2010-07-26 21:00 ` dominiq at lps dot ens dot fr
2010-07-27  8:44 ` burnus at gcc dot gnu dot org
2010-07-27  8:46 ` burnus at gcc dot gnu dot 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=20100726170342.7200.qmail@sourceware.org \
    --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).