From 7a4429b268ecbbdf9a0cf949de0e01f198dac60e Mon Sep 17 00:00:00 2001 From: pault Date: Thu, 28 Jul 2016 14:47:02 +0000 Subject: [PATCH] 2016-07-28 Steven G. Kargl Thomas Koenig PR fortran/71883 * frontend-passes.c (gfc_run_passes): Bail out if there are any errors. * error.c (gfc_internal_error): If there are any errors in the buffer, exit with EXIT_FAILURE. 2016-07-28 Paul Thomas PR fortran/71883 * gfortran.dg/pr71883.f90 : New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@238822 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 13 ++++++++++-- gcc/fortran/error.c | 39 ++++++++++++++++++++--------------- gcc/fortran/frontend-passes.c | 5 +++++ gcc/testsuite/ChangeLog | 9 ++++++-- gcc/testsuite/gfortran.dg/pr71883.f90 | 38 ++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr71883.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 5baf3982c5e..85f2107e35e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2016-07-28 Steven G. Kargl + Thomas Koenig + + PR fortran/71883 + * frontend-passes.c (gfc_run_passes): Bail out if there are any + errors. + * error.c (gfc_internal_error): If there are any errors in the + buffer, exit with EXIT_FAILURE. + 2016-07-28 Renlin Li Revert @@ -19,7 +28,7 @@ 2016-07-22 Steven G. Kargl PR fortran/71935 - * check.c (is_c_interoperable): Simplify right expression. + * check.c (is_c_interoperable): Simplify right expression. 2016-07-22 Thomas Koenig @@ -75,7 +84,7 @@ PR fortran/29819 * parse.c (parse_contained): Use proper locus. - + 2016-07-14 Andre Vehreschild PR fortran/70842 diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index 6cfe019e8ae..acba1c874cc 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -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; } @@ -1030,17 +1030,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 +1051,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); @@ -1223,8 +1223,8 @@ 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); } } @@ -1303,10 +1303,15 @@ gfc_error (const char *gmsgid, ...) void gfc_internal_error (const char *gmsgid, ...) { + int e, w; va_list argp; diagnostic_info diagnostic; rich_location rich_loc (line_table, UNKNOWN_LOCATION); + gfc_get_errors (&w, &e); + if (e > 0) + exit(EXIT_FAILURE); + va_start (argp, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ICE); report_diagnostic (&diagnostic); @@ -1332,7 +1337,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); } diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index a543ab2d4c5..29e43a11138 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -125,6 +125,7 @@ gfc_run_passes (gfc_namespace *ns) doloop_level = 0; doloop_warn (ns); doloop_list.release (); + int w, e; if (flag_frontend_optimize) { @@ -136,6 +137,10 @@ gfc_run_passes (gfc_namespace *ns) expr_array.release (); } + gfc_get_errors (&w, &e); + if (e > 0) + return; + if (flag_realloc_lhs) realloc_strings (ns); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1db9f6e5634..2a15ab021fe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-07-28 Paul Thomas + + PR fortran/71883 + * gfortran.dg/pr71883.f90 : New test. + 2016-07-28 Yuri Rumyantsev PR tree-optimization/71734 @@ -43,7 +48,7 @@ 2016-07-27 Senthil Kumar Selvaraj - * gcc.dg/torture/pr69352.c: Use __INTPTR_TYPE__ instead of + * gcc.dg/torture/pr69352.c: Use __INTPTR_TYPE__ instead of including stdint.h. * gcc.dg/torture/pr71866.c: Use __UINTPTR_TYPE__ isntead of including stdint.h. @@ -378,7 +383,7 @@ 2016-07-19 Senthil Kumar Selvaraj - * gcc.dg/params/blocksort-part.c: Conditionally define Int32 + * gcc.dg/params/blocksort-part.c: Conditionally define Int32 and UInt32 based on __SIZEOF_INT__. 2016-07-19 Richard Biener diff --git a/gcc/testsuite/gfortran.dg/pr71883.f90 b/gcc/testsuite/gfortran.dg/pr71883.f90 new file mode 100644 index 00000000000..23ed6a680bd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr71883.f90 @@ -0,0 +1,38 @@ +! { dg-do compile } +! +! Test the fix for pr71883, in which an ICE would follow the error. +! +! Contributed by Gerhard Steinmetz +! +program p + character(3), allocatable :: z(:,:) + z(1:2,1:2) = 'abc' + z(2,1) = z(12) ! { dg-error "Rank mismatch in array reference" } + z(21) = z(1,2) ! { dg-error "Rank mismatch in array reference" } +contains + subroutine a + character(3), allocatable :: z(:,:) + z(1:2,1:2) = 'abc' + z(2,1) = z(-1) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(99) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(huge(0)) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(-huge(0)) ! { dg-error "Rank mismatch in array reference" } + z(-1) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(99) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(huge(0)) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(-huge(0)) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + end subroutine + + subroutine b + character(:), allocatable :: z(:,:) + z(1:2,1:2) = 'abc' + z(2,1) = z(-1) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(99) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(huge(0)) ! { dg-error "Rank mismatch in array reference" } + z(2,1) = z(-huge(0)) ! { dg-error "Rank mismatch in array reference" } + z(-1) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(99) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(huge(0)) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + z(-huge(0)) = z(2,1) ! { dg-error "Rank mismatch in array reference" } + end subroutine +end -- 2.11.4.GIT