This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] PR20880 - Failure to detect procedures encompassing own interface


Grigory,

Many thanks for the prompt report. The attached regtests and cures your problem. It also fixes and tests PR29976.

I propose to apply the attached, as obvious, first thing tomorrow morning:

(i) For PR20880, apply a further check that the symbol be referenced so that ambiguous module symbols are tolerated, unless referred to. Amusingly, the original PR now does not emit an error but sensible cases are fixed.

(ii) For PR29976, the line of code that is patched was plain wrong :-) The testcase is the reporter's.

Cheers

Paul

2006-11-28 Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20880
	* resolve.c (resolve_fl_procedure): Error if procedure is
	ambiguous modified to require attr.referenced.

	PR fortran/29976
	* trans-expr.c (gfc_conv_missing_dummy): Remove build_int_const
	and replace with cast to type of se->expr of integer_zero_node.

2006-11-28 Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20880
	* gfortran.dg/interface_3.f90: Modify errors.

	PR fortrab/29976
	* gfortran.dg/missing_optional_dummy_3.f90
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c	(revision 119261)
--- gcc/fortran/trans-expr.c	(working copy)
*************** gfc_conv_missing_dummy (gfc_se * se, gfc
*** 153,159 ****
  
    present = gfc_conv_expr_present (arg->symtree->n.sym);
    tmp = build3 (COND_EXPR, TREE_TYPE (se->expr), present, se->expr,
! 		build_int_cst (TREE_TYPE (se->expr), 0));
    tmp = gfc_evaluate_now (tmp, &se->pre);
    se->expr = tmp;
    if (ts.type == BT_CHARACTER)
--- 153,160 ----
  
    present = gfc_conv_expr_present (arg->symtree->n.sym);
    tmp = build3 (COND_EXPR, TREE_TYPE (se->expr), present, se->expr,
! 		fold_convert (TREE_TYPE (se->expr), integer_zero_node));
! 
    tmp = gfc_evaluate_now (tmp, &se->pre);
    se->expr = tmp;
    if (ts.type == BT_CHARACTER)
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 119261)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_fl_procedure (gfc_symbol *sym, i
*** 5523,5529 ****
      return FAILURE;
  
    st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
!   if (st && st->ambiguous && !sym->attr.generic)
      {
        gfc_error ("Procedure %s at %L is ambiguous",
  		 sym->name, &sym->declared_at);
--- 5523,5531 ----
      return FAILURE;
  
    st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
!   if (st && st->ambiguous
! 	 && sym->attr.referenced
! 	 && !sym->attr.generic)
      {
        gfc_error ("Procedure %s at %L is ambiguous",
  		 sym->name, &sym->declared_at);
Index: gcc/testsuite/gfortran.dg/interface_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/interface_3.f90	(revision 119261)
--- gcc/testsuite/gfortran.dg/interface_3.f90	(working copy)
*************** interface
*** 18,31 ****
  end interface
  end module
  
! ! This is the original PR
! subroutine my_sub (a) ! { dg-error "is ambiguous" }
    use test_mod
    real a
    print *, a
  end subroutine
  
! integer function my_fun (a) ! { dg-error "is ambiguous" }
    use test_mod
    real a
    print *, a
--- 18,42 ----
  end interface
  end module
  
! module test_mod2
! interface
!   function my_fun (a)
!     real a, my_fun
!   end function
! end interface
! end module
! 
! 
! ! This is the original PR, excepting that the error requires the symbol
! ! to be referenced.
! subroutine my_sub (a)
    use test_mod
    real a
+   call my_sub (a)  ! { dg-error "ambiguous reference" }
    print *, a
  end subroutine
  
! integer function my_fun (a)
    use test_mod
    real a
    print *, a
*************** subroutine thy_sub (a)
*** 42,45 ****
--- 53,69 ----
    real a
    print *, a
  end subroutine
+ 
+ subroutine thy_fun (a)
+   use test_mod
+   use test_mod2  ! OK because there is no reference to my_fun
+   print *, a
+ end subroutine thy_fun
+ 
+ subroutine his_fun (a)
+   use test_mod
+   use test_mod2
+   print *, my_fun (a)  ! { dg-error "ambiguous reference" }
+ end subroutine his_fun
+ 
  ! { dg-final { cleanup-modules "test_mod" } }
Index: gcc/testsuite/gfortran.dg/missing_optional_dummy_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/missing_optional_dummy_3.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/missing_optional_dummy_3.f90	(revision 0)
***************
*** 0 ****
--- 1,32 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR29976, in which the call to CMPLX caused an
+ ! ICE with an optional dummy for the imaginary part.
+ !
+ ! Contributed by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+ !
+ SUBROUTINE pw_sumup (alpha_im)
+   REAL, INTENT(in), OPTIONAL :: alpha_im
+   COMPLEX :: my_alpha_c
+   IF (PRESENT(alpha_im)) THEN
+      my_alpha_c = CMPLX(0.,alpha_im)
+   END IF
+ END SUBROUTINE pw_sumup
+ 
+ ! Check non-intrinsic functions.
+ SUBROUTINE pw_sumup_2 (alpha_im)
+   REAL, INTENT(in), OPTIONAL :: alpha_im
+   COMPLEX :: my_alpha_c
+   IF (PRESENT(alpha_im)) THEN
+      my_alpha_c = MY_CMPLX(0.,alpha_im)
+   END IF
+ contains
+   complex function MY_CMPLX (re, im)
+     real, intent(in) :: re
+     real, intent(in), optional :: im
+     if (present (im)) then 
+       MY_CMPLX = cmplx (re, im)
+     else
+       MY_CMPLX = cmplx (re, 0.0)
+     end if
+   end function MY_CMPLX
+ END SUBROUTINE pw_sumup_2

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]