Hi Thomas,

>>> I think an unconditional warning is OK
>>> in this case because
>>>
>>> - Assigning to a pointer from an obvious non-contiguous target
>>>    is not useful at all, that I can see
>>
>>
>> I guess you're talking about a *contiguous* pointer here,
>
> Correct.
>
>> and in that
>> case I would argue that, beyond being "not useful", it's even illegal,
>> so why not throw a hard error, if we can infer at compile-time that
>> the target is non-contiguous?
>
> Problem is, we cannot infer this from the tests done.
> We would also have to add a test if the array is empty
> or that it contains only a single element, and that (I think)
> is a) impossible in the general case, and b) not worth the bother.

I'm not sure I understand which cases you're worried about here. Maybe
you can give an example?

In any case, I think your test case is a bit short, so I extended it
somewhat (see attachment) and found two cases along the way where your
patch throws a warning but shouldn't:

r => x(::-1)
r => x2(2:3,1)

The first one is a stride of minus one, which is valid and contiguous
AFAICS. The second one is obviously also contiguous.


>> As explained above, I'd vote for an error (or at least a conditional
>> warning, so that it can be disabled, like most(?) other gfortran
>> warnings).
>
> Attached is a version which makes this a warning enabled by -Wall;
> this should be enough to give people a heads-up.
>
> I have introduced most of your comments into the revised patch.

Thank you, looks much better already.

Apart from the two mishandled cases above, one other thing comes to my
mind: It might be a good idea to apply your checks not only to pointer
assignments, but also to dummy arguments (passing a non-contiguous
array to a contiguous dummy pointer), where the same rules should
apply.


> So, here is the updated patch.  Regression-tested on
> powerpc-linux, make dvi and make pdf also passed.
> OK for trunk?

Not quite, but we're getting closer :)

Sorry for being such a nag ...

Cheers,
Janus
! { dg-do compile }
! { dg-additional-options "-Wcontiguous" }
program cont_01_neg
  implicit none
  real, pointer, contiguous :: r(:)
  real, pointer, contiguous :: r2(:,:)
  real, target :: x(45)
  real, target :: x2(5,9)
  integer :: i

  x = (/ (real(i),i=1,45) /)
  x2 = reshape(x,shape(x2))
  i = 4

  r => x(::1)
  r => x(::-1)      ! bogus warning here
  r => x(::3)       ! { dg-warning "Assignment to contiguous pointer" }
  r => x(::-3)      ! { dg-warning "Assignment to contiguous pointer" }
  r => x(::i)       ! { dg-warning "Assignment to contiguous pointer" }

  r2 => x2(:,2:)
  r2 => x2(1:,:)
  r2 => x2(2:,:)    ! { dg-warning "Assignment to contiguous pointer" }

  r2 => x2(:,:4)
  r2 => x2(:5,:)
  r2 => x2(:4,:)    ! { dg-warning "Assignment to contiguous pointer" }

  r2 => x2(:,2:3)
  r2 => x2(1:5,:)
  r2 => x2(2:3,:)   ! { dg-warning "Assignment to contiguous pointer" }

  r => x2(3,:)      ! { dg-warning "Assignment to contiguous pointer" }
  r => x2(:,3)

  r2 => x2(3:3,:)   ! { dg-warning "Assignment to contiguous pointer" }
  r2 => x2(:,3:3)

  r2 => x2(2:3:2,:) ! { dg-warning "Assignment to contiguous pointer" }
  r2 => x2(:,2:3:2) ! { dg-warning "Assignment to contiguous pointer" }

  r => x2(1,2:3)
  r => x2(2:3,1)    ! bogus warning here

end program

Reply via email to