The attach patch fixes an ICE that occurs when a user uses a derived type as an actual argument to subprogram. Regression tested on x86_64-*-freebsd and i586-*-freebsd. OK to commit?
2018-06-10 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/68544 * resolve.c (is_dt_name): New function to compare symbol name against list of derived types. (resolve_actual_arglist): Use it to find wrong code. 2018-06-10 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/68544 * gfortran.dg/pr68544.f90: New test. * gfortran.dg/pr85687.f90: Modify test for new error message. -- Steve
Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 261376) +++ gcc/fortran/resolve.c (working copy) @@ -1862,7 +1862,19 @@ resolve_procedure_expression (gfc_expr* expr) return true; } +/* Check that name is not a derived type. */ +static bool +is_dt_name (const char *name) +{ + gfc_dt_list *dt_list; + + for (dt_list = gfc_derived_types; dt_list; dt_list = dt_list->next) + if (strcmp(dt_list->derived->name, name) == 0) + return true; + return false; +} + /* Resolve an actual argument list. Most of the time, this is just resolving the expressions in the list. The exception is that we sometimes have to decide whether arguments @@ -1963,6 +1975,14 @@ resolve_actual_arglist (gfc_actual_arglist *arg, proce gfc_error ("ELEMENTAL non-INTRINSIC procedure %qs is not " "allowed as an actual argument at %L", sym->name, &e->where); + } + + /* Check to see if the argument is actually a derived type. */ + if (is_dt_name (sym->name)) + { + gfc_error ("Derived type %qs is used as an actual " + "argument at %L", sym->name, &e->where); + goto cleanup; } /* Check if a generic interface has a specific procedure Index: gcc/testsuite/gfortran.dg/pr68544.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr68544.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr68544.f90 (working copy) @@ -0,0 +1,13 @@ +! { dg-do compile } +! PF fortran/68544 +program p + real x + type t + end type + x = f(t) ! { dg-error "used as an actual argument" } +end +subroutine b + type t + end type + print *, shape(t) ! { dg-error "used as an actual argument" } +end Index: gcc/testsuite/gfortran.dg/pr85687.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr85687.f90 (revision 261376) +++ gcc/testsuite/gfortran.dg/pr85687.f90 (working copy) @@ -1,8 +1,9 @@ ! { dg-do compile } ! PR fortran/85687 ! Code original contributed by Gerhard Steinmetz gscfq at t-oline dot de +! Originally, error message superceded by fix for PR fortran/68544. program p type t end type - print *, rank(t) ! { dg-error "must be a data object" } + print *, rank(t) ! { dg-error "used as an actual argument" } end