Manuel López-Ibáñez wrote:
Oh, I didn't notice that the _now versions override the buffered messages. Where do you see that?

I think I messed up a bit - they do not seem to get cleared. I was reading gfc_error_now_1, which has:

  error_buffer.flag = 1;
  error_buffer.index = 0;
  cur_error_buffer = &error_buffer;

and I misread the "error_buffer.index = 0" as resetting the output. However, this "index = 0" is completely unused as one has unbuffered output and it only applies to the next error.

Actually, I wonder whether that can lead to printing an error message multiple times. Assume a buffered message, that's printed with gfc_error_check(), which sets flags = 0, but the buffer->message still contains the message. gfc_error_now_1 sets the flag to 1; it doesn't touch the buffer itself as it directly outputs the message. If one now calls gfc_error_check(), it outputs the previous buffer again. I wonder whether that's sometimes happens. I do recall seeing the same message multiple times without understanding why.

Thus, I withdraw the comment. And regarding error push/pop: I also missed that point.

Well, for nearly every Fortran program, at least for one line multiple
attempts have to be done by the parser. Thus, if you set a break point in
gfc_error, you will see "syntax error" messages which never make it to the
screen. As the test suite checks for excess errors, nearly every test-suite
file tests this.
Sure, but I would like to test specifically triggering and discarding
the gfc_warning that I converted (or another single one that you
suggest), if this were possible.

Hmm, theoretically, it would be possible. However, my feeling is that there is no such case. What would be needed is something which is ambiguous, the compiler assumes first the wrong kind of statement, fails, and retries is with a different kind of statement.

That's simple. However, either one has already aborted (gfc_error or NO_MATCH) *before* reaching a gfc_warning – or the code is valid and, hence, the buffered warning is printed.

Hence, sorry, I cannot deliver for gfc_warning.

For error, I'd could create one.


Some of those can probably be simply converted, others either need to
remain, or one has to setup a proper location (currently, using
gfc_warning_now would ICE), or one creates a work around and constructs
manually the error string (at least for the fprintf cases).
Why does it ICE? At worst it should give a wrong location, but the
computation of the offset is fairly similar to what Fortran already
does. Could  you give me a patch+testcase that ICEs?

Maybe it has been fixed by your latest patch, which added %L, but using
    printf '\tend' > test.f90; gfortran -Wtabs test.f90
used to ICE for me. However, it no longer ICEs. Thus, the following patch could be committed:

--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1391 +1391 @@ gfc_gobble_whitespace (void)
-             gfc_warning_now_1 ("Nonconforming tab character at %C");
+ gfc_warning_now (OPT_Wtabs, "Nonconforming tab character at %C");


I also confirm that the "!$OMP" warning now works correctly.


However, the change

-         gfc_warning_now_1 ("Line truncated at %L", &gfc_current_locus);
+         gfc_warning_now ("Line truncated at %L", &gfc_current_locus);

still triggers an ICE with "gfortran -Wall test.f90" and with "test.f" (two locations in scanner.c; see attached test cases and attache patch). The backtrace for test.f90 is:

Aborted
0xb6c38f crash_signal
        ../../gcc/toplev.c:359
0x1244620 linemap_position_for_loc_and_offset(line_maps*, unsigned int, unsigned int)
        ../../libcpp/line-map.c:648
0x63247a gfc_format_decoder
        ../../gcc/fortran/error.c:991
0x1231e8c pp_format(pretty_printer*, text_info*)
        ../../gcc/pretty-print.c:616
0x122f6ec diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../gcc/diagnostic.c:820
0x63380b gfc_warning_now(char const*, ...)
        ../../gcc/fortran/error.c:1133
0x69aca9 gfc_next_char_literal(gfc_instring)
        ../../gcc/fortran/scanner.c:1059


Besides those, there is additionally:
  gfc_warning_now_1 ("%s:%d: Illegal preprocessor directive",
which I haven't tested.

Tobias
print *, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
end 
      print *, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 884fe70..5b42777 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -777,6 +777,6 @@ skip_free_comments (void)
 			  else
-			    gfc_warning_now_1 ("!$OMP at %C starts a commented "
-					       "line as it neither is followed "
-					       "by a space nor is a "
-					       "continuation line");
+			    gfc_warning_now ("!$OMP at %C starts a commented "
+					     "line as it neither is followed "
+					     "by a space nor is a "
+					     "continuation line");
 			}
@@ -1058,3 +1058,3 @@ restart:
 	  gfc_current_locus.nextc =  gfc_current_locus.lb->line + maxlen;
-	  gfc_warning_now_1 ("Line truncated at %L", &gfc_current_locus);
+	  gfc_warning_now ("Line truncated at %L", &gfc_current_locus);
 	  gfc_current_locus.nextc = current_nextc;
@@ -1196,3 +1196,3 @@ restart:
 	  gfc_current_locus.lb->truncated = 0;
-	  gfc_warning_now_1 ("Line truncated at %L", &gfc_current_locus);
+	  gfc_warning_now ("Line truncated at %L", &gfc_current_locus);
 	}
@@ -1390,3 +1390,3 @@ gfc_gobble_whitespace (void)
 	      linenum = cur_linenum;
-	      gfc_warning_now_1 ("Nonconforming tab character at %C");
+	      gfc_warning_now (OPT_Wtabs, "Nonconforming tab character at %C");
 	    }

Reply via email to