[Patch, Fortran, F08] PR45290: pointer initialization

Janus Weil janus@gcc.gnu.org
Tue Aug 17 21:19:00 GMT 2010


>>> And the following is invalid and gives an ICE:
>>>
>>> module m
>>>  integer, target, save  :: t1
>>>  integer, pointer :: p1 =>  t1
>>>  integer, pointer, save :: p2 =>  p2 ! invalid&  ICE
>>>  integer, pointer :: p3 =>  p1 ! ICE&  invalid as "p1" is not a TARGET
>>> end module m
>>
>> About this one I'm still not sure. F08 explicitly says:
>>
>> C556 An entity with the TARGET attribute shall not have the POINTER
>> attribute.
>>
>> But still gfc_variable_attr seems to set the TARGET attribute for
>> things that actually are POINTERS. Can someone explain this?
>
> Well, it gains the attribute after the declaration part when it appears as
> expression: in primary.c's gfc_variable_attr. If one looks at svn blame, one
> sees that the following line exists from the beginning of GCC 4.0.0:
>  if (pointer || attr.proc_pointer)
>    target = 1;
>
> I assume the idea was to allow for checks such as:
>  if (RHS->attr.target)
>    return Pointer_association_is_allowed
> instead of needing to use
>  if (RHS->attr.target || RHS->attr.pointer)
>    return Pointer_association_is_allowed
>
> But in my opinion, that's highly misleading and currently requires to write
> code such as
>  (attr.target && !attr.pointer)


Moreover it's plain wrong. But adding this patchlet:


Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 163310)
+++ gcc/fortran/primary.c	(working copy)
@@ -2017,8 +2017,6 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *t
     }

   target = attr.target;
-  if (pointer || attr.proc_pointer)
-    target = 1;

   if (ts != NULL && expr->ts.type == BT_UNKNOWN)
     *ts = sym->ts;
@@ -2074,8 +2072,6 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *t
 	    pointer = comp->attr.pointer;
 	    allocatable = comp->attr.allocatable;
 	  }
-	if (pointer || attr.proc_pointer)
-	  target = 1;

 	break;


gives me a couple of regressions:


FAIL: gfortran.fortran-torture/execute/ptr.f90 compilation,  -O0
FAIL: gfortran.dg/c_loc_tests_14.f90  -O  (test for excess errors)
FAIL: gfortran.dg/c_loc_tests_5.f03  -O  (test for excess errors)
FAIL: gfortran.dg/pointer_assign_4.f90  -O0  (test for excess errors)
FAIL: gfortran.dg/pr43984.f90  -O  (test for excess errors)
FAIL: gfortran.dg/subref_array_pointer_1.f90  -O0  (test for excess errors)

All of them, except the C_LOC ones, fail on pointer assignments. And I
think all of them are actually invalid.



Some applicable quotes from F08:


Chapter 5.3.14:
 * C546 An entity with the POINTER attribute shall not have the
ALLOCATABLE, INTRINSIC, or TARGET attribute, and shall not be a
coarray.

Chapter 5.3.17:
 * C556 An entity with the TARGET attribute shall not have the POINTER
attribute.
 * If an object has the TARGET attribute, then all of its nonpointer
subobjects also have the TARGET attribute.

Chapter 6.4.2:
 * A structure component is a pointer only if the rightmost part name
is defined to have the POINTER attribute.

Chapter 6.5.3:
 * NOTE 6.10: Unless otherwise specified, an array element or array
section does not have an attribute of the whole array. In particular,
an array element or an array section does not have the POINTER or
ALLOCATABLE attribute.


Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr45290_v3.diff
Type: application/octet-stream
Size: 14511 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20100817/ef1475d1/attachment.obj>


More information about the Fortran mailing list