This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[Patch, Fortran] PR37504 Fix special case of PROTECTED pointer assignment


Hi all,

the attached patch fixes

  some_pointer => protected_pointer

which is valid. (Protected pointers' associations may not be changed,
but their target's value may.) Before gfortran (and sunf95) rejected
it. See PR and c.l.f for details.

As I saw that the error message looks strange, I debugged it but I have
not found yet a working patch and thus deferred it to PR37513.
While debugging I found out that the checks in match.c can never be
reached as the  match("%v =>") fails earlier. (In match_variable
is the protected pointer check.) I thus decided to clean up the code
by removing these checks.

Build and currently regtesting on x86-64-linux.
OK for the trunk if regtesting suceeds?
Shall I also apply the expr.c part of the patch to 4.3?

Tobias
2008-09-14  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37504
	* expr.c (gfc_check_pointer_assign): Allow assignment of
	protected pointers.
	* match.c (gfc_match_assignment,gfc_match_pointer_assignment):
	Remove unreachable code.

2008-09-14  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37504
	* gfortran.dg/protected_7.f90: New test.

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(Revision 140345)
+++ gcc/fortran/expr.c	(Arbeitskopie)
@@ -3050,7 +3050,8 @@ gfc_check_pointer_assign (gfc_expr *lval
       return FAILURE;
     }
 
-  if (attr.is_protected && attr.use_assoc)
+  if (attr.is_protected && attr.use_assoc
+      && !(attr.pointer || attr.proc_pointer))
     {
       gfc_error ("Pointer assignment target has PROTECTED "
 		 "attribute at %L", &rvalue->where);
Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(Revision 140345)
+++ gcc/fortran/match.c	(Arbeitskopie)
@@ -1293,15 +1293,6 @@ gfc_match_assignment (void)
       return MATCH_NO;
     }
 
-  if (lvalue->symtree->n.sym->attr.is_protected
-      && lvalue->symtree->n.sym->attr.use_assoc)
-    {
-      gfc_current_locus = old_loc;
-      gfc_free_expr (lvalue);
-      gfc_error ("Setting value of PROTECTED variable at %C");
-      return MATCH_ERROR;
-    }
-
   rvalue = NULL;
   m = gfc_match (" %e%t", &rvalue);
   if (m != MATCH_YES)
@@ -1353,14 +1344,6 @@ gfc_match_pointer_assignment (void)
   if (m != MATCH_YES)
     goto cleanup;
 
-  if (lvalue->symtree->n.sym->attr.is_protected
-      && lvalue->symtree->n.sym->attr.use_assoc)
-    {
-      gfc_error ("Assigning to a PROTECTED pointer at %C");
-      m = MATCH_ERROR;
-      goto cleanup;
-    }
-
   new_st.op = EXEC_POINTER_ASSIGN;
   new_st.expr = lvalue;
   new_st.expr2 = rvalue;
Index: gcc/testsuite/gfortran.dg/protected_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/protected_7.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/protected_7.f90	(Revision 0)
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! PR fortran/37504
+!
+module m
+  implicit none
+  integer, pointer, protected :: protected_pointer
+  integer, target,  protected :: protected_target
+end module m
+
+program p
+  use m
+  implicit none
+  integer, pointer :: unprotected_pointer
+  ! The next two lines should be rejected; see PR 37513 why
+  ! we get such a strange error message.
+  protected_pointer => unprotected_pointer ! { dg-error "only allowed in specification part" }
+  protected_pointer =  unprotected_pointer ! { dg-error "only allowed in specification part" }
+  unprotected_pointer => protected_target  ! { dg-error "target has PROTECTED attribute" }
+  unprotected_pointer => protected_pointer ! OK
+end program p
+
+! { dg-final { cleanup-modules "m" } }

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