Bug 38404 - Warning message identifies incorrect line
Summary: Warning message identifies incorrect line
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.2
: P3 minor
Target Milestone: 4.6.0
Assignee: Daniel Franke
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2008-12-04 17:02 UTC by Steve Chapel
Modified: 2010-05-19 12:56 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-05-13 12:30:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Chapel 2008-12-04 17:02:41 UTC
When the following program (truncbug.f) is compiled with gfortran 4.3.2:

      SUBROUTINE ERRMSG(N,STRING,LST)
      CHARACTER*72 TEXT(2)
      DATA (TEXT(I),I=1,2)/
     X'MUST BE "CALL SIMEPS(EPS)"',
     X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T
     XHE CALL.'/
      END

This warning message results:

truncbug.f:4.72:

     X'MUST BE "CALL SIMEPS(EPS)"',                                     
                                                                       1
Warning: initialization string truncated to match variable at (1)

This is two lines before the line that the string truncation occurs on. Ideally, gfortran should put the (1) mark at the character in the string where the truncation occurs.
Comment 1 Daniel Franke 2010-05-13 12:30:30 UTC
Suggested patch:
    http://gcc.gnu.org/ml/fortran/2010-05/msg00116.html
Comment 2 Steve Chapel 2010-05-13 13:15:02 UTC
Excellent! The new warning is far more understandable than the old.

     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

If it's difficult to place the error marker at the location the string was truncated, would it be easy to list the number of characters in the initialization string, so that one would not have to count characters to determine how many characters need to be removed, or how much larger to make the variable?

Example:

     X'"R" IN CALL RANDOM MAY NOT BE USED OUTSIDE THE BLOCK CONTAINING T
       1
Warning: Initialization string of 73 characters starting at (1) was
truncated after 72 characters to match the variable
Comment 3 Daniel Franke 2010-05-13 13:26:04 UTC
That's easily doable. Alternative patch for data.c below gives:

$ gfortran-svn pr38404.f 
pr38404.f:5.7:

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

(Modified the message to be similar to many other actual-size/expected-size outputs)


Index: data.c
===================================================================
--- data.c      (revision 159348)
+++ data.c      (working copy)
@@ -154,9 +154,10 @@ create_character_intializer (gfc_expr *i
 
   if (len > end - start)
     {
+      gfc_warning_now ("Initialization string starting at %L was "
+                      "truncated to fit the variable (%d/%d)",
+                      &rvalue->where, len, end - start);
       len = end - start;
-      gfc_warning_now ("initialization string truncated to match variable "
-                      "at %L", &rvalue->where);
     }
 
   if (rvalue->ts.type == BT_HOLLERITH)
Comment 4 Steve Chapel 2010-05-13 16:28:00 UTC
:)
Comment 5 Daniel Franke 2010-05-19 12:55:44 UTC
Subject: Bug 38404

Author: dfranke
Date: Wed May 19 12:55:26 2010
New Revision: 159561

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159561
Log:
gcc/fortran/:
2010-05-19  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-19  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.


Added:
    trunk/gcc/testsuite/gfortran.dg/data_array_6.f
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/data_char_1.f90

Comment 6 Daniel Franke 2010-05-19 12:56:58 UTC
Fixed in trunk. Closing.
Thanks for the report!