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


>> > - ? ?integer(c_int), dimension(:), pointer :: int_ptr
>> > - ? ?my_c_ptr = c_loc(int_ptr(0))
>> >
>> > Well, as written is is invalid - but change it to
>> >
>> > - ? ?integer(c_int), dimension(:), pointer :: int_ptr
>> > ALLOCATE(int_ptr(0:10))
>> > - ? ?my_c_ptr = c_loc(int_ptr(0))
>> >
>> > Then it is valid.
>>
>> ... which means that a through check for validity is
>> very hard to do at compile time, since it depends on
>> the run-time value, right?
>
> Yes, like most pointer-initialization problems, most cannot
> be detected at compile time and some only with quite some
> effort. However, for compiling,
> ?my_c_ptr = c_loc(int_ptr(0))
> it should be enough to decide whether (based on that line and
> the function/variable declarations) it could be valid - and
> if so, one accepts the code. In the example, one could track
> whether "int_ptr" is ever pointer associated or allocated
> before using it; I think NAG's f95 does some of these checks,

Ok. I'm certainly not very keen on implementing this right now, but
one can open an enhancement PR for it.


Anyway, would it be ok if I commit the bulk changes needed for pointer
init now (i.e. version #2 of the patch as posted yesterday), and take
care of the remaining problems afterwards?


The remaining problems being:

(1) Initializing to a pointer:

module m
 implicit none
 integer, target, save  :: t1
 integer, pointer :: p1 => t
 integer, pointer :: p2 => p1    ! ICE
end module m

For this one currently gets:

f951: internal compiler error: in record_reference, at cgraphbuild.c:60

but I have absolutely no idea how that comes about.



(2) Making global variables in a program SAVE_IMPLICIT.

If I do that (analogously to module variables), then I get a couple of
regressions, e.g.:

alloc_comp_basics_1.f90
alloc_comp_constructor_1.f90
...

It seems that SAVE_IMPLICIT messes up automatic deallocation ...


Cheers,
Janus


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