From patchwork Sat Jul 24 16:33:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 59859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 26EEDB6F04 for ; Sun, 25 Jul 2010 02:33:40 +1000 (EST) Received: (qmail 27874 invoked by alias); 24 Jul 2010 16:33:35 -0000 Received: (qmail 27858 invoked by uid 22791); 24 Jul 2010 16:33:34 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 24 Jul 2010 16:33:28 +0000 Received: from [192.168.178.22] (port-92-204-52-63.dynamic.qsc.de [92.204.52.63]) by mx02.qsc.de (Postfix) with ESMTP id 5AF991E2A8; Sat, 24 Jul 2010 18:33:25 +0200 (CEST) Message-ID: <4C4B15D4.5070604@net-b.de> Date: Sat, 24 Jul 2010 18:33:24 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.10) Gecko/20100520 SUSE/3.0.5 Thunderbird/3.0.5 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran, committed] PR 40011 - Missing function generation (with -fwhole-file) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org PR 40011 was a quite interesting bug. As it turned out, the linker error /tmp/ccN7F1tB.o: In function `__mod_MOD_four': test.f90:(.text+0x3): undefined reference to `one_' is fully correct: gfortran simply did not generate the function "one" at all - only the call. The reason is that the gfc_global_ns_list gets overridden. Initially, it contains "two" with gfc_global_ns_lis->sibling being "one" (and no other following sibling). Somehow, gfortran decides to generate after "two" the main function - while "next" points to "two". What happens now that "next->sibling" is set to "MAIN__", breaking the link to "one", which is then never been generated. The fix is obvious. I included the test case as simple "dg-do link" test, but one can also do it fancier. Build, regtested (RUNTESTFLAGS="--target_board=unix/{-m64,-m32} - and also libgomp tested) on x86-64-linux. Committed as Rev. 162500. Tobias 2010-07-24 Tobias Burnus PR fortran/40011 * parse.c (gfc_parse_file): Do not override gfc_global_ns_list items. 2010-07-24 Tobias Burnus PR fortran/40011 * gfortran.dg/whole_file_21.f90: New. * gfortran.dg/integer_exponentiation_3.F90: Use -ffloat-store only for i?86/x86-64 -m32. Index: gcc/testsuite/gfortran.dg/whole_file_21.f90 =================================================================== --- gcc/testsuite/gfortran.dg/whole_file_21.f90 (Revision 0) +++ gcc/testsuite/gfortran.dg/whole_file_21.f90 (Revision 0) @@ -0,0 +1,27 @@ +! { dg-do link } +! PR fortran/40011 +! +! Contributed by Joost VandeVondele +! +! +! Before no "one" function was generated with -fwhole-file. +! +! +SUBROUTINE one ( ) +END SUBROUTINE one + +SUBROUTINE two ( ) +END SUBROUTINE two + +MODULE mod +CONTAINS + SUBROUTINE three ( ) + CALL two ( ) + END SUBROUTINE three + SUBROUTINE four ( ) + CALL one ( ) + END SUBROUTINE four +END MODULE mod +END + +! { dg-final { cleanup-modules "m" } } Index: gcc/testsuite/gfortran.dg/integer_exponentiation_3.F90 =================================================================== --- gcc/testsuite/gfortran.dg/integer_exponentiation_3.F90 (Revision 162499) +++ gcc/testsuite/gfortran.dg/integer_exponentiation_3.F90 (Arbeitskopie) @@ -1,8 +1,8 @@ ! { dg-do run { xfail spu-*-* } } ! FAILs on SPU because of wrong compile-time rounding mode -! { dg-options "-ffloat-store" } +! { dg-options "" } +! { dg-options "-ffloat-store" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } ! -! -ffloat-store needed for x87 ! module mod_check implicit none Index: gcc/fortran/parse.c =================================================================== --- gcc/fortran/parse.c (Revision 162499) +++ gcc/fortran/parse.c (Arbeitskopie) @@ -4414,7 +4414,11 @@ prog_units: later and all their interfaces resolved. */ gfc_current_ns->code = s.head; if (next) - next->sibling = gfc_current_ns; + { + for (; next->sibling; next = next->sibling) + ; + next->sibling = gfc_current_ns; + } else gfc_global_ns_list = gfc_current_ns;