Bug 44054 - Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragmas) and color
Summary: Handle -Werror, -Werror=, -fdiagnostics-show-option, !GCC$ diagnostic (pragma...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 53552 58189 (view as bug list)
Depends on: 62226
Blocks: 53934 58189
  Show dependency treegraph
 
Reported: 2010-05-10 10:20 UTC by Tobias Burnus
Modified: 2018-02-19 04:47 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-05-15 00:44:07


Attachments
proof of concept (3.19 KB, patch)
2014-04-16 19:58 UTC, Manuel López-Ibáñez
Details | Diff
proof of concept #2 (5.20 KB, patch)
2014-04-21 15:19 UTC, Manuel López-Ibáñez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-05-10 10:20:53 UTC
The middle end now supports besides -Werror also -Werror=list, where -Werror=<foo> implies -W<foo>. Additionally, the middle end also annotates via -fdiagnostics-show-option (enabled by default) the messages with the warning-flag name in parentheses:

-Wuninitialized  (or, e.g.: -Wall)
  foo.c:4:2: warning: 'j' is used uninitialized in this function [-Wuninitialized]
-Wuninitialized -fno-diagnostics-show-option:
  foo.c:4:2: warning: 'j' is used uninitialized in this function
-Werror=uninitialized (or, e.g.: -Werror -Wall)
  foo.c:4:2: error: 'j' is used uninitialized in this function [-Werror=uninitialized]


Expected:

a) -Werror  caues gfortran to print "Error" rather than "Warning"; currently it only changes the exit status code (and the total error count)

b) -f(no-)diagnostics-show-option is supported by printing the flag in parenthesis after the warning

c) -Werror=<list> is supported.
Comment 1 Tobias Burnus 2010-05-10 10:30:50 UTC
-Werror= was added 2006 ( http://gcc.gnu.org/viewcvs?view=revision&revision=109907 ) and the -fdiagnostics-show-option already exists since 2005 (http://gcc.gnu.org/viewcvs?view=revision&revision=99169 ) - though it has only be enabled very recently, cf. http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00910.html
Comment 2 Daniel Franke 2010-05-10 16:58:33 UTC
This probably superseeds (accompanies?) PR31601.
Comment 3 Tobias Burnus 2010-05-10 17:16:41 UTC
(In reply to comment #2)
> This probably superseeds (accompanies?) PR31601.

Not really. This is about warnings - the other is about errors due to -std=. For warnings, the purpose is to help fine-tuning the warnings - while for errors (-std=, -f(no-)range-check) the idea is to point the user to an option, which allows him/her to still compile the program. 

(Sometimes one is simply not aware that a certain option exists - and especially non-Fortran programmers tend to compile legacy Fortran programs. But even I tend to forget about. e.g., -std=legacy or -fdollar-ok.)
Comment 4 Manuel López-Ibáñez 2010-05-15 00:44:07 UTC
It would be so nice if there was a single diagnostics library that all FEs could use and help to enhance. Something configurable, flexible and powerful like LLVM's diagnostics library. Then Fortran could configure the library to get a consistent output. Maybe pooling resources we could get caret diagnostics, ranges, xml output, color, fix-it hints, spell-checker and a few other features that LLVM already has.

Comment 5 Manuel López-Ibáñez 2014-04-16 19:58:58 UTC
Created attachment 32622 [details]
proof of concept

The attached patch is a proof of concept. It gives the following output:

/home/manuel/test1/test-gfc-warning.f03:11:0:
Warning: Possible change of value in conversion from INTEGER(8) to INTEGER(4) at (1) [-Wconversion]
   arr = (/ INTEGER(KIND=4) :: HUGE(0_8) /) ! { dg-warning "conversion from" }
 ^

This warning is controllable by -Wno-conversion, -Werror=conversion and the #pragma GCC diagnostic. Also the diagnostic is in color (unfortunately it does not show it here).

Contrary to what I said above, I think it is actually easier for Fortran to use the common pretty printer rather than fake their own. It will also remove quite a bit of duplicated code from the Fortran FE. The transition can be done in the following steps (I chose the wrong warning to start with):

1. Warnings that don't use %L (so initially you don't have to deal with locus)
2. Warnings that use %C
3. Warnings that use one %L
4. Warnings that use two %L


If there is one or more willing Fortran developers that wants to tackle this for the next release, I think the four steps are feasible within one release. To fully match the current Fortran diagnostics, the common diagnostics machinery needs the following features:

a. Make the printing of the caret line more customizable. For the C/C++ FE it will be moved to the diagnostic_finalizer, whereas for Fortran it will go in the diagnostic_starter, so it can be printed before the actual text.
b. A way to customize the caret symbol so Fortran can print '1' instead of '^'.
c. Pass down offsets relative to current location. This is anyway necessary for printing more precise diagnostics for format strings, so it is a matter to add an offset field to the diagnostic_info structure.
d. A way to print two locations in the caret line.

And that is all as far as I can see.

If a Fortran developer volunteers to tackle the Fortran bits, I will be happy to implement the common diagnostics bits. From the above a) and b) are trivial. c) is also trivial but requires writing a bit more of code. d) is a bit more convoluted but it should work fine.

