Bug 14569 - [4.0 only] should not warn about truncated comment lines
Summary: [4.0 only] should not warn about truncated comment lines
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: tree-ssa
: P2 enhancement
Target Milestone: 4.0.1
Assignee: Richard Biener
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-03-13 10:56 UTC by Erik Schnetter
Modified: 2005-04-23 14:10 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 4.0.0
Last reconfirmed: 2005-03-29 01:43:56


Attachments
testcase for wrong filename/line information (92 bytes, text/plain)
2005-04-15 11:26 UTC, Richard Biener
Details
proposed patch (1.37 KB, patch)
2005-04-15 14:50 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Schnetter 2004-03-13 10:56:23 UTC
Gfortran warns when a comment line in fixed format is longer than 72 (?) 
characters when -Wall is enabled.  Such lines are often caused by CVS $Header$ 
statements, and truncating comment lines does no harm.  There should be an 
easy way to turn this warning off, and warn only about the more severe case of 
truncated lines of code.
Comment 1 Andrew Pinski 2004-03-13 16:13:52 UTC
Confirmed.
Comment 2 Tobias Schlüter 2004-04-30 13:43:46 UTC
This is not as easy as it seems, because comments get eaten after the scanner
has truncated overlong lines. This way the scanner needs to know much less about
the source code, it doesn't have to keep track if it is inside a character
string and it doesn't need to keep track of continuation lines. So I don't think
this is worth fixing, but I'll keep this on my list, maybe there's a solution I
couldn't yet think of.
Comment 3 Tobias Schlüter 2004-09-27 13:59:56 UTC
A possible solution, which I didn't yet have time to implement: when scanning,
record for each line if it has been truncated, but don't warn. Then, when moving
from line to line (in next_statement), check if the line had been truncated,
warn iff not in comment.
Comment 4 Richard Biener 2005-04-15 11:25:29 UTC
Another thing is, that the warning shows up as

alwazn:default> gfortran -Wall -Dlinux -ffixed-form -I. -I../../include -o
bounds.o -c bounds.F
Warning: /tmp/cciShzeh.f:1: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:101: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:171: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:112: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated
Warning: /tmp/cciShzeh.f:0: Line is being truncated

I.e. it doesn't translate back to the original filename and looks
confusing as line 0 is repeated endlessly.  Of course this seems
to be caused by the same problem.

Testcase for the second problem attached - output is

tmp> gfortran -c t.f -Wall
Warning: t.f:1: Line is being truncated
Warning: t.f:0: Line is being truncated
Warning: t.f:1: Line is being truncated
Warning: t.f:0: Line is being truncated

while it should be

Warning: bounds.F:1: Line is being truncated
Warning: ../../include/hh.inc:1: Line is being truncated
Warning: bounds.F:12: Line is being truncated
Warning: ../../include/hh.inc:1: Line is being truncated

and possibly avoid giving duplicate warnings on files included
multiple times.

Of course I also like the warning being disabled for comment lines.
Comment 5 Richard Biener 2005-04-15 11:26:21 UTC
Created attachment 8642 [details]
testcase for wrong filename/line information

Attached testcase.
Comment 6 Richard Biener 2005-04-15 11:30:03 UTC
Oh btw, looking into fixing all this.
Comment 7 Richard Biener 2005-04-15 14:50:04 UTC
Created attachment 8649 [details]
proposed patch

Proposed patch attached; it seems, error reporting interferes with warnings,
though.  Or error reporting causes line increment.  Or whatever is going wrong.


F.i we produce for

      SUBROUTINE foo(x,y)
      x =							  4.3	+ 1.2
      END

 In file /tmp/t2.f:2

      x =							  4.3	
								       1
Warning: Line truncated at (1)

but for

      SUBROUTINE foo(x,y)
      x =							  4.3 + 1.2
      END

 In file /tmp/t2.f:2

      x =							  4.3 + 
								      1
Error: Syntax error in expression at (1)


I'm probably missing something obvious.
Comment 8 Tobias Schlüter 2005-04-15 15:10:45 UTC
I didn't count columns, but why would you be surprised that 
  x = 4.3 +
