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] PR57895 - avoid segfault and improve diagnostic


Without this patch, GCC 4.3 and later segfault. As Mikael wrote: "gfc_restore_last_undo_checkpoint seems to take care of the cleanup, so we don't need to do it in gfc_match_common."

Additionally, this patch ensures that the error message about the "$" gets printed - without the change, it doesn't. Initially I had gfc_error_now instead of gfc_fatal_error. However, that gave tons of nonhelpful errors for the original test case - and for the test case in this patch, it prints the same message around twenty times. Hence, gfc_fatal_error is much more reasonable - even if the test case then no longer checks for the double free.

Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

PS: Formally, it would qualify as regression as GCC 4.1 doesn't crash but prints "Syntax error in COMMON statement". Thus, if any one prefers, we could also backport the patch to the maintained branches.
2013-07-17  Mikael Morin  <mikael@gcc.gnu.org>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/57895
	* match.c (gfc_match_name): Ensure that the error
	message regarding -fdollar-ok gets printed.
	(gfc_match_common): Avoid multiple freeing.

2013-07-17  Tobias Burnus  <burnus@net-b.de>

	PR fortran/57895
	* gfortran.dg/dollar_sym_3.f: New.
	* gfortran.dg/dollar_sym_1.f90: Update dg-error.

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 2533584..9ce4723 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -556,8 +556,8 @@ gfc_match_name (char *buffer)
 
   if (c == '$' && !gfc_option.flag_dollar_ok)
     {
-      gfc_error ("Invalid character '$' at %C. Use -fdollar-ok to allow it "
-		 "as an extension");
+      gfc_fatal_error ("Invalid character '$' at %C. Use -fdollar-ok to allow "
+		       "it as an extension");
       return MATCH_ERROR;
     }
 
@@ -4520,10 +4520,6 @@ syntax:
   gfc_syntax_error (ST_COMMON);
 
 cleanup:
-  if (old_blank_common)
-    old_blank_common->common_next = NULL;
-  else
-    gfc_current_ns->blank_common.head = NULL;
   gfc_free_array_spec (as);
   return MATCH_ERROR;
 }
--- /dev/null	2013-07-17 09:16:46.664064383 +0200
+++ gcc/gcc/testsuite/gfortran.dg/dollar_sym_3.f	2013-07-17 12:09:31.853146069 +0200
@@ -0,0 +1,10 @@
+! { dg-do compile }
+!
+! PR fortran/57895
+!
+! Contributed by Vittorio Zecca
+!
+c Segmentation fault in gfc_restore_last_undo_checkpoint
+      COMMON RADE3155V62$JUTMU9L9E(3,3,3), LADE314JUTMP9         ! { dg-error "Invalid character '\\$' at .1.. Use -fdollar-ok to allow it as an extension" }
+     +LHEDDJNTMP9L(3,3,3)                                                       
+      end
diff --git a/gcc/testsuite/gfortran.dg/dollar_sym_1.f90 b/gcc/testsuite/gfortran.dg/dollar_sym_1.f90
index 37f0f88..6c0dfcb 100644
--- a/gcc/testsuite/gfortran.dg/dollar_sym_1.f90
+++ b/gcc/testsuite/gfortran.dg/dollar_sym_1.f90
@@ -3,7 +3,7 @@
 ! Variable names containing $ signs
 ! 
       REAL*4 PLT$C_HOUSTPIX   ! { dg-error "Invalid character '\\$'" }
-      INTEGER PLT$C_COMMAND   ! { dg-error "Invalid character '\\$'" }
-      PARAMETER (PLT$B_OPC=0) ! { dg-error "Invalid character '\\$'" }
-      common /abc$def/ PLT$C_HOUSTPIX, PLT$C_COMMAND ! { dg-error "Invalid character '\\$'" }
+      INTEGER PLT$C_COMMAND   ! Unreachable as the error above is now fatal
+      PARAMETER (PLT$B_OPC=0) !  Unreachable as the error above is now fatal
+      common /abc$def/ PLT$C_HOUSTPIX, PLT$C_COMMAND !  Unreachable as the error above is now fatal
       end

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