[fortran] PR49630 - [OOP] ICE on obsolescent deferred-length type bound character function

Message ID CAGkQGi+6NqYydemVd=zaP-T=dtmf322L_FwyzdDg0fik8Ua8sQ@mail.gmail.com
State New
Headers show
Series
  • [fortran] PR49630 - [OOP] ICE on obsolescent deferred-length type bound character function
Related show

Commit Message

Paul Richard Thomas June 19, 2018, 9:16 a.m.
I got caught with a wild goose chase with this one. I tried to get it
to work before seeing the standard reference in trans-expr.c. In fact,
it would be impossible to fix because there is no way to resolve
different instances of the abstract interface with different character
lengths.

Bootstrapped and regtested on FC28/x86_64 - OK for trunk.

I do not intend to backport it unless there is any enthusiasm for me to do so.

Regards

Paul

2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/49630
    * resolve.c (resolve_contained_fntype): Change standard ref.
    from F95 to F2003: C418. Correct a spelling error in a comment.
    It is an error for an abstract interface to have an assumed
    character length result.
    * trans-expr.c (gfc_conv_procedure_call): Likewise change the
    standard reference.

2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/49630
    * gfortran.dg/assumed_charlen_function_7.f90: New test.

Comments

Paul Richard Thomas June 21, 2018, 8:03 a.m. | #1
Ping!

On 19 June 2018 at 10:16, Paul Richard Thomas
<paul.richard.thomas@gmail.com> wrote:
> I got caught with a wild goose chase with this one. I tried to get it

> to work before seeing the standard reference in trans-expr.c. In fact,

> it would be impossible to fix because there is no way to resolve

> different instances of the abstract interface with different character

> lengths.

>

> Bootstrapped and regtested on FC28/x86_64 - OK for trunk.

>

> I do not intend to backport it unless there is any enthusiasm for me to do so.

>

> Regards

>

> Paul

>

> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

>

>     PR fortran/49630

>     * resolve.c (resolve_contained_fntype): Change standard ref.

>     from F95 to F2003: C418. Correct a spelling error in a comment.

>     It is an error for an abstract interface to have an assumed

>     character length result.

>     * trans-expr.c (gfc_conv_procedure_call): Likewise change the

>     standard reference.

>

> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

>

>     PR fortran/49630

>     * gfortran.dg/assumed_charlen_function_7.f90: New test.




-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
Steve Kargl June 21, 2018, 3:25 p.m. | #2
On Thu, Jun 21, 2018 at 09:03:47AM +0100, Paul Richard Thomas wrote:
> Ping!

> 

> > 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

> >

> >     PR fortran/49630

> >     * resolve.c (resolve_contained_fntype): Change standard ref.

> >     from F95 to F2003: C418. Correct a spelling error in a comment.

> >     It is an error for an abstract interface to have an assumed

> >     character length result.

> >     * trans-expr.c (gfc_conv_procedure_call): Likewise change the

> >     standard reference.

> >

> > 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

> >

> >     PR fortran/49630

> >     * gfortran.dg/assumed_charlen_function_7.f90: New test.


OK.

-- 
Steve
Martin Liška June 22, 2018, 11:36 a.m. | #3
On 06/21/2018 05:25 PM, Steve Kargl wrote:
> On Thu, Jun 21, 2018 at 09:03:47AM +0100, Paul Richard Thomas wrote:

>> Ping!

>>

>>> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

>>>

>>>     PR fortran/49630

>>>     * resolve.c (resolve_contained_fntype): Change standard ref.

>>>     from F95 to F2003: C418. Correct a spelling error in a comment.

>>>     It is an error for an abstract interface to have an assumed

>>>     character length result.

>>>     * trans-expr.c (gfc_conv_procedure_call): Likewise change the

>>>     standard reference.

>>>

>>> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

>>>

>>>     PR fortran/49630

>>>     * gfortran.dg/assumed_charlen_function_7.f90: New test.

> 

> OK.

> 


Hi.

If I see correctly it caused:

$ ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/typebound_proc_35.f90 -c
f951: internal compiler error: Segmentation fault
0x10d0b55 crash_signal
	/home/marxin/Programming/gcc/gcc/toplev.c:324
0x7ffff6d8ba6f ???
	/usr/src/debug/glibc-2.27-5.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x916122 resolve_function
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:3119
0x91e829 gfc_resolve_expr(gfc_expr*)
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:6741
0x91d7b8 resolve_compcall
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:6299
0x91dbb5 resolve_typebound_function
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:6408
0x91e89f gfc_resolve_expr(gfc_expr*)
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:6752
0x928b2a gfc_resolve_code(gfc_code*, gfc_namespace*)
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:11137
0x9364ad resolve_codes
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:16581
0x93638b resolve_codes
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:16565
0x9365d7 gfc_resolve(gfc_namespace*)
	/home/marxin/Programming/gcc/gcc/fortran/resolve.c:16616
