[Patch, fortran] PR32047 - ICE (segfault) for pure function without argument
Paul Richard Thomas
paul.richard.thomas@gmail.com
Wed May 23 10:50:00 GMT 2007
:ADDPATCH fortran:
This problem was caused by an incorrect ordering of conditions in my
fix for PR31215. I propose to apply this patch, as 'obvious',
tonight.
Regtested on Cygwin_NT/PIV
Paul
2007-05-23 Paul Thomas <pault@gcc.gnu.org>
PR fortran/32047
* trans-expr.c (gfc_apply_interface_mapping_to_expr): Change
order in logic under EXPR_FUNCTION to handle functions with
no arguments.
2007-05-23 Paul Thomas <pault@gcc.gnu.org>
PR fortran/32047
* gfortran.dg/result_in_spec_2.f90: New test.
-------------- next part --------------
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c (r?vision 124902)
--- gcc/fortran/trans-expr.c (copie de travail)
*************** gfc_apply_interface_mapping_to_expr (gfc
*** 1653,1664 ****
break;
case EXPR_FUNCTION:
! if (expr->value.function.actual->expr->expr_type == EXPR_VARIABLE
! && gfc_apply_interface_mapping_to_expr (mapping,
! expr->value.function.actual->expr)
! && expr->value.function.esym == NULL
&& expr->value.function.isym != NULL
! && expr->value.function.isym->generic_id == GFC_ISYM_LEN)
{
gfc_expr *new_expr;
new_expr = gfc_copy_expr (expr->value.function.actual->expr->ts.cl->length);
--- 1653,1664 ----
break;
case EXPR_FUNCTION:
! if (expr->value.function.esym == NULL
&& expr->value.function.isym != NULL
! && expr->value.function.isym->generic_id == GFC_ISYM_LEN
! && expr->value.function.actual->expr->expr_type == EXPR_VARIABLE
! && gfc_apply_interface_mapping_to_expr (mapping,
! expr->value.function.actual->expr))
{
gfc_expr *new_expr;
new_expr = gfc_copy_expr (expr->value.function.actual->expr->ts.cl->length);
*************** gfc_conv_function_call (gfc_se * se, gfc
*** 2459,2465 ****
if (byref)
{
/* Add the function call to the pre chain. There is no expression. */
! gfc_add_expr_to_block (&se->pre, se->expr);
se->expr = NULL_TREE;
if (!se->direct_byref)
--- 2459,2466 ----
if (byref)
{
/* Add the function call to the pre chain. There is no expression. */
! if (!se->no_function_call)
! gfc_add_expr_to_block (&se->pre, se->expr);
se->expr = NULL_TREE;
if (!se->direct_byref)
Index: gcc/testsuite/gfortran.dg/result_in_spec_2.f90
===================================================================
*** gcc/testsuite/gfortran.dg/result_in_spec_2.f90 (r?vision 0)
--- gcc/testsuite/gfortran.dg/result_in_spec_2.f90 (r?vision 0)
***************
*** 0 ****
--- 1,30 ----
+ ! { dg-do run }
+ ! Tests the fix for PR32047, in which the null agument
+ ! function for the character length would cause an ICE.
+ !
+ ! Contributed by Tobias Burnus <burnus@gcc.gnu.org >
+ !
+ module test1
+ implicit none
+ contains
+ character(f()) function test2() result(r)
+ interface
+ pure function f()
+ integer f
+ end function f
+ end interface
+ r = '123'
+ end function test2
+ end module test1
+
+ pure function f()
+ integer :: f
+ f = 3
+ end function f
+
+ program test
+ use test1
+ implicit none
+ if(len (test2()) /= 3) call abort ()
+ if(test2() /= '123') call abort ()
+ end program test
More information about the Fortran
mailing list