From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12093 invoked by alias); 24 Jul 2010 19:13:55 -0000 Received: (qmail 12032 invoked by uid 48); 24 Jul 2010 19:13:43 -0000 Date: Sat, 24 Jul 2010 19:13:00 -0000 Message-ID: <20100724191343.12031.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/msg02677.txt.bz2 ------- Comment #18 from burnus at gcc dot gnu dot org 2010-07-24 19:13 ------- (In reply to comment #17) > comment 1 still fails with current trunk (In reply to comment #1) > subroutine two() > call three() > end subroutine two > > subroutine three() > end subroutine three The problem is that one first generates code for "two" and thus calls gfc_get_extern_function_decl to generate the decl for "three" - there is no existing declaration. As next step, one works on "three" and calls gfc_create_function_decl which creates another declaration. The test case in comment 1 and the one in comment 16 (with the bogus "use demo" comment out) worked with an initial version of the following patch. However, it give an ICE for the test in comment 4: 22.f90:5:0: internal compiler error: in build_function_decl, at fortran/trans-decl.c:1599 The solution was to make the newly generated procedure as global - which it surely is - otherwise, it were not accessible. Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (Revision 162502) +++ gcc/fortran/trans-decl.c (Arbeitskopie) @@ -1411,9 +1411,19 @@ gfc_get_extern_function_decl (gfc_symbol && !sym->attr.use_assoc && !sym->backend_decl && gsym && gsym->ns - && ((gsym->type == GSYM_SUBROUTINE) || (gsym->type == GSYM_FUNCTION)) - && gsym->ns->proc_name->backend_decl) + && ((gsym->type == GSYM_SUBROUTINE) || (gsym->type == GSYM_FUNCTION))) { + if (!gsym->ns->proc_name->backend_decl) + { + tree save_fn_decl = current_function_decl; + /* By construction, the external function cannot be + a contained procedure. */ + current_function_decl = NULL_TREE; + gfc_create_function_decl (gsym->ns); + current_function_decl = save_fn_decl; + gcc_assert (gsym->ns->proc_name->backend_decl); + } + /* If the namespace has entries, the proc_name is the entry master. Find the entry and use its backend_decl. otherwise, use the proc_name backend_decl. */ -- burnus at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|pault at gcc dot gnu dot org|burnus at gcc dot gnu dot | |org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40873