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] Fix PR 38536


Hi Tobias,

>> > On 01/15/2011 02:45 PM, Thomas Koenig wrote:
>>>>> >>>> here is an update of the patch.  This one just warns about array
>>>>> >>>> sections if they are followed by component references.
>> > 
>> > s/warns/prints an error/
>> > 
>>> >> Revision 169130 übertragen.
>> > 
>> > How about the following patch on top of it? I think the crucial part
>> > (for F2008 at least) is rather the contiguity. The patch looks longer
>> > than it is due to white space changes.
> Shouldn't the test on gfc_is_simply_contiguous be reversed?  The test
> case in c_loc_tests_16.f90 would then have to be changed.

I applied your patch with the test reversed and tested it with the
following source:

ig25@linux-fd1f:~/Krempel/Ref-c> cat cloc.f90
! { dg-do compile }
! PR 38536 - array sections as arguments to c_loc are illegal.
program main
  use iso_c_binding
  implicit none
  interface
     subroutine fun(arg) BIND(C)
       use iso_c_binding
       type(c_ptr) :: arg
     end subroutine fun
  end interface

  integer(c_int), target :: n(3)

  type(C_PTR) :: p

  n(1) = 3
  n(2) = 5
  n(3) = 7
  p = c_loc(n)
  call fun(p)
  p = c_loc(n(2:3))  ! { dg-warning "Array section" }
  call fun(p)
  print *,n
end program main
ig25@linux-fd1f:~/Krempel/Ref-c> cat fun.c
#include <stdio.h>

void fun(void *);

void fun(void *p)
{
  int *pp;
  pp = p;
  printf("%p %d %d\n",p, pp[0], pp[1]);
}
ig25@linux-fd1f:~/Krempel/Ref-c> gfortran cloc.f90 fun.c
ig25@linux-fd1f:~/Krempel/Ref-c> ./a.out
0x7fff4e19b508 1310307600 32767
0x7fff4e19b508 1310307604 32767
           3           5           7

Either my test program is wrong (which is entirely possible because I
don't use ISO C binding myself, much), or there are at least two
problems with using c_loc like this - the first version should have
worked in any case.

	Thomas


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