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, F08] PR45290: pointer initialization


>>> 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 deïned to have the POINTER attribute.

Chapter 6.5.3:
 * NOTE 6.10: Unless otherwise speciïed, 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

Attachment: pr45290_v3.diff
Description: Binary data


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