Bug 52158

Summary: Regression on character function with gfortran 4.7
Product: gcc Reporter: Damian Rouson <damian>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: burnus, damian
Priority: P3    
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: Patch for 52158 and 45170#19

Description Damian Rouson 2012-02-07 20:52:01 UTC
A build from a snapshot of the development branch as of February 4 appears to have a regression on deferred-length character functions.  The text below shows a test that compiles with gcc 4.6.2 but not with 4.7.  

$ cat character_function.F90
module foo_class 
  implicit none 
  type foo 
  contains 
    procedure :: bar
  end type 
contains 
  function bar(this)
    class(foo) :: this
    character(:), allocatable :: bar
  end function 
end module 
$ /opt/local/bin/gfortran-mp-4.6 -c character_function.F90
$ /opt/local/bin/gfortran-mp-4.7 -c character_function.F90
character_function.F90:9.22:

    class(foo) :: this
                      1
Error: Deferred-length character component 'bar' at (1) is not yet
supported
$ /opt/local/bin/gfortran-mp-4.7 --version
GNU Fortran (GCC) 4.7.0 20120204 (experimental)


Damian
Comment 1 Tobias Burnus 2012-02-08 08:13:27 UTC
Possible patch:
  http://gcc.gnu.org/ml/fortran/2012-02/msg00031.html

While the patch fixes a bogus error, it also protected the compiler from an - unrelated - ICE involving deferred-length function results: One now gets for PR 45170 comment #19 a segfault instead of the bogus error message. Cf.
  http://gcc.gnu.org/ml/fortran/2012-02/msg00035.html
Comment 2 Alessandro Fanfarillo 2012-05-06 10:32:22 UTC
Created attachment 27323 [details]
Patch for 52158 and 45170#19

Patch realized on gcc version 4.8.0 20120505
Comment 3 Alessandro Fanfarillo 2012-05-06 10:38:12 UTC
Hi all,

with the Tobias support I realized this patch (which includes the Paul one) for PR 45170#19.

I'm a newbie, so I'm waiting for comments before to send the patch to gcc-fortran and gcc-patches mailing lists.

Regards.
Comment 4 Tobias Burnus 2012-05-13 10:52:37 UTC
Author: burnus
Date: Sun May 13 10:52:32 2012
New Revision: 187436

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187436
Log:
2012-05-13  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>
            Tobias Burnus  <burnus@net-b.de>

        PR fortran/52158
        PR fortran/45170
        PR fortran/49430
        * resolve.c (resolve_fl_derived0): Deferred character length 
        procedure components are supported.
        * trans-expr.c (gfc_conv_procedure_call): Handle TBP with 
        deferred-length results.
        (gfc_string_to_single_character): Add a new check to prevent
        NULL read.
        (gfc_conv_procedure_call): Remove unuseful checks on 
        symbol's attributes. Add new checks to prevent NULL read on
        string length. 

2012-05-13  Alessandro Fanfarillo  <fanfarillo.gcc@gmail.com>

        PR fortran/45170
        * gfortran.dg/deferred_type_param_3.f90: New.
        * gfortran.dg/deferred_type_proc_pointer_1.f90: New.
        * gfortran.dg/deferred_type_proc_pointer_2.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/deferred_type_param_3.f90
    trunk/gcc/testsuite/gfortran.dg/deferred_type_proc_pointer_1.f90
    trunk/gcc/testsuite/gfortran.dg/deferred_type_proc_pointer_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Tobias Burnus 2012-05-13 11:21:17 UTC
FIXED on thr 4.8 trunk.

Thanks Damian for the test case (in this PR and in PR 45170 comment 19).