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.
Confirmed.
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.
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.
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.
Created attachment 8642 [details] testcase for wrong filename/line information Attached testcase.
Oh btw, looking into fixing all this.
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.
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.
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.
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).
(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.
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.
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.
Ok, I'm looking into implementing your suggestion.
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
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
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
Applied to 4.0 branch. Fixed.