I encountered an ICE when the fortran FE tries to parse an OpenACC routine directive when the containing function has a syntax error. E.g.
integer function f1 is missing an argument list, so the fortran FE will not create a function symbol for f1. Consequently, the OpenACC routine parser cannot register the routine directive with any function, so it hit a gcc_unreachable. This patch replaces that gcc_unreachable with a match_error. While the syntax of the routine directive may be correct, it is still an error to have a dangling acc routine directive not associated with a function. I've applied this patch to gomp-4_0-branch. Cesar
2017-04-27 Cesar Philippidis <ce...@codesourcery.com> gcc/fortran/ * openmp.c (gfc_match_oacc_routine): Don't match OpenACC routines when the current function failed to parse due to a syntax error. gcc/testsuite/ * gfortran.dg/goacc/routine-10.f90: New test. diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 0aecda4..72c6669 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -2576,7 +2576,9 @@ gfc_match_oacc_routine (void) goto cleanup; } else - gcc_unreachable (); + /* Something has gone wrong. Perhaps there was a syntax error + in the program-stmt. */ + goto cleanup; if (n) n->clauses = c; diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-10.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-10.f90 new file mode 100644 index 0000000..4d8b5ba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/routine-10.f90 @@ -0,0 +1,8 @@ +! Ensure that GFortran doesn't ICE with incomplete function +! definitions. + +! { dg-do compile } + +integer function f1 ! { dg-error "Expected formal argument list in function definition" } + !$acc routine ! { dg-error "Unclassifiable OpenACC directive" } +end function f1 ! { dg-error "Expecting END PROGRAM statement" }