Created attachment 36839 [details] Minimal test case The attached code causes an internal compiler error with the latest source from git master (commit 9c822ac) and 5.2.0. It attempts to pass the implicit constructor for a derived type as an argument to a subroutine. I don't know if this is valid code. I haven't found anything in the standards which suggest either way yet. Sun's F90 compiler rejects it, but gives a useful error message. gfortran -v: Using built-in specs. COLLECT_GCC=/home/jimmacarthur/gcc-5.2.0/gccinstall/bin/gfortran COLLECT_LTO_WRAPPER=/home/jimmacarthur/gcc-5.2.0/gccinstall/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-5.2.0/configure --with-languages=fortran --prefix=/home/jimmacarthur/gcc-5.2.0/gccinstall --disable-bootstrap Thread model: posix gcc version 5.2.0 (GCC) Compiler command line: ~/gcc-5.2.0/gccinstall/bin/gfortran -Wall -Wextra pass-type-constructor-as-function.f output: pass-type-constructor-as-function.f:1:23: SUBROUTINE sub (f) 1 Warning: Unused dummy argument ‘f’ at (1) [-Wunused-dummy-argument] pass-type-constructor-as-function.f:7:0: TYPE t 1 internal compiler error: Segmentation fault 0xa20cdf crash_signal ../../gcc-5.2.0/gcc/toplev.c:383 0x67b990 gfc_sym_identifier ../../gcc-5.2.0/gcc/fortran/trans-decl.c:347 0x67c38a build_function_decl ../../gcc-5.2.0/gcc/fortran/trans-decl.c:2057 0x682fa5 gfc_get_symbol_decl(gfc_symbol*) ../../gcc-5.2.0/gcc/fortran/trans-decl.c:1487 0x693537 gfc_conv_variable ../../gcc-5.2.0/gcc/fortran/trans-expr.c:2312 0x690c8a gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc-5.2.0/gcc/fortran/trans-expr.c:7219 0x696048 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc-5.2.0/gcc/fortran/trans-expr.c:7319 0x68d3ff gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*, gfc_expr*, vec<tree_node*, va_gc, vl_embed>*) ../../gcc-5.2.0/gcc/fortran/trans-expr.c:4831 0x6be024 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool) ../../gcc-5.2.0/gcc/fortran/trans-stmt.c:419 0x66539c trans_code ../../gcc-5.2.0/gcc/fortran/trans.c:1743 0x685e54 gfc_generate_function_code(gfc_namespace*) ../../gcc-5.2.0/gcc/fortran/trans-decl.c:5841 0x622648 translate_all_program_units ../../gcc-5.2.0/gcc/fortran/parse.c:5340 0x622648 gfc_parse_file() ../../gcc-5.2.0/gcc/fortran/parse.c:5537 0x6613e5 gfc_be_parse_file ../../gcc-5.2.0/gcc/fortran/f95-lang.c:229
Confirmed from 4.8 up to trunk (6.0). > Sun's F90 compiler rejects it, but gives a useful error message. What is the message?
Sun f90 output: CALL sub(t) ^ "pass-type-constructor-as-function.f", Line = 10, Column = 16: ERROR: This use of derived type "T" is not valid.
Update : $ cat z1.f90 program p type t end type call f(t) end $ gfortran-7-20161120 z1.f90 z1.f90:2:0: type t internal compiler error: Segmentation fault 0xc4265f crash_signal ../../gcc/toplev.c:333 0x74c990 gfc_sym_identifier ../../gcc/fortran/trans-decl.c:339 0x74e2e3 build_function_decl ../../gcc/fortran/trans-decl.c:2197 0x75806a gfc_get_symbol_decl(gfc_symbol*) ../../gcc/fortran/trans-decl.c:1622 0x77005f gfc_conv_variable ../../gcc/fortran/trans-expr.c:2494 0x76bcf2 gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7704 0x773aa6 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7804 0x767220 gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*, gfc_expr*, vec<tree_node*, va_gc, vl_embed>*) ../../gcc/fortran/trans-expr.c:5169 0x7b0fe4 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool) ../../gcc/fortran/trans-stmt.c:407 0x72c59a trans_code ../../gcc/fortran/trans.c:1774 0x75c578 gfc_generate_function_code(gfc_namespace*) ../../gcc/fortran/trans-decl.c:6261 0x6e53e0 translate_all_program_units ../../gcc/fortran/parse.c:6038 0x6e53e0 gfc_parse_file() ../../gcc/fortran/parse.c:6238 0x729052 gfc_be_parse_file ../../gcc/fortran/f95-lang.c:202
Invalid code with a function : $ cat z2.f90 program p type t end type print *, f(t) end $ gfortran-7-20161120 z2.f90 z2.f90:2:0: type t internal compiler error: Segmentation fault 0xc4265f crash_signal ../../gcc/toplev.c:333 0x74c990 gfc_sym_identifier ../../gcc/fortran/trans-decl.c:339 0x74e2e3 build_function_decl ../../gcc/fortran/trans-decl.c:2197 0x75806a gfc_get_symbol_decl(gfc_symbol*) ../../gcc/fortran/trans-decl.c:1622 0x77005f gfc_conv_variable ../../gcc/fortran/trans-expr.c:2494 0x76bcf2 gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7704 0x773aa6 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7804 0x767220 gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*, gfc_expr*, vec<tree_node*, va_gc, vl_embed>*) ../../gcc/fortran/trans-expr.c:5169 0x76bcd2 gfc_conv_expr(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7696 0x7737d8 gfc_conv_expr_reference(gfc_se*, gfc_expr*) ../../gcc/fortran/trans-expr.c:7831 0x79a586 gfc_trans_transfer(gfc_code*) ../../gcc/fortran/trans-io.c:2482 0x72c237 trans_code ../../gcc/fortran/trans.c:1902 0x7972e0 build_dt ../../gcc/fortran/trans-io.c:1980 0x72c257 trans_code ../../gcc/fortran/trans.c:1874 0x75c578 gfc_generate_function_code(gfc_namespace*) ../../gcc/fortran/trans-decl.c:6261 0x6e53e0 translate_all_program_units ../../gcc/fortran/parse.c:6038 0x6e53e0 gfc_parse_file() ../../gcc/fortran/parse.c:6238 0x729052 gfc_be_parse_file ../../gcc/fortran/f95-lang.c:202
Affects several intrinsic functions/subroutines ... $ cat z7.f90 program p type t end type print *, atomic_define(t) print *, atomic_ref(t) print *, coshape(t) print *, cpu_time(t) print *, date_and_time(t) print *, execute_command_line(t) print *, findloc(t) print *, get_command(t) print *, get_command_argument(t) print *, get_environment_variable(t) print *, is_contiguous(t) print *, move_alloc(t) print *, mvbits(t) print *, out_of_range(t) print *, random_init(t) print *, random_number(t) print *, random_seed(t) print *, rank(t) print *, reduce(t) print *, system_clock(t) end
These snippets are silently accepted (t is not an array nor a scalar). $ cat z3.f90 program p type t end type print *, shape(t) end $ gfortran-7-20161120 -Wall -fcheck=all z3.f90 $ a.out $ --- $ cat z4.f90 subroutine s(t) type t end type end $ gfortran-7-20161120 -c z4.f90 $
(In reply to Gerhard Steinmetz from comment #3) > Update : > > > $ cat z1.f90 > program p > type t > end type > call f(t) > end Adding "implicit none" triggers a misleading error message: pr68544.f90:3:8: type t 1 Error: Symbol 't' at (1) has no IMPLICIT type I think the code is invalid. Intel writes: pr68544.f90(5): error #6478: A type-name must not be used as a variable. [T] call f(t) ---------^ compilation aborted for pr68544.f90 (code 1)
(In reply to Gerhard Steinmetz from comment #3) > Update : > > > $ cat z1.f90 > program p > type t > end type > call f(t) > end > > > $ gfortran-7-20161120 z1.f90 > z1.f90:2:0: > > type t > > internal compiler error: Segmentation fault > 0xc4265f crash_signal > ../../gcc/toplev.c:333 > 0x74c990 gfc_sym_identifier > ../../gcc/fortran/trans-decl.c:339 > 0x74e2e3 build_function_decl > ../../gcc/fortran/trans-decl.c:2197 > 0x75806a gfc_get_symbol_decl(gfc_symbol*) > ../../gcc/fortran/trans-decl.c:1622 > 0x77005f gfc_conv_variable > ../../gcc/fortran/trans-expr.c:2494 > 0x76bcf2 gfc_conv_expr(gfc_se*, gfc_expr*) > ../../gcc/fortran/trans-expr.c:7704 > 0x773aa6 gfc_conv_expr_reference(gfc_se*, gfc_expr*) > ../../gcc/fortran/trans-expr.c:7804 > 0x767220 gfc_conv_procedure_call(gfc_se*, gfc_symbol*, gfc_actual_arglist*, > gfc_expr*, vec<tree_node*, va_gc, vl_embed>*) > ../../gcc/fortran/trans-expr.c:5169 > 0x7b0fe4 gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool) > ../../gcc/fortran/trans-stmt.c:407 > 0x72c59a trans_code > ../../gcc/fortran/trans.c:1774 > 0x75c578 gfc_generate_function_code(gfc_namespace*) > ../../gcc/fortran/trans-decl.c:6261 > 0x6e53e0 translate_all_program_units > ../../gcc/fortran/parse.c:6038 > 0x6e53e0 gfc_parse_file() > ../../gcc/fortran/parse.c:6238 > 0x729052 gfc_be_parse_file > ../../gcc/fortran/f95-lang.c:202 Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 266281) +++ gcc/fortran/resolve.c (working copy) @@ -1863,7 +1863,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_symbol *dt_list; + + for (dt_list = gfc_derived_types; dt_list; dt_list = dt_list->dt_next) + if (strcmp(dt_list->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 @@ -1964,6 +1976,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 266281) +++ 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
(In reply to kargl from comment #8) > Index: gcc/fortran/resolve.c > =================================================================== > --- gcc/fortran/resolve.c (revision 266281) > +++ gcc/fortran/resolve.c (working copy) > @@ -1863,7 +1863,19 @@ resolve_procedure_expression (gfc_expr* expr) Steve, what is the status of your patch?
(In reply to Harald Anlauf from comment #9) > (In reply to kargl from comment #8) > > Index: gcc/fortran/resolve.c > > =================================================================== > > --- gcc/fortran/resolve.c (revision 266281) > > +++ gcc/fortran/resolve.c (working copy) > > @@ -1863,7 +1863,19 @@ resolve_procedure_expression (gfc_expr* expr) > > Steve, > > what is the status of your patch? It no longer applies and works. Someone (pault?) removed the list of derived types (gfc_derived_types), so the patch needs to be reworked to walk the list of symbols to see if the actual argument is a derived type or not. I haven't pursued doing that
Author: kargl Date: Thu Jun 13 18:40:19 2019 New Revision: 272259 URL: https://gcc.gnu.org/viewcvs?rev=272259&root=gcc&view=rev Log: 2019-06-13 Steven G. Kargl <kargl@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. 2019-06-13 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/68544 * gfortran.dg/pr68544.f90: New test. * gfortran.dg/pr85687.f90: Modify test for new error message. Added: trunk/gcc/testsuite/gfortran.dg/pr68544.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/pr85687.f90
Fixed on trunk. Thanks for bug report. Sorry it took so long to fix.
Note that the test z4.f90 in comment 6 is still accepted.
Author: kargl Date: Thu Jun 20 23:15:32 2019 New Revision: 272529 URL: https://gcc.gnu.org/viewcvs?rev=272529&root=gcc&view=rev Log: 2019-06-20 Steven G. Kargl <kargl@gcc.gnu.org> Backport from mainline 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. 2019-06-20 Steven G. Kargl <kargl@gcc.gnu.org> Backport from mainline PR fortran/68544 * gfortran.dg/pr68544.f90: New test. * gfortran.dg/pr85687.f90: Modify test for new error message. Added: branches/gcc-9-branch/gcc/testsuite/gfortran.dg/pr68544.f90 Modified: branches/gcc-9-branch/gcc/fortran/ChangeLog branches/gcc-9-branch/gcc/fortran/resolve.c branches/gcc-9-branch/gcc/testsuite/ChangeLog branches/gcc-9-branch/gcc/testsuite/gfortran.dg/pr85687.f90
Update target milestone after backport to branch-9.