The Fortran transition can be incremental, that is, if Fortran disables colors and -fdiagnostics-show-option by default, then the converted diagnostics will be indistinguishable from the unconverted ones (except that -Wno-*, -Werror= and the #pragmas will only work for the converted ones).
Comment 6 Manuel López-Ibáñez 2014-04-16 20:26:18 UTC
*** Bug 53552 has been marked as a duplicate of this bug. ***
Comment 7 Manuel López-Ibáñez 2014-04-16 20:27:46 UTC
*** Bug 58189 has been marked as a duplicate of this bug. ***
Comment 8 Manuel López-Ibáñez 2014-04-21 15:19:26 UTC
Created attachment 32650 [details]
proof of concept #2

Updated proof of concept. With this new version the output is:

/home/manuel/test1/test-gfc-warning.f03:11:0:

   arr = (/ INTEGER(KIND=4) :: HUGE(0_8) /) ! { dg-warning "conversion from" }
 1
Warning: Possible change of value in conversion from INTEGER(8) to INTEGER(4) at (1) [-Wconversion]

(plus colors)

So the only remaining major issue is the offset.

It is not clear to me why Fortran needs an explicit offset, don't you track locations when parsing using line-map.c ? So before implementing it I would like to understand whether it is actually needed.

Also, is there any case where gcf_linebuf.file->filename != LOCATION_FILE(gcf_linebuf.location) ?
Comment 9 Manuel López-Ibáñez 2014-04-30 23:01:00 UTC
Fortran devs, is there any interest in this approach?
Comment 10 Tobias Burnus 2014-05-03 08:27:03 UTC
(In reply to Manuel López-Ibáñez from comment #8)
> /home/manuel/test1/test-gfc-warning.f03:11:0:
>    arr = (/ INTEGER(KIND=4) :: HUGE(0_8) /) ! { dg-warning "conversion from"
> }
>  1
> Warning: Possible change of value in conversion from INTEGER(8) to
> INTEGER(4) at (1) [-Wconversion]

Looks good to me at a glance. However, I have not yet applied the patch and played around with it.

Thanks for working on this!


> Also, is there any case where gcf_linebuf.file->filename !=
> LOCATION_FILE(gcf_linebuf.location) ?

Seemingly not. I tried to use:
a) include "some_file"
b) #include "some_file"
and the latter using both "-cpp" and using the pre-processed output as input. And it always worked.


Also looking at the code in scanner.c, it seems as if it is always set to the correct value:

get_file (const char *name, enum lc_reason reason ATTRIBUTE_UNUSED)
...
  f->filename = xstrdup (name);
...
  linemap_add (line_table, reason, false, f->filename, 1);

Thus, on terms of the linebuffer, there should be no reason of having "filename" at all. It seems to get used in scanner.c itself - where some of the diagnostic by-passes the default diagnostic. Either by constructing the file/line numbers manually or even by calling "fprintf(stderr" directly.

[One probably should do some clean up there as well… But having the 'proper' diagnostic for the rest would be a start.]


> So the only remaining major issue is the offset. It is not clear to me why
> Fortran needs an explicit offset, don't you track locations when parsing
> using line-map.c

Seemingly, we don't. The offset within a line is calculated using:
  c1 = l1->nextc - l1->lb->line;
and in "next_char" one simply uses:
  c = *gfc_current_locus.nextc++;

For the line map, we just use:
     b->location
        = linemap_line_start (line_table, current_file->line++, 120);
which gives the line but not the offset.


One might handle this in a more clever way, but can't you use in gfc_warning2, gfortran's normal "locus" and use linemap_position_for_column() to map from the offset to the column?



Another thing I wonder how to handle best is the case of having two locations in the same line, e.g.
  integer, allocatable :: v(:)
  allocate (v(3), v(4))
  end
that currently prints:
  foo.f90:foo.f90:2.10-16:
  allocate (v(3), v(4))
            1     2
  Error: Allocate-object at (1) also appears at (2)

or with line break (note the "&"):
  allocate (v(3), &
            v(4))
as
  foo.f90:foo.f90:2.10:
  allocate (v(3), &
            1
  foo.f90:foo.f90:3.10:
          v(4))
          2
  Error: Allocate-object at (1) also appears at (2)