is not a valid statement?  At least this seems to be the compiler's complaint in
your second example.
Comment 9 Richard Biener 2005-04-15 15:12:32 UTC
I'm surprised that the line truncation warning is omitted in the error case. 
Somewhere in the dark of the parser or error reporter someone advances to the
next line without my notice.
Comment 10 Tobias Schlüter 2005-04-15 15:15:48 UTC
The patch is ok.  IIRC I actually tried the exact same thing, except that I used
gfc_warning instead of gfc_warning_now (and indeed the latter makes a lot more
sense).
Comment 11 Tobias Schlüter 2005-04-15 15:17:56 UTC
(In reply to comment #9)
> I'm surprised that the line truncation warning is omitted in the error case. 
> Somewhere in the dark of the parser or error reporter someone advances to the
> next line without my notice.

Yes, I had just figured out that there's a problem WRT to this.  I guess that
next_statement is not called if the statement is not finished, as is the case
with the expression that is cut in half.
Comment 12 Tobias Schlüter 2005-04-15 15:27:35 UTC
Yes, this seems to be the case: when the statement matchers don't succeed, they
skip to the next line via gfc_error_recovery, see the bottom of
decode_statement.  therefore the if (gfc_at_eol ()) you changed doesn't trigger.

It looks like we should either have the statment matchers return a new statement
type ST_ERROR, and not advance across the end-of-statement, or code similar to
the code you added to next_statement is needed in gfc_error_recovery or thereabout.
Comment 13 Tobias Schlüter 2005-04-15 15:46:21 UTC
I just caught that you only sent the patch to gcc-patches@

Fortran patches should be sent to both gcc-patches@ and fortran@gcc.gnu.org, few
of the Fortran people are subscribed to gcc-patches.
Comment 14 Richard Biener 2005-04-15 18:23:30 UTC
Ok, I'm looking into implementing your suggestion.
Comment 15 Richard Biener 2005-04-15 20:01:12 UTC
It works by not advancing to the next line in gfc_error_recovery.  Final patch at
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg01768.html
Comment 16 GCC Commits 2005-04-15 20:35:31 UTC
Subject: Bug 14569

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rguenth@gcc.gnu.org	2005-04-15 20:35:26

Modified files:
	gcc/fortran    : ChangeLog gfortran.h parse.c scanner.c 

Log message:
	2005-04-15  Richard Guenther  <rguenth@gcc.gnu.org>
	
	PR fortran/14569
	* gfortran.h (gfc_linebuf): Add truncated field.
	* parse.c (next_statement): Handle warning for truncated
	lines.
	* scanner.c (load_line): Return if line was truncated.
	No longer warn for truncated lines.  Remove unused parameters.
	(load_file): Store load_line return value to linebuf.
	(gfc_error_recovery): Do not advance line at the end.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.393&r2=1.394
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/gfortran.h.diff?cvsroot=gcc&r1=1.64&r2=1.65
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/parse.c.diff?cvsroot=gcc&r1=1.25&r2=1.26
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/scanner.c.diff?cvsroot=gcc&r1=1.16&r2=1.17

Comment 17 GCC Commits 2005-04-23 14:09:11 UTC
Subject: Bug 14569

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rguenth@gcc.gnu.org	2005-04-23 14:09:02

Modified files:
	gcc/fortran    : ChangeLog gfortran.h parse.c scanner.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: wtruncate.f wtruncate.f90 

Log message:
	2005-04-23  Richard Guenther  <rguenth@gcc.gnu.org>
	
	PR fortran/14569
	* gfortran.h (gfc_linebuf): Add truncated field.
	* parse.c (next_statement): Handle warning for truncated lines.
	* scanner.c (load_line): Return if line was truncated.
	No longer warn for truncated lines.  Remove unused parameters.
	(load_file): Store load_line return value to linebuf.
	(gfc_next_char_literal): Reset truncation flag for lines ending
	in a comment for both fixed and free form.
	(gfc_error_recovery): Do not advance line at the end.
	
	* gfortran.dg/wtruncate.f: New testcase.
	* gfortran.dg/wtruncate.f90: New testcase.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.335.2.36&r2=1.335.2.37
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/gfortran.h.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.58.2.4&r2=1.58.2.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/parse.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.25&r2=1.25.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/scanner.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.16&r2=1.16.10.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.132&r2=1.5084.2.133
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/wtruncate.f.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/wtruncate.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 18 Richard Biener 2005-04-23 14:10:01 UTC
Applied to 4.0 branch.  Fixed.