0x9070f9 gfc_parse_file()
	/home/marxin/Programming/gcc/gcc/fortran/parse.c:6266
0x962a81 gfc_be_parse_file
	/home/marxin/Programming/gcc/gcc/fortran/f95-lang.c:204

and some other ICEs:

FAIL: gfortran.dg/actual_array_offset_1.f90   -O0  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O0  (test for excess errors)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O1  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O1  (test for excess errors)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O2  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O2  (test for excess errors)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess errors)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -g  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -g  (test for excess errors)
FAIL: gfortran.dg/actual_array_offset_1.f90   -Os  (internal compiler error)
FAIL: gfortran.dg/actual_array_offset_1.f90   -Os  (test for excess errors)
FAIL: gfortran.dg/assumed_charlen_function_7.f90   -O  (test for excess errors)
FAIL: gfortran.dg/interface_abstract_4.f90   -O  (internal compiler error)
FAIL: gfortran.dg/interface_abstract_4.f90   -O  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -O0  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -O0  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -O1  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -O1  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -O2  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -O2  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -g  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -g  (test for excess errors)
FAIL: gfortran.dg/typebound_proc_35.f90   -Os  (internal compiler error)
FAIL: gfortran.dg/typebound_proc_35.f90   -Os  (test for excess errors)

Martin
Christophe Lyon June 23, 2018, 4:11 p.m. | #4
On Fri, 22 Jun 2018 at 13:36, Martin Liška <mliska@suse.cz> wrote:
>

> On 06/21/2018 05:25 PM, Steve Kargl wrote:

> > On Thu, Jun 21, 2018 at 09:03:47AM +0100, Paul Richard Thomas wrote:

> >> Ping!

> >>

> >>> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

> >>>

> >>>     PR fortran/49630

> >>>     * resolve.c (resolve_contained_fntype): Change standard ref.

> >>>     from F95 to F2003: C418. Correct a spelling error in a comment.

> >>>     It is an error for an abstract interface to have an assumed

> >>>     character length result.

> >>>     * trans-expr.c (gfc_conv_procedure_call): Likewise change the

> >>>     standard reference.

> >>>

> >>> 2018-06-19  Paul Thomas  <pault@gcc.gnu.org>

> >>>

> >>>     PR fortran/49630

> >>>     * gfortran.dg/assumed_charlen_function_7.f90: New test.

> >

> > OK.

> >

>

> Hi.

>

> If I see correctly it caused:

>

> $ ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/typebound_proc_35.f90 -c

> f951: internal compiler error: Segmentation fault

> 0x10d0b55 crash_signal

>         /home/marxin/Programming/gcc/gcc/toplev.c:324

> 0x7ffff6d8ba6f ???

>         /usr/src/debug/glibc-2.27-5.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0

> 0x916122 resolve_function

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:3119

> 0x91e829 gfc_resolve_expr(gfc_expr*)

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:6741

> 0x91d7b8 resolve_compcall

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:6299

> 0x91dbb5 resolve_typebound_function

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:6408

> 0x91e89f gfc_resolve_expr(gfc_expr*)

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:6752

> 0x928b2a gfc_resolve_code(gfc_code*, gfc_namespace*)

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:11137

> 0x9364ad resolve_codes

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:16581

> 0x93638b resolve_codes

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:16565

> 0x9365d7 gfc_resolve(gfc_namespace*)

>         /home/marxin/Programming/gcc/gcc/fortran/resolve.c:16616

> 0x9070f9 gfc_parse_file()

>         /home/marxin/Programming/gcc/gcc/fortran/parse.c:6266

> 0x962a81 gfc_be_parse_file

>         /home/marxin/Programming/gcc/gcc/fortran/f95-lang.c:204

>

> and some other ICEs:

>

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O0  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O0  (test for excess errors)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O1  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O1  (test for excess errors)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O2  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O2  (test for excess errors)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess errors)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -g  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -O3 -g  (test for excess errors)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -Os  (internal compiler error)

> FAIL: gfortran.dg/actual_array_offset_1.f90   -Os  (test for excess errors)

> FAIL: gfortran.dg/assumed_charlen_function_7.f90   -O  (test for excess errors)

> FAIL: gfortran.dg/interface_abstract_4.f90   -O  (internal compiler error)

> FAIL: gfortran.dg/interface_abstract_4.f90   -O  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O0  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O0  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O1  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O1  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O2  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O2  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -g  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -O3 -g  (test for excess errors)

> FAIL: gfortran.dg/typebound_proc_35.f90   -Os  (internal compiler error)

> FAIL: gfortran.dg/typebound_proc_35.f90   -Os  (test for excess errors)

>


I've seen that on arm and aarch64 too.