Comment 11 Manuel López-Ibáñez 2014-05-03 09:47:18 UTC
(In reply to Tobias Burnus from comment #10)
> Looks good to me at a glance. However, I have not yet applied the patch and
> played around with it.
> 
> Thanks for working on this!

Thanks for looking at it. If you have a suggestion for a warning that doesn't use %L, I could produce a simpler but more complete proof-of-concept.

> > Also, is there any case where gcf_linebuf.file->filename !=
> > LOCATION_FILE(gcf_linebuf.location) ?
> 
> Seemingly not. I tried to use:

It would simplify the work on this PR to remove it and use LOCATION_FILE() in gfortran.

> > So the only remaining major issue is the offset. It is not clear to me why
> > Fortran needs an explicit offset, don't you track locations when parsing
> > using line-map.c
> 
> Seemingly, we don't. The offset within a line is calculated using:
>   c1 = l1->nextc - l1->lb->line;
> and in "next_char" one simply uses:
>   c = *gfc_current_locus.nextc++;
> 
> For the line map, we just use:
>      b->location
>         = linemap_line_start (line_table, current_file->line++, 120);
> which gives the line but not the offset.
> 
> 
> One might handle this in a more clever way, but can't you use in
> gfc_warning2, gfortran's normal "locus" and use
> linemap_position_for_column() to map from the offset to the column?

You cannot insert new locations out of order in a line-map. Perhaps one could create a dummy line-map, but it would be easier if the diagnostics machinery handled arbitrary offsets, so I would favor that. Arbitrary offsets are useful also to other FEs for some special cases anyway.

Of course, the two things are not incompatible: 1) gfortran could use the full linemaps for tracking column numbers, thus removing another duplication of code  and 2) for particular cases, the diagnostic machinery could handle explicit offsets passed by gfortran.

 
> Another thing I wonder how to handle best is the case of having two
> locations in the same line, e.g.
>   integer, allocatable :: v(:)
>   allocate (v(3), v(4))
>   end
> that currently prints:
>   foo.f90:foo.f90:2.10-16:
>   allocate (v(3), v(4))
>             1     2
>   Error: Allocate-object at (1) also appears at (2)
> 
> or with line break (note the "&"):
>   allocate (v(3), &
>             v(4))
> as
>   foo.f90:foo.f90:2.10:
>   allocate (v(3), &
>             1
>   foo.f90:foo.f90:3.10:
>           v(4))
>           2
>   Error: Allocate-object at (1) also appears at (2)

To implement this, the diagnostic machinery should be able to handle two locations first. Then diagnostic_show_locus should handle two locations as well. The particular format used by gfortran will be achieved by playing with the prefix in gcf_diagnostic_starter. The major difficulty is in implementing the one with the line break. A possible solution would be to make diagnostic_build_prefix a hook that can be overriden by the FE and call it from diagnostic_show_locus for each extra line shown. It doesn't seem a lot of work in any case, so I think this is not a show-stopper. But I'd rather start with the simplest cases (for example, those warnings that don't use any explicit %L).

However, I don't want to spend a lot of effort on this if there is no interest in the Fortran side. I'm happy to give guidance, to implement things in the common diagnostic machinery and to implement proof-of-concept patches for the Fortran side, but someone else needs to go over the list of Fortran warnings and update them, build and test one by one. As I said, the work can be done incrementally, but I don't have the time to do it all and I'd rather not start if no one on the Fortran side plans to continue it.
Comment 12 Manuel López-Ibáñez 2014-05-03 10:03:24 UTC
> > One might handle this in a more clever way, but can't you use in
> > gfc_warning2, gfortran's normal "locus" and use
> > linemap_position_for_column() to map from the offset to the column?
> 
> You cannot insert new locations out of order in a line-map. Perhaps one
> could create a dummy line-map, but it would be easier if the diagnostics
> machinery handled arbitrary offsets, so I would favor that. Arbitrary
> offsets are useful also to other FEs for some special cases anyway.
> 
> Of course, the two things are not incompatible: 1) gfortran could use the
> full linemaps for tracking column numbers, thus removing another duplication
> of code  and 2) for particular cases, the diagnostic machinery could handle
> explicit offsets passed by gfortran.

Or in other words: This PR can be fixed without gfortran tracking column-numbers using line-maps (just using an explicit offset), but you'll need that for fixing PR 53934.
Comment 13 Manuel López-Ibáñez 2014-08-15 15:10:48 UTC
Author: manu
Date: Fri Aug 15 15:10:15 2014
New Revision: 214024

URL: https://gcc.gnu.org/viewcvs?rev=214024&root=gcc&view=rev
Log:
2014-08-15  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
gcc/
	* diagnostic.c (build_message_string): Make it extern.
	* diagnostic.h (build_message_string): Make it extern.
c-family/
	* c-format.c: Handle Fortran flags.
fortran/
	* gfortran.h: Define GCC_DIAG_STYLE.
	(gfc_diagnostics_init,gfc_warning_cmdline): Declare.
	* trans-array.c: Include gfortran.h before diagnostic-core.h.
	* trans-expr.c: Likewise.
	* trans-openmp.c: Likewise.
	* trans-const.c: Likewise.
	* trans.c: Likewise.
	* trans-types.c: Likewise.
	* f95-lang.c: Likewise.
	* trans-decl.c: Likewise.
	* trans-io.c: Likewise.
	* trans-intrinsic.c: Likewise.
	* error.c: Include diagnostic.h and diagnostic-color.h.
	(gfc_diagnostic_build_prefix): New.
	(gfc_diagnostic_starter): New.
	(gfc_diagnostic_finalizer): New.
	(gfc_warning_cmdline): New.
	(gfc_diagnostics_init): New.
	* gfc-diagnostic.def: New.
	* options.c (gfc_init_options): Call gfc_diagnostics_init.
	(gfc_post_options): Use gfc_warning_cmdline.

