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: RFA: Revamp fortran array types


On 08/18/2009 05:14 PM, Steve Kargl wrote:
> On Tue, Aug 18, 2009 at 04:40:17PM +0200, Michael Matz wrote:
>   
>> ----------------------------------
>>   integer, target :: foo
>>   integer, pointer :: p,p2
>>   integer :: i
>>   p=>foo
>>   p2=>foo
>>   i = clobber(p,p2)
>>   if (i /= 2) call abort
>> contains
>>   function clobber(p,p2)
>>     integer clobber
>>     integer, pointer :: p,p2
>>     p = 1
>>     p2 = 2
>>     clobber = p
>>   end function
>> end
>> ----------------------------------
>>
>> An unpatched compiler with "-O2 -fno-inline" will make this testcase 
>> abort, exactly due to the hack called flag_argument_noalias.
>>     
> The above code is technically invalid Fortran, so a compiler
> can do whatever it wants.  The abort is a possible "correct"
> result.  The standard prohits a programmer from aliasing 
> the input arguments.  The standard also does not require a
> compiler to detect aliasing.
>   

I think this is oversimplified:

"12.5.2.13 Restrictions on entities associated with dummy arguments"
"Action that affects the value of the entity or any subobject of it
shall be taken only through the dummy argument unless ... the actual
argument is a target"

(For pointer it presumably means the target to which the pointer points
to, i.e. those are covered as well.)

Thus the example looks fine to me - unless I missed some fine-print
somewhere.

(Quote taken from the last Fortran 2008 draft, cf.
http://gcc.gnu.org/wiki/GFortranStandards; other relevant quotes for
aliasing are:
"5.3.17 TARGET attribute": "The TARGET attribute specifies that a data
object may have a pointer associated with it (7.2.2). An object without
the TARGET attribute shall not have a pointer associated with it."
"If the dummy argument has the TARGET attribute and the effective
argument does not have the TARGET attribute or is an array section with
a vector subscript, any pointers associated with the dummy argument
become undefined when execution of the procedure completes." (12.5.2.4
Ordinary dummy variables).)

Tobias


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