The following patch fixes an ICE due to a gcc_assert() firing. As everyone here knows, gfortran runs a series a matchers during parsing. If a matcher fails, it often queuesi/reports an error message and returns, which allows other matchers to run. If a match is successful, a queued error message(s) is discarded. If no match is found, one (or typically many) error is emitted.
In the case at hand, an error is reported to the user. However, running additional matchers runs into a situation that causes an ICE due to the gcc_assert(). Fortunately, a recent change to gfc_internal_error() checks to see if gfortran has already reports error(s). If yes, then gfc_internal_error() gracefully exits. If no, she panics. Regression tested on x86_64-*-freebsd. Ok to commit? 2016-09-09 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/77429 * dependency.c (gfc_check_dependency): Convert gcc_assert() to a conditional and possible call to gfc_internal_error(). 2016-09-09 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/77429 * gfortran.dg/pr77429.f90: New test. Index: gcc/fortran/dependency.c =================================================================== --- gcc/fortran/dependency.c (revision 240051) +++ gcc/fortran/dependency.c (working copy) @@ -1258,7 +1258,8 @@ gfc_check_dependency (gfc_expr *expr1, g && strcmp (expr1->value.function.name, "_F.caf_get") == 0) return 0; - gcc_assert (expr1->expr_type == EXPR_VARIABLE); + if (expr1->expr_type != EXPR_VARIABLE) + gfc_internal_error ("gfc_check_dependency: expecting an EXPR_VARIABLE"); switch (expr2->expr_type) { Index: gcc/testsuite/gfortran.dg/pr77429.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr77429.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr77429.f90 (working copy) @@ -0,0 +1,7 @@ +! { dg-do compile } +program p + shape(1) = 0 ! { dg-error "expression in variable definition context" } + shape(1,2) = 0 ! { dg-error "expression in variable definition context" } + shape(1,2,3) = 0 ! { dg-error "Too many arguments in call" } + lbound([1]) = 0 ! { dg-error "expression in variable definition context" } +end -- Steve