From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9308 invoked by alias); 26 Jul 2010 17:04:16 -0000 Received: (qmail 7202 invoked by uid 48); 26 Jul 2010 17:03:42 -0000 Date: Mon, 26 Jul 2010 17:04:00 -0000 Message-ID: <20100726170342.7200.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/40873] -fwhole-file -fwhole-program: Wrong decls cause too much to be optimized away In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "burnus at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-07/txt/msg02892.txt.bz2 ------- 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