diff options
Diffstat (limited to 'gcc/fortran/error.c')
-rw-r--r-- | gcc/fortran/error.c | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index 49ede5a71f..0312499f32 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -1,5 +1,5 @@ /* Handle errors. - Copyright (C) 2000-2016 Free Software Foundation, Inc. + Copyright (C) 2000-2017 Free Software Foundation, Inc. Contributed by Andy Vaught & Niels Kristian Bech Jensen This file is part of GCC. @@ -67,7 +67,7 @@ gfc_push_suppress_errors (void) } static void -gfc_error (const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(1,0); +gfc_error_opt (int opt, const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(2,0); static bool gfc_warning (int opt, const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(2,0); @@ -307,7 +307,7 @@ show_locus (locus *loc, int c1, int c2) error_string (f->filename); error_char (':'); - + error_integer (LOCATION_LINE (lb->location)); if ((c1 > 0) || (c2 > 0)) @@ -357,7 +357,7 @@ show_locus (locus *loc, int c1, int c2) offset = cmax - terminal_width + 5; /* Show the line itself, taking care not to print more than what can - show up on the terminal. Tabs are converted to spaces, and + show up on the terminal. Tabs are converted to spaces, and nonprintable characters are converted to a "\xNN" sequence. */ p = &(lb->line[offset]); @@ -375,7 +375,7 @@ show_locus (locus *loc, int c1, int c2) error_char ('\n'); /* Show the '1' and/or '2' corresponding to the column of the error - locus. Note that a value of -1 for c1 or c2 will simply cause + locus. Note that a value of -1 for c1 or c2 will simply cause the relevant number not to be printed. */ c1 -= offset; @@ -440,7 +440,7 @@ show_loci (locus *l1, locus *l2) else m = c1 - c2; - /* Note that the margin value of 10 here needs to be less than the + /* Note that the margin value of 10 here needs to be less than the margin of 5 used in the calculation of offset in show_locus. */ if (l1->lb != l2->lb || m > terminal_width - 10) @@ -467,11 +467,11 @@ show_loci (locus *l1, locus *l2) If a locus pointer is given, the actual source line is printed out and the column is indicated. Since we want the error message at the bottom of any source file information, we must scan the - argument list twice -- once to determine whether the loci are + argument list twice -- once to determine whether the loci are present and record this for printing, and once to print the error message after and loci have been printed. A maximum of two locus arguments are permitted. - + This function is also called (recursively) by show_locus in the case of included files; however, as show_locus does not resupply any loci, the recursion is at most one level deep. */ @@ -687,11 +687,11 @@ error_print (const char *type, const char *format0, va_list argp) /* This is a position specifier. See comment above. */ while (ISDIGIT (*format)) format++; - + /* Skip over the dollar sign. */ format++; } - + switch (*format) { case '%': @@ -804,10 +804,10 @@ gfc_warning (int opt, const char *gmsgid, va_list ap) ++werrorcount; else if (diagnostic.kind == DK_ERROR) ++werrorcount_buffered; - else + else ++werrorcount, --warningcount, ++warningcount_buffered; } - + va_end (argp); return ret; } @@ -902,7 +902,7 @@ gfc_notify_std (int std, const char *gmsgid, ...) if (warning) gfc_warning (0, buffer, argp); else - gfc_error (buffer, argp); + gfc_error_opt (0, buffer, argp); va_end (argp); return (warning && !warnings_are_errors) ? true : false; @@ -916,10 +916,8 @@ gfc_notify_std (int std, const char *gmsgid, ...) %L Takes locus argument */ static bool -gfc_format_decoder (pretty_printer *pp, - text_info *text, const char *spec, - int precision ATTRIBUTE_UNUSED, bool wide ATTRIBUTE_UNUSED, - bool plus ATTRIBUTE_UNUSED, bool hash ATTRIBUTE_UNUSED) +gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec, + int precision, bool wide, bool set_locus, bool hash) { switch (*spec) { @@ -946,7 +944,11 @@ gfc_format_decoder (pretty_printer *pp, return true; } default: - return false; + /* Fall through info the middle-end decoder, as e.g. stor-layout.c + etc. diagnostics can use the FE printer while the FE is still + active. */ + return default_tree_printer (pp, text, spec, precision, wide, + set_locus, hash); } } @@ -1030,17 +1032,17 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context, With -fdiagnostic-show-caret (the default) it prints: [locus of primary range]: - + some code 1 Error: Some error at (1) - + With -fno-diagnostic-show-caret or if the primary range is not valid, it prints: [locus of primary range]: Error: Some error at (1) and (2) */ -static void +static void gfc_diagnostic_starter (diagnostic_context *context, diagnostic_info *diagnostic) { @@ -1051,7 +1053,7 @@ gfc_diagnostic_starter (diagnostic_context *context, bool one_locus = diagnostic->richloc->get_num_locations () < 2; bool same_locus = false; - if (!one_locus) + if (!one_locus) { s2 = diagnostic_expand_location (diagnostic, 1); same_locus = diagnostic_same_line (context, s1, s2); @@ -1089,11 +1091,11 @@ gfc_diagnostic_starter (diagnostic_context *context, } else { - pp_verbatim (context->printer, locus_prefix); + pp_verbatim (context->printer, "%s", locus_prefix); free (locus_prefix); /* Fortran uses an empty line between locus and caret line. */ pp_newline (context->printer); - diagnostic_show_locus (context, diagnostic); + diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind); /* If the caret line was shown, the prefix does not contain the locus. */ pp_set_prefix (context->printer, kind_prefix); @@ -1106,7 +1108,7 @@ gfc_diagnostic_start_span (diagnostic_context *context, { char *locus_prefix; locus_prefix = gfc_diagnostic_build_locus_prefix (context, exploc); - pp_verbatim (context->printer, locus_prefix); + pp_verbatim (context->printer, "%s", locus_prefix); free (locus_prefix); pp_newline (context->printer); /* Fortran uses an empty line between locus and caret line. */ @@ -1160,6 +1162,24 @@ gfc_warning_now (int opt, const char *gmsgid, ...) return ret; } +/* Internal warning, do not buffer. */ + +bool +gfc_warning_internal (int opt, const char *gmsgid, ...) +{ + va_list argp; + diagnostic_info diagnostic; + rich_location rich_loc (line_table, UNKNOWN_LOCATION); + bool ret; + + va_start (argp, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, + DK_WARNING); + diagnostic.option_index = opt; + ret = report_diagnostic (&diagnostic); + va_end (argp); + return ret; +} /* Immediate error (i.e. do not buffer). */ @@ -1223,9 +1243,10 @@ gfc_warning_check (void) werrorcount += werrorcount_buffered; gcc_assert (warningcount_buffered + werrorcount_buffered == 1); pp->buffer = tmp_buffer; - diagnostic_action_after_output (global_dc, - warningcount_buffered + diagnostic_action_after_output (global_dc, + warningcount_buffered ? DK_WARNING : DK_ERROR); + diagnostic_check_max_errors (global_dc, true); } } @@ -1233,7 +1254,7 @@ gfc_warning_check (void) /* Issue an error. */ static void -gfc_error (const char *gmsgid, va_list ap) +gfc_error_opt (int opt, const char *gmsgid, va_list ap) { va_list argp; va_copy (argp, ap); @@ -1241,7 +1262,7 @@ gfc_error (const char *gmsgid, va_list ap) if (warnings_not_errors) { - gfc_warning (/*opt=*/0, gmsgid, argp); + gfc_warning (opt, gmsgid, argp); va_end (argp); return; } @@ -1289,11 +1310,21 @@ gfc_error (const char *gmsgid, va_list ap) void +gfc_error_opt (int opt, const char *gmsgid, ...) +{ + va_list argp; + va_start (argp, gmsgid); + gfc_error_opt (opt, gmsgid, argp); + va_end (argp); +} + + +void gfc_error (const char *gmsgid, ...) { va_list argp; va_start (argp, gmsgid); - gfc_error (gmsgid, argp); + gfc_error_opt (0, gmsgid, argp); va_end (argp); } @@ -1337,7 +1368,7 @@ gfc_clear_error (void) bool gfc_error_flag_test (void) { - return error_buffer.flag + return error_buffer.flag || !gfc_output_buffer_empty_p (pp_error_buffer); } @@ -1360,6 +1391,7 @@ gfc_error_check (void) gcc_assert (gfc_output_buffer_empty_p (pp_error_buffer)); pp->buffer = tmp_buffer; diagnostic_action_after_output (global_dc, DK_ERROR); + diagnostic_check_max_errors (global_dc, true); return true; } |