Added:
    trunk/gcc/fortran/gfc-diagnostic.def
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-format.c
    trunk/gcc/diagnostic.c
    trunk/gcc/diagnostic.h
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-openmp.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans.c
Comment 14 Manuel López-Ibáñez 2014-08-20 23:08:01 UTC
Author: manu
Date: Wed Aug 20 23:07:29 2014
New Revision: 214245

URL: https://gcc.gnu.org/viewcvs?rev=214245&root=gcc&view=rev
Log:
gcc/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* diagnostic.c (default_diagnostic_finalizer): Move caret printing
	 to here ...
	(diagnostic_report_diagnostic): ... from here.
	* toplev.c (general_init): Move code to c-family.

gcc/cp/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (cp_diagnostic_finalizer): Delete.
	(init_error): Do not set diagnostic_finalizer here.

gcc/c-family/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* c-opts.c: Include tree-diagnostics.h.
	(c_diagnostic_finalizer): New.
	(c_common_initialize_diagnostics): Use it.

gcc/fortran/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (gfc_diagnostic_finalizer): Call default finalizer.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-opts.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/error.c
    trunk/gcc/diagnostic.c
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
    trunk/gcc/toplev.c
Comment 15 Manuel López-Ibáñez 2014-08-21 00:27:57 UTC
Author: manu
Date: Thu Aug 21 00:27:25 2014
New Revision: 214251

URL: https://gcc.gnu.org/viewcvs?rev=214251&root=gcc&view=rev
Log:
gcc/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* diagnostic.c: Set default caret.
	(diagnostic_show_locus): Use it. Tell pretty-printer that a new
	line is needed.
	* diagnostic.h (struct diagnostic_context):


gcc/fortran/ChangeLog:

2014-08-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (gfc_diagnostic_build_locus_prefix): New function.
	(gfc_diagnostic_starter): Follow Fortran FE diagnostics.
	(gfc_diagnostic_finalizer): Do not call default finalizer.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/diagnostic.c
    trunk/gcc/diagnostic.h
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
Comment 16 Manuel López-Ibáñez 2014-10-07 16:13:54 UTC
Author: manu
Date: Tue Oct  7 16:13:22 2014
New Revision: 215974

URL: https://gcc.gnu.org/viewcvs?rev=215974&root=gcc&view=rev
Log:
gcc/fortran/ChangeLog:

2014-10-06  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	PR fortran/54687
	* gfortran.h (gfc_warning_cmdline): Add overload that takes an
	option.
	(gfc_error_cmdline): Declare.
	* error.c (gfc_warning_cmdline): New overload that takes an option.
	(gfc_error_cmdline): New.
	* lang.opt (Wmissing-include-dirs): New.
	* scanner.c (add_path_to_list): Use the new functions.
	(load_file): Likewise.
	* options.c (gfc_init_options): Wmissing-include-dirs is enabled
	by default in Fortran.
	(gfc_handle_option): Accept automatically handled options.



Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/scanner.c
Comment 17 Manuel López-Ibáñez 2014-10-28 21:56:56 UTC
Author: manu
Date: Tue Oct 28 21:56:24 2014
New Revision: 216812

URL: https://gcc.gnu.org/viewcvs?rev=216812&root=gcc&view=rev
Log:
2014-10-28  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* gfortran.h (gfc_warning_cmdline): Rename as gfc_warning_now_2.
	(gfc_error_cmdline): Rename as gfc_error_now_2.
	* error.c (gfc_diagnostic_build_locus_prefix): Remove trailing space.
	(gfc_diagnostic_starter): Add space between locus and prefix.
	(gfc_warning_now_2): Renamed from gfc_warning_cmdline.
	(gfc_error_now_2): Renamed from gfc_error_cmdline.
	* scanner.c (add_path_to_list): Use gfc_warning_now_2.
	(load_line): Likewise.
	(load_file): Likewise.
	* options.c (gfc_post_options): Update all renamed functions.



Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/scanner.c
Comment 18 Manuel López-Ibáñez 2014-11-11 22:51:20 UTC
Author: manu
Date: Tue Nov 11 22:50:48 2014
New Revision: 217383

URL: https://gcc.gnu.org/viewcvs?rev=217383&root=gcc&view=rev
Log:
libcpp/ChangeLog:

2014-11-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* include/line-map.h (linemap_position_for_loc_and_offset):
	Declare.
	* line-map.c (linemap_position_for_loc_and_offset): New.


gcc/fortran/ChangeLog:

2014-11-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* gfortran.h (warn_use_without_only): Remove.
	(gfc_diagnostics_finish): Declare.
	* error.c: Include tree-diagnostics.h
	(gfc_format_decoder): New.
	(gfc_diagnostics_init): Use gfc_format_decoder. Set default caret
	char.
	(gfc_diagnostics_finish): Restore tree diagnostics defaults, but
	keep gfc_diagnostics_starter and finalizer. Restore default caret.
	* options.c: Remove all uses of warn_use_without_only.
	* lang.opt (Wuse-without-only): Add Var.
	* f95-lang.c (gfc_be_parse_file): Call gfc_diagnostics_finish.
	* module.c (gfc_use_module): Use gfc_warning_now_2.
	* parse.c (decode_statement): Likewise.
	(decode_gcc_attribute): Likewise.
	(next_free): Likewise.
	(next_fixed): Likewise.


