From patchwork Fri Nov 25 10:46:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 127666 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 CB8791007D5 for ; Fri, 25 Nov 2011 21:47:04 +1100 (EST) Received: (qmail 12332 invoked by alias); 25 Nov 2011 10:46:59 -0000 Received: (qmail 12318 invoked by uid 22791); 25 Nov 2011 10:46:58 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 25 Nov 2011 10:46:44 +0000 Received: from [192.168.178.22] (port-92-204-12-48.dynamic.qsc.de [92.204.12.48]) by mx01.qsc.de (Postfix) with ESMTP id 2E9133D81E; Fri, 25 Nov 2011 11:46:38 +0100 (CET) Message-ID: <4ECF720D.8020303@net-b.de> Date: Fri, 25 Nov 2011 11:46:37 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 50408 [4.6/4.7] ICE related to whole-file processing 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 The patch fixes an issue when the backend_decl is reused (-fwhole-file). The problem is that not always the ts.u.derived->backend_decl was copied as well. I copied what was done a bit later in the file and extended it to also include BT_CLASS. The trans-type.c change is not needed, but I thought it is a good optimization. from == to seems to happen quite regularly. Build and regtested on x86-64-linux. OK for the trunk and 4.6? Tobias PS: It also affects 4.5 if one uses -fwhole-file. However, my impression is that no one uses that option with 4.5 and other whole-file bugs have only been fixed for 4.6. But if you think one should backport it to 4.5, I can surely do so. 2011-11-25 Tobias Burnus PR fortran/50408 * trans-decl.c (gfc_get_module_backend_decl): Also copy ts.u.derived from the gsym if the ts.type is BT_CLASS. (gfc_get_extern_function_decl): Copy also the backend_decl for the symbol's ts.u.{derived,cl} from the gsym. * trans-types.c (gfc_copy_dt_decls_ifequal): Directly return if "from" and "to" are the same. 2011-11-25 Tobias Burnus PR fortran/50408 * gfortran.dg/whole_file_35.f90: New. diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index fc8a9ed..39ec8cd 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -718,7 +718,7 @@ gfc_get_module_backend_decl (gfc_symbol *sym) } else if (s->backend_decl) { - if (sym->ts.type == BT_DERIVED) + if (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS) gfc_copy_dt_decls_ifequal (s->ts.u.derived, sym->ts.u.derived, true); else if (sym->ts.type == BT_CHARACTER) @@ -1670,6 +1670,11 @@ gfc_get_extern_function_decl (gfc_symbol * sym) gfc_find_symbol (sym->name, gsym->ns, 0, &s); if (s && s->backend_decl) { + if (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS) + gfc_copy_dt_decls_ifequal (s->ts.u.derived, sym->ts.u.derived, + true); + else if (sym->ts.type == BT_CHARACTER) + sym->ts.u.cl->backend_decl = s->ts.u.cl->backend_decl; sym->backend_decl = s->backend_decl; return sym->backend_decl; } diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 3f4ebd5..d643c2e 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -2188,6 +2188,9 @@ gfc_copy_dt_decls_ifequal (gfc_symbol *from, gfc_symbol *to, gfc_component *to_cm; gfc_component *from_cm; + if (from == to) + return 1; + if (from->backend_decl == NULL || !gfc_compare_derived_types (from, to)) return 0; --- /dev/null 2011-11-22 07:52:35.375586753 +0100 +++ gcc/gcc/testsuite/gfortran.dg/whole_file_35.f90 2011-11-25 09:30:18.000000000 +0100 @@ -0,0 +1,28 @@ +! { dg-do compile } +! +! PR fortran/50408 +! +! Contributed by Vittorio Zecca +! + module m + type int + integer :: val + end type int + interface ichar + module procedure uch + end interface + contains + function uch (c) + character (len=1), intent (in) :: c + type (int) :: uch + intrinsic ichar + uch%val = 127 - ichar (c) + end function uch + end module m + + program p + use m + print *,ichar('~') ! must print "1" + end program p + +! { dg-final { cleanup-modules "m" } }