This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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] PR38404 - improve error location


Hi all.

Error location is sometimes a bit off. Sometimes more so.
This test gives ...

      CHARACTER*72 TEXT(1)
      DATA TEXT(1)/
     X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T
     XHE CALL.'/
      END

$> gfortran-4.5 pr38404.f 
pr38404.f:3.72:

      DATA TEXT(1)/                                                     
                                                                        1
Warning: initialization string truncated to match variable at (1)

Problem being that the matcher for string constants saves the position just 
outside string. Thus, reading the first character advances the line. On 
warning/error, the start location is used - which points to the previous line. 
Attached patch modifies this to save the position just inside the string. 
Also, I rephrased the message to make it clearer what we actually point at.

For above test, the output now is:
$> gfortran-svn pr38404.f 
pr38404.f:4.7:

     X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T
       1
Warning: Initialization string starting at (1) was truncated after 72 
characters to match the variable

Actually placing the error marker at the location of the runcation would be 
preferrable, but that's not so simple.


gcc/fortran/:
2010-05-11  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/38404
	* primary.c (match_string_constant): Move start_locus just inside 
	the string.
	* data.c (create_character_intializer): Clarified truncation warning.

gcc/testsuite/:
2010-05-11  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/38404
	* gfortran.dg/data_char_1.f90: Updated warning message.
	* gfortran.dg/data_array_6.f: New.


Regression tested on i686-pc-linux-gnu.
Ok for trunk?

	Daniel


P.S. It's not two weeks yet, but ...
	http://gcc.gnu.org/ml/fortran/2010-05/msg00057.html :)
Index: primary.c
===================================================================
--- primary.c	(revision 159211)
+++ primary.c	(working copy)
@@ -868,12 +868,11 @@ match_string_constant (gfc_expr **result
 
   gfc_gobble_whitespace ();
 
-  start_locus = gfc_current_locus;
-
   c = gfc_next_char ();
   if (c == '\'' || c == '"')
     {
       kind = gfc_default_character_kind;
+      start_locus = gfc_current_locus;
       goto got_delim;
     }
 
@@ -917,12 +916,13 @@ match_string_constant (gfc_expr **result
     goto no_match;
 
   gfc_gobble_whitespace ();
-  start_locus = gfc_current_locus;
 
   c = gfc_next_char ();
   if (c != '\'' && c != '"')
     goto no_match;
 
+  start_locus = gfc_current_locus;
+
   if (kind == -1)
     {
       q = gfc_extract_int (sym->value, &kind);
@@ -976,7 +976,6 @@ got_delim:
   e->ts.is_iso_c = 0;
 
   gfc_current_locus = start_locus;
-  gfc_next_char ();		/* Skip delimiter */
 
   /* We disable the warning for the following loop as the warning has already
      been printed in the loop above.  */
Index: data.c
===================================================================
--- data.c	(revision 159211)
+++ data.c	(working copy)
@@ -155,8 +155,9 @@ create_character_intializer (gfc_expr *i
   if (len > end - start)
     {
       len = end - start;
-      gfc_warning_now ("initialization string truncated to match variable "
-		       "at %L", &rvalue->where);
+      gfc_warning_now ("Initialization string starting at %L was "
+		       "truncated after %d characters to fit the "
+		       "variable", &rvalue->where, len);
     }
 
   if (rvalue->ts.type == BT_HOLLERITH)

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