gcc/testsuite/ChangeLog:

2014-11-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* lib/gfortran-dg.exp: Update regexp to match locus and message
	without caret.
	* gfortran.dg/use_without_only_1.f90: Add column numbers.
        * gfortran.dg/warnings_are_errors_1.f: Update.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/use_without_only_1.f90
    trunk/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f
    trunk/gcc/testsuite/lib/gfortran-dg.exp
    trunk/libcpp/ChangeLog
    trunk/libcpp/include/line-map.h
    trunk/libcpp/line-map.c
Comment 19 Manuel López-Ibáñez 2014-11-23 23:48:15 UTC
Author: manu
Date: Sun Nov 23 23:47:42 2014
New Revision: 217992

URL: https://gcc.gnu.org/viewcvs?rev=217992&root=gcc&view=rev
Log:
gcc/fortran/ChangeLog:

2014-11-23  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* decl.c (gfc_verify_c_interop_param): Use gfc_error_now_2.
	(gfc_set_constant_character_len): Use gfc_warning_now_2.
	* resolve.c (resolve_ordinary_assign): Likewise.
	* gfortran.h (warn_character_truncation): Do not declare here.
	* error.c (gfc_format_decoder): Handle %L.
	* lang.opt (Wcharacter-truncation): Add Var and LangEnabledBy.
	* options.c (gfc_init_options): Do not handle
	warn_character_truncation explicitly.
	(set_Wall): Likewise.
	(gfc_handle_option): Likewise.



Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/resolve.c
Comment 20 Manuel López-Ibáñez 2014-12-03 17:50:38 UTC
Author: manu
Date: Wed Dec  3 17:50:06 2014
New Revision: 218326

URL: https://gcc.gnu.org/viewcvs?rev=218326&root=gcc&view=rev
Log:
gcc/testsuite/ChangeLog:

2014-12-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* gfortran.dg/warnings_are_errors_1.f90: Update warnings to errors.
	* gfortran.dg/warnings_are_errors_1.f: Likewise.

gcc/fortran/ChangeLog:

2014-12-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* gfortran.h (gfc_warning): Now returns bool. Add overload that
	accepts opt.
	(gfc_warning_1): Declare.
	* error.c
	(pp_warning_buffer,warningcount_buffered,werrorcount_buffered):	New.
	(gfc_buffer_error): Set pp_warning_buffer.flush_p.
	(gfc_clear_pp_buffer): New.
	(gfc_warning_1): Renamed from gfc_warning.
	(gfc_warning): Add three new overloads. One that takes just a
	format string and ellipsis, another that takes also a warning
	option, and another that takes also va_list instead of ellipsis.
	(gfc_clear_warning): Clear pp_warning_buffer.
	(gfc_warning_check): Flush pp_warning_buffer and update warning
	and werror counters.
	(gfc_diagnostics_init): Init pp_warning_buffer.

	* Update all gfc_warning calls that do not multiple
	locations to use %qs and OPT_W*, otherwise use gfc_warning_1.

gcc/ChangeLog:

2014-12-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* pretty-print.c (output_buffer::output_buffer): Init flush_p to true.
	(pp_flush): Flush only if flush_p.
	(pp_really_flush): New.
	* pretty-print.h (struct output_buffer): Add flush_p.
	(pp_really_flush): Declare.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/dependency.c
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/io.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/scanner.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-common.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/pretty-print.c
    trunk/gcc/pretty-print.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f
    trunk/gcc/testsuite/gfortran.dg/warnings_are_errors_1.f90
Comment 21 Manuel López-Ibáñez 2014-12-11 15:14:05 UTC
Author: manu
Date: Thu Dec 11 15:13:33 2014
New Revision: 218627

URL: https://gcc.gnu.org/viewcvs?rev=218627&root=gcc&view=rev
Log:
gcc/ChangeLog:

2014-12-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* diagnostic.c (diagnostic_action_after_output): Make it extern.
	Take diagnostic_t argument instead of diagnostic_info. Count also
	DK_WERROR towards max_errors.
	(diagnostic_report_diagnostic): Update call according to the above.
	(error_recursion): Likewise.
	* diagnostic.h (diagnostic_action_after_output): Declare.
	* pretty-print.c (pp_formatted_text_data): Delete.
	(pp_append_r): Call output_buffer_append_r.
	(pp_formatted_text): Call output_buffer_formatted_text.
	(pp_last_position_in_text): Call output_buffer_last_position_in_text.
	* pretty-print.h (output_buffer_formatted_text): New.
	(output_buffer_append_r): New.
	(output_buffer_last_position_in_text): New.

gcc/testsuite/ChangeLog:

2014-12-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

        * gfortran.dg/do_iterator.f90: Remove bogus dg-warning.

