This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR33550 - ICE (segfault) when USEing ambiguous symbols


:ADDPATCH fortran:

This annoying bug emerged from the woodwork in discussion of PR33542
on comp.lang.fortran

Thanks to James Buskirk for pointing it out and to Tobias Burnus for posting it.

The fix is utterly trivial.  It bootstraps and regtests on
x86_ia64/fc5 - OK for trunk?

Paul

-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy

Attachment: Change.Logs
Description: Binary data

Index: /svn/trunk/gcc/fortran/decl.c
===================================================================
--- /svn/trunk/gcc/fortran/decl.c	(revision 128873)
+++ /svn/trunk/gcc/fortran/decl.c	(working copy)
@@ -669,7 +669,7 @@
 {
   gfc_symtree *st;
   gfc_symbol *sym;
-  int rc;
+  int rc = 0;
 
   /* Module functions have to be left in their own namespace because
      they have potentially (almost certainly!) already been referenced.
@@ -706,6 +706,9 @@
   else
     rc = gfc_get_symbol (name, gfc_current_ns->parent, result);
 
+  if (rc)
+    return rc;
+
   sym = *result;
   gfc_current_ns->refs++;
 
Index: /svn/trunk/gcc/testsuite/gfortran.dg/ambiguous_reference_1.f90
===================================================================
--- /svn/trunk/gcc/testsuite/gfortran.dg/ambiguous_reference_1.f90	(revision 0)
+++ /svn/trunk/gcc/testsuite/gfortran.dg/ambiguous_reference_1.f90	(revision 0)
@@ -0,0 +1,50 @@
+! { dg-do compile }
+! Tests the fix for PR33550, in which an ICE would occur, instead of
+! the abiguous reference error.
+!
+! Found at
+! http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1abc1549a6a164f1/
+! by James Van Buskirk:
+!
+module M1
+   real x
+end module M1
+
+module M2
+   contains
+      subroutine y
+      end subroutine y
+end module M2
+
+module M3
+   use M2, x => y
+end module M3
+
+module M4
+   use M1
+   use M3
+end module M4
+
+module M5
+   use M4             ! 'x' is ambiguous here but is not referred to
+end module M5
+
+module M6
+   use M5             ! ditto
+end module M6
+
+program test
+   use M1
+   use M3
+   interface
+      function x(z)   ! { dg-error "ambiguous reference" }
+      end function x  ! { dg-error "Expecting END INTERFACE" }
+   end interface
+
+   write(*,*) 'Hello, world!'
+end program test
+
+function x(z)
+   x = z
+end function x
+! { dg-final { cleanup-modules "m1 m2 m3 m4 m5 m6" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]