[Bug fortran/23308] named common block confused as procedure - runtime segfault
-- pinskia at gcc dot gnu dot org changed: What|Removed |Added Target Milestone|--- |4.1.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #12 from pault at gcc dot gnu dot org 2006-01-27 22:16 --- Subject: Bug 23308 Author: pault Date: Fri Jan 27 22:16:04 2006 New Revision: 110310 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=110310 Log: 2005-01-28 Paul Thomas [EMAIL PROTECTED] PR fortran/25964 * resolve.c (resolve_function): Exclude statement functions from global reference checking. PR fortran/25084 PR fortran/20852 PR fortran/25085 PR fortran/25086 * resolve.c (resolve_function): Declare a gfc_symbol to replace the references through the symtree to the symbol associated with the function expresion. Give error on reference to an assumed character length function is defined in an interface or an external function that is not a dummy argument. (resolve_symbol): Give error if an assumed character length function is array-valued, pointer-valued, pure or recursive. Emit warning that character(*) value functions are obsolescent in F95. PR fortran/25416 * trans-expr.c (gfc_conv_function_call): The above patch to resolve.c prevents any assumed character length function call from getting here except intrinsics such as SPREAD. In this case, ensure that no segfault occurs from referencing non-existent charlen-length- expr_type and provide a backend_decl for the charlen from the charlen of the first actual argument. Cure temp name confusion. * trans-expr.c (gfc_get_interface_mapping_array): Change name of temporary from parm to ifm to avoid clash with temp coming from trans-array.c. PR fortran/25124 PR fortran/25625 * decl.c (get_proc_name): If there is an existing symbol in the encompassing namespace, call errors if it is a procedure of the same name or the kind field is set, indicating a type declaration. PR fortran/20881 PR fortran/23308 PR fortran/25538 PR fortran/25710 * decl.c (add_global_entry): New function to check for existing global symbol with this name and to create new one if none exists. (gfc_match_entry): Call add_global_entry before matching argument lists for subroutine and function entries. * gfortran.h: Prototype for existing function, global_used. * resolve.c (resolve_global_procedure): New function to check global symbols for procedures. (resolve_call, resolve_function): Calls to this new function for non-contained and non-module procedures. * match.c (match_common): Add check for existing global symbol, creat one if none exists and emit error if there is a clash. * parse.c (global_used): Remove static and use the gsymbol name rather than the new_block name, so that the function can be called from resolve.c. (parse_block_data, parse_module, add_global_procedure): Improve checks for existing gsymbols. Emit error if already defined or if references were to another type. Set defined flag. PR fortran/24276 * trans-expr.c (gfc_conv_aliased_arg): New function called by gfc_conv_function_call that coverts an expression for an aliased component reference to a derived type array into a temporary array of the same type as the component. The temporary is passed as an actual argument for the procedure call and is copied back to the derived type after the call. (is_aliased_array): New function that detects an array reference that is followed by a component reference. (gfc_conv_function_call): Detect an aliased actual argument with is_aliased_array and convert it to a temporary and back again using gfc_conv_aliased_arg. PR fortran/25124 PR fortran/25625 * gfortran.dg/internal_references_1.f90: New test. PR fortran/25901 * gfortran.dg/internal references_2.f90: New test. PR fortran/20881 PR fortran/23308 PR fortran/25538 PR fortran/25710 * gfortran.dg/global_references_1.f90: New test. * gfortran.dg/g77/19990905-1.f: Restore the error that there is a clash between the common block name and the name of a subroutine reference. PR fortran/25964 * gfortran.dg/global_references_2.f90: New test. PR fortran/24276 * gfortran.dg/aliasing_dummy_1.f90: New test. PR fortran/25084 PR fortran/20852 PR fortran/25085 PR fortran/25086 * gfortran.dg/assumed_charlen_function_1.f90: New test. * gfortran.dg/assumed_charlen_function_3.f90: New test. PR fortran/25416 * gfortran.dg/assumed_charlen_function_2.f90: New test. PR fortran/25964 *
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #13 from pault at gcc dot gnu dot org 2006-01-27 22:30 --- Fixed on trunk and 4.1 Paul -- pault at gcc dot gnu dot org changed: What|Removed |Added Status|NEW |RESOLVED Resolution||FIXED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #11 from pault at gcc dot gnu dot org 2006-01-21 09:09 --- Subject: Bug 23308 Author: pault Date: Sat Jan 21 09:08:54 2006 New Revision: 110063 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=110063 Log: 2005-01-21 Paul Thomas [EMAIL PROTECTED] PR fortran/25124 PR fortran/25625 * decl.c (get_proc_name): If there is an existing symbol in the encompassing namespace, call errors if it is a procedure of the same name or the kind field is set, indicating a type declaration. PR fortran/20881 PR fortran/23308 PR fortran/25538 PR fortran/25710 * decl.c (add_global_entry): New function to check for existing global symbol with this name and to create new one if none exists. (gfc_match_entry): Call add_global_entry before matching argument lists for subroutine and function entries. * gfortran.h: Prototype for existing function, global_used. * resolve.c (resolve_global_procedure): New function to check global symbols for procedures. (resolve_call, resolve_function): Calls to this new function for non-contained and non-module procedures. * match.c (match_common): Add check for existing global symbol, creat one if none exists and emit error if there is a clash. * parse.c (global_used): Remove static and use the gsymbol name rather than the new_block name, so that the function can be called from resolve.c. (parse_block_data, parse_module, add_global_procedure): Improve checks for existing gsymbols. Emit error if already defined or if references were to another type. Set defined flag. PR fortran/PR24276 * trans-expr.c (gfc_conv_aliased_arg): New function called by gfc_conv_function_call that coverts an expression for an aliased component reference to a derived type array into a temporary array of the same type as the component. The temporary is passed as an actual argument for the procedure call and is copied back to the derived type after the call. (is_aliased_array): New function that detects an array reference that is followed by a component reference. (gfc_conv_function_call): Detect an aliased actual argument with is_aliased_array and convert it to a temporary and back again using gfc_conv_aliased_arg. 2005-01-21 Paul Thomas [EMAIL PROTECTED] PR fortran/25124 PR fortran/25625 * gfortran.dg/internal_references_1.f90: New test. PR fortran/20881 PR fortran/23308 PR fortran/25538 PR fortran/25710 * gfortran.dg/global_references_1.f90: New test. * gfortran.dg/g77/19990905-1.f: Restore the error that there is a clash between the common block name and the name of a subroutine reference. PR fortran/PR24276 * gfortran.dg/aliasing_dummy_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/aliasing_dummy_1.f90 trunk/gcc/testsuite/gfortran.dg/global_references_1.f90 trunk/gcc/testsuite/gfortran.dg/internal_references_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/decl.c trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/match.c trunk/gcc/fortran/parse.c trunk/gcc/fortran/resolve.c trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/g77/19990905-1.f -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #9 from paulthomas2 at wanadoo dot fr 2006-01-08 09:49 --- Subject: Re: named common block confused as procedure - runtime segfault pinskia at gcc dot gnu dot org wrote: --- Comment #8 from pinskia at gcc dot gnu dot org 2006-01-08 06:13 --- (In reply to comment #7) In fact, it regtests OK, apart from the above. I want to say that PR 20881 is the same issue too. Thanks Andrew, I know that one of Joost's PRs were associated with this issue. I will sit down tonight with the standard and will work out who can or cannot reference whom; I came across entry_1.f90 i the testsuite that has a program name thet is the same as one of the procedures. I believe that it is kosher but I want to be really sure. Equally PR23308 and g77/19990905-1.f need to have their legality sorted out. Apart from that, the patch is ready. Maybe I should do argument type checking too? Paul -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #10 from pinskia at gcc dot gnu dot org 2006-01-08 15:15 --- (In reply to comment #5) Andrew, Lahey's code checking utility gives Lahey's Fortran 95 code checker that is online gives: 2604-S: SOURCE.F90, line 3: The name 'foo' cannot be specified as both external procedure name and common block name. The previous appearance is in 'line 4'. 2521-S: SOURCE.F90, line 4: Intrinsic procedure name or external procedure name same as common block name 'foo'. So maybe this should only be an error in Fortran 95 mode. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #3 from pault at gcc dot gnu dot org 2006-01-07 17:07 --- (In reply to comment #2) Note I think fixing PR 25710 and the mentioned problem of not keeping symbols correctly will fix this bug. I have been trying to fix this but it is hard. I notice that there is a handle in gfortran.h to deal with this: /* Global symbols are symbols of global scope. Currently we only use this to detect collisions already when parsing. TODO: Extend to verify procedure calls. */ typedef struct gfc_gsymbol { BBT_HEADER(gfc_gsymbol); const char *name; enum { GSYM_UNKNOWN=1, GSYM_PROGRAM, GSYM_FUNCTION, GSYM_SUBROUTINE, GSYM_MODULE, GSYM_COMMON, GSYM_BLOCK_DATA } type; int defined, used; locus where; } gfc_gsymbol; extern gfc_gsymbol *gfc_gsym_root; and in symbol.c /* Search a tree for the global symbol. */ gfc_gsymbol * gfc_find_gsymbol (gfc_gsymbol *symbol, const char *name) { friends Astonishingly, none of this is ever used! The experimental patch below picks up pr25710 but not this one. COMMON blocks need to be given a gsymbol, methinks. Paul Index: gcc/fortran/resolve.c === *** gcc/fortran/resolve.c (revision 109449) --- gcc/fortran/resolve.c (working copy) *** resolve_function (gfc_expr * expr) *** 1157,1162 --- 1157,1172 try t; int temp; + gfc_gsymbol * gsym; + + gsym = gfc_find_gsymbol (gfc_gsym_root, expr-symtree-n.sym-name); + + if ((gsym gsym-type != GSYM_UNKNOWN gsym-type != GSYM_FUNCTION) +|| + (expr-symtree !expr-symtree-n.sym-attr.external !expr-symtree-n.sym-attr.subroutine)) + gfc_warning_now (CALL at %L to procedure %s which is not a function, +expr-where, expr-symtree-n.sym-name); + /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; *** resolve_call (gfc_code * c) *** 1510,1515 --- 1520,1535 { try t; + gfc_gsymbol * gsym; + + gsym = gfc_find_gsymbol (gfc_gsym_root, c-symtree-n.sym-name); + + if ((gsym gsym-type != GSYM_UNKNOWN gsym-type != GSYM_SUBROUTINE) +|| + (c-symtree !c-symtree-n.sym-attr.external !c-symtree-n.sym-attr.subroutine)) + gfc_warning_now (CALL at %L to procedure %s which is not a subroutine, +c-loc, c-symtree-n.sym-name); + /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #4 from pinskia at gcc dot gnu dot org 2006-01-07 19:27 --- (In reply to comment #3) Index: gcc/fortran/resolve.c === *** gcc/fortran/resolve.c (revision 109449) --- gcc/fortran/resolve.c (working copy) *** resolve_function (gfc_expr * expr) *** 1157,1162 --- 1157,1172 try t; int temp; The only question I have with this patch is the following still passes (this is the main reason why I filed PR 25710 because I could not get the testcase in there and this testcase working): function f() REAL :: f f = 1.0 end function call f contains SUBROUTINE f end SUBROUTINE end -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #5 from kargl at gcc dot gnu dot org 2006-01-07 20:19 --- Andrew, Lahey's code checking utility gives Compiling program unit f at line 1: Compiling program unit test at line 5: Encountered 0 errors, 0 warnings, 0 informations in file SOURCE.F90. Compiling file SOURCE.F90. NAG's compiler also compiles the code without an error or warning. -- kargl at gcc dot gnu dot org changed: What|Removed |Added CC||kargl at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #6 from paulthomas2 at wanadoo dot fr 2006-01-07 21:44 --- Subject: Re: named common block confused as procedure - runtime segfault Steve and Andrew, --- Comment #5 from kargl at gcc dot gnu dot org 2006-01-07 20:19 --- Andrew, Lahey's code checking utility gives Compiling program unit f at line 1: Compiling program unit test at line 5: Encountered 0 errors, 0 warnings, 0 informations in file SOURCE.F90. Compiling file SOURCE.F90. NAG's compiler also compiles the code without an error or warning. The enclosed patch catches Andrew's PR but also snags on g77/19990905-1.f (The Burley test case). I will sit down with the standard and sort out what is and is not required of global symbols, contained symbols and scopes in general. If nothing else, the enclosed will catch some nasties that are escaping at the moment. Best regards Paul Index: gcc/fortran/resolve.c === *** gcc/fortran/resolve.c (revision 109449) --- gcc/fortran/resolve.c (working copy) *** resolve_function (gfc_expr * expr) *** 1157,1162 --- 1157,1172 try t; int temp; + gfc_gsymbol * gsym; + + gsym = NULL; + if (expr-symtree expr-symtree-n.sym) + gsym = gfc_find_gsymbol (gfc_gsym_root, expr-symtree-n.sym-name); + + if ((gsym gsym-type != GSYM_UNKNOWN gsym-type != GSYM_FUNCTION)) + gfc_warning_now (reference at %L to %s which is not a function, +expr-where, expr-symtree-n.sym-name); + /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; *** resolve_call (gfc_code * c) *** 1510,1515 --- 1520,1535 { try t; + gfc_gsymbol * gsym; + + gsym = NULL; + if (c-symtree c-symtree-n.sym) + gsym = gfc_find_gsymbol (gfc_gsym_root, c-symtree-n.sym-name); + + if ((gsym gsym-type != GSYM_UNKNOWN gsym-type != GSYM_SUBROUTINE)) + gfc_warning_now (CALL at %L to %s which is not a subroutine, +c-loc, c-symtree-n.sym-name); + /* Switch off assumed size checking and do this again for certain kinds of procedure, once the procedure itself is resolved. */ need_full_assumed_size++; Index: gcc/fortran/match.c === *** gcc/fortran/match.c (revision 109448) --- gcc/fortran/match.c (working copy) *** gfc_match_common (void) *** 2247,2252 --- 2247,2253 gfc_array_spec *as; gfc_equiv * e1, * e2; match m; + gfc_gsymbol *gsym; old_blank_common = gfc_current_ns-blank_common.head; if (old_blank_common) *** gfc_match_common (void) *** 2263,2268 --- 2264,2278 if (m == MATCH_ERROR) goto cleanup; + gsym = gfc_get_gsymbol (name); + if (gsym-type != GSYM_UNKNOWN gsym-type != GSYM_COMMON) + { + gfc_error (Symbol '%s' at %C is already an external symbol that is not COMMON, +sym-name); + goto cleanup; + } + gsym-type = GSYM_COMMON; + if (name[0] == '\0') { t = gfc_current_ns-blank_common; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #7 from paulthomas2 at wanadoo dot fr 2006-01-07 21:46 --- Subject: Re: named common block confused as procedure - runtime segfault The enclosed patch catches Andrew's PR but also snags on g77/19990905-1.f (The Burley test case). In fact, it regtests OK, apart from the above. Paul -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #8 from pinskia at gcc dot gnu dot org 2006-01-08 06:13 --- (In reply to comment #7) In fact, it regtests OK, apart from the above. I want to say that PR 20881 is the same issue too. -- pinskia at gcc dot gnu dot org changed: What|Removed |Added OtherBugsDependingO||20881 nThis|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Comment #2 from pinskia at gcc dot gnu dot org 2006-01-07 05:31 --- Note I think fixing PR 25710 and the mentioned problem of not keeping symbols correctly will fix this bug. I have been trying to fix this but it is hard. Also note we have the same problem with call to functions. Also I have been thinking ICC is not a good compiler to test with for diagnostic issues. Actually this is only horrible Fortran 95 according to Lahey's fortran compiler. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308
[Bug fortran/23308] named common block confused as procedure - runtime segfault
--- Additional Comments From pinskia at gcc dot gnu dot org 2005-08-10 11:50 --- Confirmed, ICC also does not warn or error out. -- What|Removed |Added Status|UNCONFIRMED |NEW Ever Confirmed||1 Last reconfirmed|-00-00 00:00:00 |2005-08-10 11:50:15 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23308