Bug 46060 - [F03] procedure pointer component referenced without argument list
Summary: [F03] procedure pointer component referenced without argument list
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2010-10-17 19:57 UTC by Stephen J. Bespalko
Modified: 2010-10-21 11:35 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-10-18 09:48:42


Attachments
module test_1.f90 which is referenced in the bug report (243 bytes, text/plain)
2010-10-17 19:57 UTC, Stephen J. Bespalko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen J. Bespalko 2010-10-17 19:57:49 UTC
Created attachment 22072 [details]
module test_1.f90 which is referenced in the bug report

Compiling the module below causes a segmentation fault.

gfortran -c test_1.f90
test_1.f90: In function ‘test_subroutine’:
test_1.f90:20:0: internal compiler error: Segmentation fault

the crash occurs in last week's 4.6 trunk and 4.5.

========

gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin10.3.0/4.5.1/lto-wrapper
Target: x86_64-apple-darwin10.3.0
Configured with: ../gcc-4_5-branch/configure --prefix=/usr/local/gfortran --enable-languages=c,c++,fortran --with-gmp=/Users/fx/devel/gcc/ibin45/../irun45 --enable-bootstrap --with-included-gettext --with-arch=nocona --with-tune=generic
Thread model: posix
gcc version 4.5.1 20100506 (prerelease) (GCC) 

=========

/volumes/dev/gfortran-4.6-trunk/bin/gfortran -v
Using built-in specs.
COLLECT_GCC=/volumes/dev/gfortran-4.6-trunk/bin/gfortran
COLLECT_LTO_WRAPPER=/Volumes/dev/gfortran-4.6-trunk/bin/../libexec/gcc/x86_64-apple-darwin10/4.6.0/lto-wrapper
Target: x86_64-apple-darwin10
Configured with: ../gfortran-4.6-src/configure --prefix=/volumes/dev/gfortran-4.6-trunk --enable-languages=fortran --host=x86_64-apple-darwin10 --build=x86_64-apple-darwin10 --target=x86_64-apple-darwin10
Thread model: posix
gcc version 4.6.0 20101013 (experimental) (GCC)
Comment 1 kargl 2010-10-18 02:17:48 UTC
The following patch allows your code to compile, but 
I have no idea if it is the correct fix.

Index: trans-expr.c
===================================================================
--- trans-expr.c        (revision 165533)
+++ trans-expr.c        (working copy)
@@ -5675,7 +5675,7 @@ gfc_trans_assignment_1 (gfc_expr * expr1
   gfc_conv_expr (&rse, expr2);
 
   /* Stabilize a string length for temporaries.  */
-  if (expr2->ts.type == BT_CHARACTER)
+  if (expr2->ts.type == BT_CHARACTER && rse.string_length)
     string_length = gfc_evaluate_now (rse.string_length, &rse.pre);
   else
     string_length = NULL_TREE;
Comment 2 Tobias Burnus 2010-10-18 06:42:42 UTC
(In reply to comment #1)
> The following patch allows your code to compile, but 
> I have no idea if it is the correct fix.

I have the feeling that it is not the best fix. The string lengths are known at the compile time - thus, rse.string_length should be defined. I wonder whether something goes wrong either in resolve_procedure_interface, or in add_hidden_procptr_result or in ...?
Comment 3 janus 2010-10-18 09:48:42 UTC
Confirmed. Here is a slightly reduced test case:

implicit none

abstract interface
  function name_func (ivar) result (res)
    integer, intent(in) :: ivar
    character(len=8) :: res
  end function name_func
end interface

type var_type
  procedure(name_func), nopass, pointer :: name
end type var_type

type(var_type) :: vars
character(len=8) name

name = vars%name   ! invalid !!!

end


This, like the original code, is invalid and gives an ICE. Changing the invalid line to something like

name = vars%name(3)

makes the ICE go away.
Comment 4 janus 2010-10-18 11:44:40 UTC
Here is another variation which causes a different ICE:


implicit none

type var_type
  procedure(integer), nopass, pointer :: ppc
end type var_type

type(var_type) :: vars
integer :: i

i = vars%ppc

end



internal compiler error: in fold_convert_loc, at fold-const.c:1899
Comment 5 janus 2010-10-18 20:48:26 UTC
Here is a preliminary patch:


Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c       (revision 165600)
+++ gcc/fortran/primary.c       (working copy)
@@ -1883,13 +1883,20 @@ gfc_match_varspec (gfc_expr *primary, int equiv_fl
       if (component->attr.proc_pointer && ppc_arg
          && !gfc_matching_procptr_assignment)
        {
+         /* Procedure pointer component call: Look for argument list.  */
          m = gfc_match_actual_arglist (sub_flag,
                                        &primary->value.compcall.actual);
          if (m == MATCH_ERROR)
            return MATCH_ERROR;
-         if (m == MATCH_YES)
-           primary->expr_type = EXPR_PPC;
 
+         if (m == MATCH_NO)
+           {
+             gfc_error ("Procedure pointer component '%s' requires an "
+                        "argument list at %C", component->name);
+             return MATCH_ERROR;
+           }
+
+         primary->expr_type = EXPR_PPC;
           break;
        }
 

It rejects the test cases in comment #0, #3 and #4 with the proper error message, but is otherwise untested.
Comment 6 janus 2010-10-21 11:31:58 UTC
Author: janus
Date: Thu Oct 21 11:31:55 2010
New Revision: 165769

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165769
Log:
2010-10-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46060
	* match.h (gfc_matching_ptr_assignment): New global variable to indicate
	we're currently matching a (non-proc-)pointer assignment.
	* decl.c (match_pointer_init): Set it.
	* match.c (gfc_match_pointer_assignment): Ditto.
	* primary.c (matching_actual_arglist): New global variable to indicate
	we're currently matching an actual argument list.
	(gfc_match_actual_arglist): Set it.
	(gfc_match_varspec): Reject procedure pointer component calls with
	missing argument list.


2010-10-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/46060
	* gfortran.dg/proc_ptr_comp_25.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_25.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2010-10-21 11:35:05 UTC
Fixed with r165769. Closing.

Thanks for the report, Stephen!