> Martin
Steve Kargl June 23, 2018, 4:15 p.m. | #5
On Sat, Jun 23, 2018 at 06:11:24PM +0200, Christophe Lyon wrote:
> 

> I've seen that on arm and aarch64 too.

> 


It was fixed yesterday.  Update your sources.

-- 
Steve
Christophe Lyon June 23, 2018, 4:55 p.m. | #6
On Sat, 23 Jun 2018 at 18:16, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
>

> On Sat, Jun 23, 2018 at 06:11:24PM +0200, Christophe Lyon wrote:

> >

> > I've seen that on arm and aarch64 too.

> >

>

> It was fixed yesterday.  Update your sources.

>

Ha right, sorry for the noise. I missed because it was masked by other
regressions breaking the tcl code (GUALITY_GDB_NAME changes)

> --

> Steve

Patch

Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 261126)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_contained_fntype (gfc_symbol *sy
*** 601,609 ****
  	}
      }
  
!   /* Fortran 95 Draft Standard, page 51, Section 5.1.1.5, on the Character
       type, lists the only ways a character length value of * can be used:
!      dummy arguments of procedures, named constants, and function results
       in external functions.  Internal function results and results of module
       procedures are not on this list, ergo, not permitted.  */
  
--- 601,610 ----
  	}
      }
  
!   /* Fortran 2003 Draft Standard, page 535, C418, on type-param-value
       type, lists the only ways a character length value of * can be used:
!      dummy arguments of procedures, named constants, function results and
!      in allocate statements if the allocate_object is an assumed length dummy
       in external functions.  Internal function results and results of module
       procedures are not on this list, ergo, not permitted.  */
  
*************** resolve_function (gfc_expr *expr)
*** 3103,3109 ****
        return false;
      }
  
!   /* If this ia a deferred TBP with an abstract interface (which may
       of course be referenced), expr->value.function.esym will be set.  */
    if (sym && sym->attr.abstract && !expr->value.function.esym)
      {
--- 3104,3110 ----
        return false;
      }
  
!   /* If this is a deferred TBP with an abstract interface (which may
       of course be referenced), expr->value.function.esym will be set.  */
    if (sym && sym->attr.abstract && !expr->value.function.esym)
      {
*************** resolve_function (gfc_expr *expr)
*** 3112,3117 ****
--- 3113,3129 ----
        return false;
      }
  
+   /* If this is a deferred TBP with an abstract interface, its result
+      cannot be an assumed length character (F2003: C418).  */
+   if (sym && sym->attr.abstract && sym->attr.function
+       && sym->result->ts.u.cl->length == NULL)
+     {
+       gfc_error ("ABSTRACT INTERFACE %qs at %L must not have an assumed "
+ 		 "character length result (F2003: C418)", sym->name,
+ 		 &sym->declared_at);
+       return false;
+     }
+ 
    /* 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/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 261126)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_conv_procedure_call (gfc_se * se, gf
*** 5941,5947 ****
      {
        if (ts.u.cl->length == NULL)
  	{
! 	  /* Assumed character length results are not allowed by 5.1.1.5 of the
  	     standard and are trapped in resolve.c; except in the case of SPREAD
  	     (and other intrinsics?) and dummy functions.  In the case of SPREAD,
  	     we take the character length of the first argument for the result.
--- 5941,5947 ----
      {
        if (ts.u.cl->length == NULL)
  	{
! 	  /* Assumed character length results are not allowed by C418 of the 2003
  	     standard and are trapped in resolve.c; except in the case of SPREAD
  	     (and other intrinsics?) and dummy functions.  In the case of SPREAD,
  	     we take the character length of the first argument for the result.
Index: gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90
===================================================================
*** gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90	(nonexistent)
--- gcc/testsuite/gfortran.dg/assumed_charlen_function_7.f90	(working copy)
***************
*** 0 ****
--- 1,34 ----
+ ! { dg-do compile }
+ !
+ ! Test the fix for PR49630, comment #11.
+ !
+ ! Contributed by Vittorio Zecca  <zeccav@gmail.com>
+ !
+ module abc
+   implicit none
+   type,abstract::abc_abstract
+   contains
+     procedure(abc_interface),deferred::abc_function
+   end type abc_abstract
+   type,extends(abc_abstract)::abc_type
+   contains
+     procedure::abc_function
+   end type abc_type
+   abstract interface
+     function abc_interface(this) ! { dg-error "assumed character length result" }
+       import abc_abstract
+       class(abc_abstract),intent(in)::this
+       character(len=*)::abc_interface
+     end function abc_interface
+   end interface
+ contains
+   function abc_function(this)
+     class(abc_type),intent(in)::this
+     character(len=5)::abc_function
+     abc_function="hello"
+   end function abc_function
+   subroutine do_something(this)
+     class(abc_abstract),intent(in)::this
+     print *,this%abc_function()
+   end subroutine do_something
+ end module abc