gcc/fortran/ChangeLog:

2014-12-11  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (pp_error_buffer): New static variable.
	(pp_warning_buffer): Make it a pointer.
	(gfc_output_buffer_empty_p): New.
	(gfc_error_init_1): Call gfc_buffer_error.
	(gfc_buffer_error): Do not use pp_warning_buffer.flush_p as the
	buffered_p flag.
	(gfc_clear_warning): Likewise.
	(gfc_warning_check): Call gfc_clear_warning. Only check the new
	pp_warning_buffer if the old warning_buffer was empty. Call
	diagnostic_action_after_output.
	(gfc_error_1): Renamed from gfc_error.
	(gfc_error): New.
	(gfc_clear_error): Clear also pp_error_buffer.
	(gfc_error_flag_test): Check also pp_error_buffer.
	(gfc_error_check): Likewise. Only check the new pp_error_buffer
	if the old error_buffer was empty.
	(gfc_move_output_buffer_from_to): New.
	(gfc_push_error): Use it here. Take also an output_buffer as argument.
	(gfc_pop_error): Likewise.
	(gfc_free_error): Likewise.
	(gfc_diagnostics_init): Use XNEW and placement-new to init
	pp_error_buffer and pp_warning_buffer. Set flush_p to false for
	both pp_warning_buffer and pp_error_buffer.

	* Update gfc_push_error, gfc_pop_error and gfc_free_error calls
	according to the above changes.
	* Use gfc_error_1 for all gfc_error calls that use multiple
	locations.
	* Use %qs instead of '%s' for many gfc_error calls.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/diagnostic.c
    trunk/gcc/diagnostic.h
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/openmp.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/scanner.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-common.c
    trunk/gcc/pretty-print.c
    trunk/gcc/pretty-print.h
    trunk/gcc/testsuite/ChangeLog
Comment 22 Manuel López-Ibáñez 2014-12-11 15:38:07 UTC
I think the two remaining issues are:

1) Multiple locations (%C/%L) in diagnostics

2) Support !GCC$ diagnostic (pragmas)

For (2), I'm not planning to work on it since it seems all the common support is there, Fortran just needs to parse and handle the pragmas in the same way as the C/C++ FEs do. There may be some opportunity for code sharing (perhaps the pragmas are language specific and they should not be), but I haven't looked at the details.

For (1), my plan is to add location_t location[2] to text_info and make diagnostic_context directly use those. The common part in diagnostic.c will need some refactoring to print two caret chars in the same line and to customize which caret char and which location is printed so that Fortran can print the second location on a different line with a different caret char when desired. The most tricky part is how to handle the prefix/locus_prefix difference when there is zero, one or two caret lines printed, in gfc_diagnostic_starter(). Handling two locations in gfc_format_decoder is trivial if one considers that the only way to set text->location[0] in Fortran is via gfc_format_decoder itself:

