diff mbox series

[fortran] PR80657 - [7/8/9 Regression] Loop in character function declaration

Message ID CAGkQGiJR8V=5DzA=LknU0vYRk1iFvWfAORZYpLJ7qQBBfCWS4w@mail.gmail.com
State New
Headers show
Series [fortran] PR80657 - [7/8/9 Regression] Loop in character function declaration | expand

Commit Message

Paul Richard Thomas May 19, 2018, 10:39 a.m. UTC
I intend to commit this as 'obvious' once the patches for PR82923 and
82275 are out of the way.

Paul

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

    PR fortran/80657
    * resolve.c (flag_fn_result_spec): Use the 'sym' argument to
    test for self refs to the function result in the character len
    expression. If a self reference is found, emit an error and
    return true.
    (resolve_fntype): Use the function symbol in the calls to the
    above.

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

    PR fortran/80657
    * gfortran.dg/char_result_18.f90: New test.
diff mbox series

Patch

Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 260389)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_equivalence (gfc_equiv *eq)
*** 16217,16223 ****
  
  static bool
  flag_fn_result_spec (gfc_expr *expr,
!                      gfc_symbol *sym ATTRIBUTE_UNUSED,
                       int *f ATTRIBUTE_UNUSED)
  {
    gfc_namespace *ns;
--- 16217,16223 ----
  
  static bool
  flag_fn_result_spec (gfc_expr *expr,
!                      gfc_symbol *sym,
                       int *f ATTRIBUTE_UNUSED)
  {
    gfc_namespace *ns;
*************** flag_fn_result_spec (gfc_expr *expr,
*** 16230,16235 ****
--- 16230,16242 ----
  	if (!ns->parent)
  	  break;
  
+       if (sym == s)
+ 	{
+ 	  gfc_error ("Self reference in character length expression "
+ 		     "for %qs at %L", sym->name, &expr->where);
+ 	  return true;
+ 	}
+ 
        if (!s->fn_result_spec
  	  && s->attr.flavor == FL_PARAMETER)
  	{
*************** resolve_fntype (gfc_namespace *ns)
*** 16312,16318 ****
        }
  
    if (sym->ts.type == BT_CHARACTER)
!     gfc_traverse_expr (sym->ts.u.cl->length, NULL, flag_fn_result_spec, 0);
  }
  
  
--- 16319,16325 ----
        }
  
    if (sym->ts.type == BT_CHARACTER)
!     gfc_traverse_expr (sym->ts.u.cl->length, sym, flag_fn_result_spec, 0);
  }
  
  
Index: gcc/testsuite/gfortran.dg/char_result_18.f90
===================================================================
*** gcc/testsuite/gfortran.dg/char_result_18.f90	(nonexistent)
--- gcc/testsuite/gfortran.dg/char_result_18.f90	(working copy)
***************
*** 0 ****
--- 1,10 ----
+ ! { dg-do compile }
+ !
+ ! Tests the fix for PR80657.
+ !
+ ! Contributed by Vittorio Zecca  <zeccav@gmail.com>
+ !
+ function f(x)
+ implicit character(len(f)) (x) ! { dg-error "Self reference in character length" }
+ character(len(x)) f
+ end