Component references to array values had a couple of TODOs in the contiguity checker; implement them so that contiguity errors/warnings and code generation are more accurate. Specifically, "a(1:1)%b" is contiguous because there's a single element; "a(1:2)%b" is contiguous when the type of "a" has but a single component. The case of multiple components in the type is discontiguous when the array is known to have multiple elements.
27 lines
685 B
Fortran
27 lines
685 B
Fortran
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
|
|
subroutine s1
|
|
type :: d1
|
|
real :: x
|
|
end type
|
|
type :: d2
|
|
type(d1) :: x
|
|
end type
|
|
type(d1), target :: a(5)
|
|
type(d2), target :: b(5)
|
|
real, pointer, contiguous :: c(:)
|
|
c => a%x ! okay, type has single component
|
|
c => b%x%x ! okay, types have single components
|
|
end
|
|
|
|
subroutine s2
|
|
type :: d1
|
|
real :: x, y
|
|
end type
|
|
type(d1), target :: b(5)
|
|
real, pointer, contiguous :: c(:)
|
|
!ERROR: CONTIGUOUS pointer may not be associated with a discontiguous target
|
|
c => b%x
|
|
c => b(1:1)%x ! okay, one element
|
|
!ERROR: CONTIGUOUS pointer may not be associated with a discontiguous target
|
|
c => b(1:2)%x
|
|
end
|