--- gcc/fortran/error.c (revision 218628)
+++ gcc/fortran/error.c (working copy)
@@ -1056,25 +1056,26 @@ gfc_format_decoder (pretty_printer *pp,
   switch (*spec)
     {
     case 'C':
     case 'L':
       {
-       static const char *result = "(1)";
+       static const char *result[2] = { "(1)", "(2)" };
        locus *loc;
        if (*spec == 'C')
          loc = &gfc_current_locus;
        else
          loc = va_arg (*text->args_ptr, locus *);
        gcc_assert (loc->nextc - loc->lb->line >= 0);
        unsigned int offset = loc->nextc - loc->lb->line;
-       gcc_assert (text->locus);
-       *text->locus
+       /* If location[0] != UNKNOWN_LOCATION means that we already
+          processed one of %C/%L.  */
+       int loc_num = text->location[0] == UNKNOWN_LOCATION ? 0 : 1;
+       text->location[loc_num]
          = linemap_position_for_loc_and_offset (line_table,
                                                 loc->lb->location,
                                                 offset);
-       global_dc->caret_char = '1';
-       pp_string (pp, result);
+       pp_string (pp, result[loc_num]);
        return true;
       }
     default:
       return false;
     }
Comment 23 Tobias Burnus 2014-12-11 16:30:57 UTC
(In reply to Manuel López-Ibáñez from comment #22)
> 2) Support !GCC$ diagnostic (pragmas)

That's now PR64273.
Comment 24 Manuel López-Ibáñez 2015-05-16 12:30:36 UTC
Author: manu
Date: Sat May 16 12:30:04 2015
New Revision: 223236

URL: https://gcc.gnu.org/viewcvs?rev=223236&root=gcc&view=rev
Log:
gcc/fortran/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054

	Replace all calls to gfc_notify_std_1 with gfc_notify_std and
	gfc_warning_1 with gfc_warning.
	* decl.c (gfc_verify_c_interop_param): Here.
	* resolve.c (resolve_branch): Here.
	(resolve_fl_derived): Here.
	* dependency.c (gfc_check_argument_var_dependency):
	* scanner.c (preprocessor_line): Use gfc_warning_now_at. Fix line
	counter and locations before and after warning.
	* gfortran.h (gfc_warning_1, gfc_warning_now_1, gfc_notify_std_1):
	Delete.
	(gfc_warning_now_at): Declare.
	* error.c (gfc_warning_1): Delete.
	(gfc_notify_std_1): Delete.
	(gfc_warning_now_1): Delete.
	(gfc_format_decoder): Handle two locations.
	(gfc_diagnostic_build_prefix): Rename as
	gfc_diagnostic_build_kind_prefix.
	(gfc_diagnostic_build_locus_prefix): Take an expanded_location
	instead of diagnostic_info.
	(gfc_diagnostic_build_locus_prefix): Add overload that takes two
	expanded_location.
	(gfc_diagnostic_starter): Handle two locations.
	(gfc_warning_now_at): New.
	(gfc_diagnostics_init): Initialize caret_chars array.
	(gfc_diagnostics_finish): Reset caret_chars array to default.

gcc/cp/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (cp_diagnostic_starter): Use diagnostic_location
	function.
	(cp_print_error_function): Likewise.
	(cp_printer): Replace locus pointer with accessor function.

gcc/c/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* c-objc-common.c (c_tree_printer): Replace locus pointer with
	accessor function.

gcc/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* tree-pretty-print.c (percent_K_format): Replace locus pointer
	with accessor function.
	* tree-diagnostic.c (diagnostic_report_current_function): Use
	diagnostic_location function.
	(maybe_unwind_expanded_macro_loc): Likewise.
	(virt_loc_aware_diagnostic_finalizer): Likewise.
	(default_tree_printer): Replace locus pointer with accessor function.
	* diagnostic.c (diagnostic_initialize): Initialize caret_chars array.
	(diagnostic_set_info_translated): Initialize second location.
	(diagnostic_build_prefix): Use CARET_LINE_MARGIN.
	(diagnostic_show_locus): Handle two locations. Call
	diagnostic_print_caret_line.
	(diagnostic_print_caret_line): New.
	(default_diagnostic_starter): Use diagnostic_location function.
	(diagnostic_report_diagnostic): Use diagnostic_location function.
	(verbatim): Do not set text.locus.
	* diagnostic.h (struct diagnostic_info): Remove location field.
	(struct diagnostic_context): Make caret_chars an array of two.
	(diagnostic_location): New inline.
	(diagnostic_expand_location): Handle two locations.
	(diagnostic_same_line): New inline.
	(diagnostic_print_caret_line): Declare.
	(CARET_LINE_MARGIN): New constant.
	* pretty-print.c (pp_printf): Do not set text.locus.
	(pp_verbatim): Do not set text.locus.
	* pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): New constant.
	(struct text_info): Replace locus pointer with locations
	array. Add accessor functions.

gcc/testsuite/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* lib/gfortran-dg.exp: Update regex to handle two locations for
	the same diagnostic without caret.
	* gfortran.dg/badline.f: Test also that line numbers are correct
	before and after "left but not entered" warning.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/testsuite/ChangeLog
Comment 25 Manuel López-Ibáñez 2015-05-16 12:31:32 UTC
Author: manu
Date: Sat May 16 12:31:00 2015
New Revision: 223237

URL: https://gcc.gnu.org/viewcvs?rev=223237&root=gcc&view=rev
Log:
gcc/fortran/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054

	Replace all calls to gfc_notify_std_1 with gfc_notify_std and
	gfc_warning_1 with gfc_warning.
	* decl.c (gfc_verify_c_interop_param): Here.
	* resolve.c (resolve_branch): Here.
	(resolve_fl_derived): Here.
	* dependency.c (gfc_check_argument_var_dependency):
	* scanner.c (preprocessor_line): Use gfc_warning_now_at. Fix line
	counter and locations before and after warning.
	* gfortran.h (gfc_warning_1, gfc_warning_now_1, gfc_notify_std_1):
	Delete.
	(gfc_warning_now_at): Declare.
	* error.c (gfc_warning_1): Delete.
	(gfc_notify_std_1): Delete.
	(gfc_warning_now_1): Delete.
	(gfc_format_decoder): Handle two locations.
	(gfc_diagnostic_build_prefix): Rename as
	gfc_diagnostic_build_kind_prefix.
	(gfc_diagnostic_build_locus_prefix): Take an expanded_location
	instead of diagnostic_info.
	(gfc_diagnostic_build_locus_prefix): Add overload that takes two
	expanded_location.
	(gfc_diagnostic_starter): Handle two locations.
	(gfc_warning_now_at): New.
	(gfc_diagnostics_init): Initialize caret_chars array.
	(gfc_diagnostics_finish): Reset caret_chars array to default.

gcc/cp/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* error.c (cp_diagnostic_starter): Use diagnostic_location
	function.
	(cp_print_error_function): Likewise.
	(cp_printer): Replace locus pointer with accessor function.

gcc/c/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* c-objc-common.c (c_tree_printer): Replace locus pointer with
	accessor function.

