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] PR29539 and PR29634 - derived_types without a proc_name causing an ICE.


:ADDPATCH fortran:

Both these PRs are associated with an ICE at the the same line in decl.c because the derived types being tested for an error do not have a proc_name.

The first part of the fix is "obvious" - exclude these derived types because the error does not apply to them.

However, the testcase for PR29634 is invalid code because it contains an interface for a contained function. This is detected gfc_match_function_decl and an appropriate error stacked away. However, the parser presses on here, just in case another matcher works and gfc_match_data_decl comes close to doing so. However, in returning MATCH_ERROR, it produces its own error, which overwrites the original with one complaining about the syntax. In order to fix this, I have added a new function to test the error buffer flag. If this is set, the new syntax error is not emitted and the old one retained.

Regtested on Cygwin_NT/amd64 - OK for trunk, 4.2 and 4.1?

Paul

2006-10-31 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29539
   PR fortran/29634
   * decl.c (variable_decl): Add test for presence of proc_name.
   * error.c (gfc_error_flag_test): New function.
   * gfortran.h : Prototype for gfc_error_flag_test.

2006-11-05 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/29539
   * gfortran.dg/gfortran.dg/blockdata_3.f90: New test.

   PR fortran/29634
   * gfortran.dg/gfortran.dg/derived_function_interface_1.f90: New test.

Index: gcc/fortran/decl.c
===================================================================
*** gcc/fortran/decl.c	(revision 118510)
--- gcc/fortran/decl.c	(working copy)
*************** variable_decl (int elem)
*** 1218,1223 ****
--- 1218,1224 ----
       that the interface may specify a procedure that is not pure if the procedure
       is defined to be pure(12.3.2).  */
    if (current_ts.type == BT_DERIVED
+ 	&& gfc_current_ns->proc_name
  	&& gfc_current_ns->proc_name->attr.if_source == IFSRC_IFBODY
  	&& current_ts.derived->ns != gfc_current_ns)
      {
*************** ok:
*** 2384,2390 ****
  	break;
      }
  
!   gfc_error ("Syntax error in data declaration at %C");
    m = MATCH_ERROR;
  
    gfc_free_data_all (gfc_current_ns);
--- 2385,2392 ----
  	break;
      }
  
!   if (gfc_error_flag_test () == 0)
!     gfc_error ("Syntax error in data declaration at %C");
    m = MATCH_ERROR;
  
    gfc_free_data_all (gfc_current_ns);
Index: gcc/fortran/gfortran.h
===================================================================
*** gcc/fortran/gfortran.h	(revision 118510)
--- gcc/fortran/gfortran.h	(working copy)
*************** void gfc_fatal_error (const char *, ...)
*** 1788,1793 ****
--- 1788,1794 ----
  void gfc_internal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_GCC_GFC(1,2);
  void gfc_clear_error (void);
  int gfc_error_check (void);
+ int gfc_error_flag_test (void);
  
  notification gfc_notification_std (int);
  try gfc_notify_std (int, const char *, ...) ATTRIBUTE_GCC_GFC(2,3);
Index: gcc/fortran/error.c
===================================================================
*** gcc/fortran/error.c	(revision 118510)
--- gcc/fortran/error.c	(working copy)
*************** gfc_clear_error (void)
*** 699,704 ****
--- 699,713 ----
  }
  
  
+ /* Tests the state of error_flag.  */
+ 
+ int
+ gfc_error_flag_test (void)
+ {
+   return error_buffer.flag;
+ }
+ 
+ 
  /* Check to see if any errors have been saved.
     If so, print the error.  Returns the state of error_flag.  */
  
Index: gcc/testsuite/gfortran.dg/derived_function_interface_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/derived_function_interface_1.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/derived_function_interface_1.f90	(revision 0)
***************
*** 0 ****
--- 1,40 ----
+ ! { dg-compile }
+ ! Tests the fix for PR29634, in which an ICE would occur in the
+ ! interface declaration of a function with an 'old-style' type
+ ! declaration.  When fixed, it was found that the error message
+ ! was not very helpful - this was fixed.
+ !
+ ! Contributed by Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+ !
+ type(foo) function ext_fun()
+   type foo
+     integer :: i
+   end type foo
+   ext_fun%i = 1
+ end function ext_fun
+ 
+   type foo
+     integer :: i
+   end type foo
+ 
+   interface fun_interface
+     type(foo) function fun()
+     end function fun
+   end interface
+ 
+   interface ext_fun_interface
+     type(foo) function ext_fun()
+     end function ext_fun
+   end interface
+ 
+   type(foo) :: x
+ 
+   x = ext_fun ()
+   print *, x%i
+ 
+ contains
+ 
+   type(foo) function fun() ! { dg-error "already has an explicit interface" }
+   end function fun  ! { dg-error "Expecting END PROGRAM" }
+ 
+ end
Index: gcc/testsuite/gfortran.dg/blockdata_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/blockdata_3.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/blockdata_3.f90	(revision 0)
***************
*** 0 ****
--- 1,28 ----
+ ! { dg-compile }
+ ! { dg-options "-W -Wall" }
+ ! Tests the fix for PR29539, in which the derived type in a blockdata
+ ! cause an ICE.  With the fix for PR29565, this now compiles and runs
+ ! correctly.
+ !
+ ! Contributed by Bernhard Fischer  <aldot@gcc.gnu.org>
+ !
+ block data
+   common /c/ d(5), cc
+   type c_t
+     sequence
+     integer i
+   end type c_t
+   type (c_t) :: cc
+   data d /5*1./
+   data cc%i /5/
+ end
+ 
+   common /c/ d(5), cc
+   type c_t
+     sequence
+     integer i
+   end type c_t
+   type (c_t) :: cc
+   print *, d
+   print *, cc
+ end
2006-10-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29539
	PR fortran/29634
	* decl.c (variable_decl): Add test for presence of proc_name.
	* error.c (gfc_error_flag_test): New function.
	* gfortran.h : Prototype for gfc_error_flag_test.

2006-11-05  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/29539
	* gfortran.dg/gfortran.dg/blockdata_3.f90: New test.

	PR fortran/29634
	* gfortran.dg/gfortran.dg/derived_function_interface_1.f90: New test.

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