[PATCH] Fix PR47839
Richard Guenther
rguenther@suse.de
Wed Feb 23 12:01:00 GMT 2011
This avoids putting extern decls with NULL DECL_CONTEXT into the
BLOCK tree, which is bogus and confuses LTO and dwarf2out. The
proper way to bring externs into scope is to insert a decl copy
with function DECL_CONTEXT into the BLOCKs (into every relevant
block, not just the first as done by the FE).
Bootstrapped and tested on x86_64-unknown-linux-gnu, I also built
SPEC with -flto and debug-info to verify this ICE is fixed.
Ok?
Thanks,
Richard.
2011-02-23 Richard Guenther <rguenther@suse.de>
PR fortran/47839
* f95-lang.c (pushdecl): For externs in non-global scope push
a copy of the decl into the BLOCK.
* gfortran.dg/lto/pr47839_0.f90: New testcase.
* gfortran.dg/lto/pr47839_1.f90: Likewise.
Index: gcc/fortran/f95-lang.c
===================================================================
*** gcc/fortran/f95-lang.c (revision 170407)
--- gcc/fortran/f95-lang.c (working copy)
*************** poplevel (int keep, int reverse, int fun
*** 498,510 ****
tree
pushdecl (tree decl)
{
! /* External objects aren't nested, other objects may be. */
! if (DECL_EXTERNAL (decl))
! DECL_CONTEXT (decl) = NULL_TREE;
! else if (global_bindings_p ())
DECL_CONTEXT (decl) = current_translation_unit;
else
! DECL_CONTEXT (decl) = current_function_decl;
/* Put the declaration on the list. The list of declarations is in reverse
order. The list will be reversed later if necessary. This needs to be
--- 498,517 ----
tree
pushdecl (tree decl)
{
! if (global_bindings_p ())
DECL_CONTEXT (decl) = current_translation_unit;
else
! {
! /* External objects aren't nested. For debug info insert a copy
! of the decl into the binding level. */
! if (DECL_EXTERNAL (decl))
! {
! tree orig = decl;
! decl = copy_node (decl);
! DECL_CONTEXT (orig) = NULL_TREE;
! }
! DECL_CONTEXT (decl) = current_function_decl;
! }
/* Put the declaration on the list. The list of declarations is in reverse
order. The list will be reversed later if necessary. This needs to be
Index: gcc/testsuite/gfortran.dg/lto/pr47839_0.f90
===================================================================
*** gcc/testsuite/gfortran.dg/lto/pr47839_0.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/lto/pr47839_0.f90 (revision 0)
***************
*** 0 ****
--- 1,8 ----
+ ! { dg-lto-do link }
+ ! { dg-lto-options {{ -g -flto }} }
+ ! { dg-extra-ld-options "-r -nostdlib" }
+
+ MODULE globalvar_mod
+ integer :: xstop
+ CONTAINS
+ END MODULE globalvar_mod
Index: gcc/testsuite/gfortran.dg/lto/pr47839_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/lto/pr47839_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/lto/pr47839_1.f90 (revision 0)
***************
*** 0 ****
--- 1,7 ----
+ MODULE PEC_mod
+ CONTAINS
+ SUBROUTINE PECapply(Ex)
+ USE globalvar_mod, ONLY : xstop
+ real(kind=8), dimension(1:xstop), intent(inout) :: Ex
+ END SUBROUTINE PECapply
+ END MODULE PEC_mod
More information about the Fortran
mailing list