gcc/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* tree-pretty-print.c (percent_K_format): Replace locus pointer
	with accessor function.
	* tree-diagnostic.c (diagnostic_report_current_function): Use
	diagnostic_location function.
	(maybe_unwind_expanded_macro_loc): Likewise.
	(virt_loc_aware_diagnostic_finalizer): Likewise.
	(default_tree_printer): Replace locus pointer with accessor function.
	* diagnostic.c (diagnostic_initialize): Initialize caret_chars array.
	(diagnostic_set_info_translated): Initialize second location.
	(diagnostic_build_prefix): Use CARET_LINE_MARGIN.
	(diagnostic_show_locus): Handle two locations. Call
	diagnostic_print_caret_line.
	(diagnostic_print_caret_line): New.
	(default_diagnostic_starter): Use diagnostic_location function.
	(diagnostic_report_diagnostic): Use diagnostic_location function.
	(verbatim): Do not set text.locus.
	* diagnostic.h (struct diagnostic_info): Remove location field.
	(struct diagnostic_context): Make caret_chars an array of two.
	(diagnostic_location): New inline.
	(diagnostic_expand_location): Handle two locations.
	(diagnostic_same_line): New inline.
	(diagnostic_print_caret_line): Declare.
	(CARET_LINE_MARGIN): New constant.
	* pretty-print.c (pp_printf): Do not set text.locus.
	(pp_verbatim): Do not set text.locus.
	* pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): New constant.
	(struct text_info): Replace locus pointer with locations
	array. Add accessor functions.

gcc/testsuite/ChangeLog:

2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* lib/gfortran-dg.exp: Update regex to handle two locations for
	the same diagnostic without caret.
	* gfortran.dg/badline.f: Test also that line numbers are correct
	before and after "left but not entered" warning.



Modified:
    trunk/gcc/c/c-objc-common.c
    trunk/gcc/cp/error.c
    trunk/gcc/diagnostic.c
    trunk/gcc/diagnostic.h
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/dependency.c
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/scanner.c
    trunk/gcc/pretty-print.c
    trunk/gcc/pretty-print.h
    trunk/gcc/testsuite/gfortran.dg/badline.f
    trunk/gcc/testsuite/lib/gfortran-dg.exp
    trunk/gcc/tree-diagnostic.c
    trunk/gcc/tree-pretty-print.c
Comment 26 Manuel López-Ibáñez 2015-05-23 23:03:23 UTC
Author: manu
Date: Sat May 23 23:02:52 2015
New Revision: 223614

URL: https://gcc.gnu.org/viewcvs?rev=223614&root=gcc&view=rev
Log:
gcc/fortran/ChangeLog:

2015-05-24  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR fortran/44054
	* gfortran.h (struct gfc_error_buf): Rename as
	gfc_error_buffer. Move closer to push, pop and free
	methods. Reimplement using an output_buffer.
	* error.c (errors, warnings, warning_buffer, cur_error_buffer):
	Delete everywhere in this file.
	(error_char): Delete all contents.
	(gfc_increment_error_count): Delete.
	(gfc_error_now): Update comment. Set error_buffer.flag.
	(gfc_warning_check): Do not handle warning_buffer.
	(gfc_error_1): Delete.
	(gfc_error_now_1): Delete.
	(gfc_error_check): Simplify.
	(gfc_move_error_buffer_from_to): Renamed from
	gfc_move_output_buffer_from_to.
	(gfc_push_error): Handle only gfc_error_buffer.
	(gfc_pop_error): Likewise.
	(gfc_free_error): Likewise.
	(gfc_get_errors): Remove warnings and errors.
	(gfc_diagnostics_init): Use static error_buffer.
	(gfc_error_1,gfc_error_now_1): Delete declarations.
	* symbol.c, decl.c, trans-common.c, data.c, expr.c, expr.c,
	frontend-passes.c, resolve.c, match.c, parse.c: Replace
	gfc_error_1 with gfc_error and gfc_error_now_1 with gfc_error_1
	everywhere.
	* f95-lang.c (gfc_be_parse_file): Do not update errorcount and
	warningcount here.
	* primary.c (match_complex_constant): Replace gfc_error_buf and
	output_buffer with gfc_error_buffer.



Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/error.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/trans-common.c
Comment 27 Manuel López-Ibáñez 2015-05-24 10:02:03 UTC
From my POV, this is FIXED.

The only thing missing is the diagnostic pragmas: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas

I'm not sure how pragmas work in the Fortran FE, but it should be a matter of following more or less what the C/C++ FE do to interface with diagnostic.c. 

I'm not going to work on that. I leave to the Fortran maintainers whether to track that on a different PR and close this one or leave this one open.
Comment 28 Dominique d'Humieres 2015-11-11 10:43:07 UTC
From comment 27:

> From my POV, this is FIXED.

>
> The only thing missing is the diagnostic pragmas:
> https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas

>
> I'm not sure how pragmas work in the Fortran FE, but it should be a matter
> of following more or less what the C/C++ FE do to interface with diagnostic.c. 

>
> I'm not going to work on that. I leave to the Fortran maintainers whether
> to track that on a different PR and close this one or leave this one open.

I have filed pr68289, closing as FIXED.