Skip to content

Commit

Permalink
[flang] Accept CONTIGUOUS attribute when redundant (#70853)
Browse files Browse the repository at this point in the history
As an extension, accept the redundant use of the CONTIGUOUS attribute
when applied to scalars and to simply contiguous objects, with a
portability warning.
  • Loading branch information
klausler committed Oct 31, 2023
1 parent 5bfa16c commit 9191738
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions flang/docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ end
we also treat scalars as being trivially contiguous, so that they
can be used in contexts like data targets in pointer assignments
with bounds remapping.
* The `CONTIGUOUS` attribute can be redundantly applied to simply
contiguous objects, including scalars, with a portability warning.
* We support some combinations of specific procedures in generic
interfaces that a strict reading of the standard would preclude
when their calls must nonetheless be distinguishable.
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2129,11 +2129,11 @@ void CheckHelper::CheckContiguous(const Symbol &symbol) {
evaluate::IsAssumedRank(symbol))) {
} else if (symbol.owner().IsDerivedType()) { // C752
messages_.Say(
"CONTIGUOUS component '%s' must be an array with the POINTER attribute"_err_en_US,
"CONTIGUOUS component '%s' should be an array with the POINTER attribute"_port_en_US,
symbol.name());
} else {
messages_.Say(
"CONTIGUOUS entity '%s' must be an array pointer, assumed-shape, or assumed-rank"_err_en_US,
"CONTIGUOUS entity '%s' should be an array pointer, assumed-shape, or assumed-rank"_port_en_US,
symbol.name());
}
}
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Semantics/bind-c13.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Interoperable objects that require descriptors cannot be CONTIGUOUS
subroutine interop(ptr,ashape,arank,eshape,asize) bind(c)
!ERROR: An interoperable pointer must not be CONTIGUOUS
real, pointer, contiguous :: ptr(:)
real, contiguous :: ashape(:) ! ok
real, contiguous :: arank(..) ! ok
!ERROR: CONTIGUOUS entity 'eshape' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'eshape' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous :: eshape(10)
!ERROR: CONTIGUOUS entity 'asize' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'asize' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous :: asize(*)
end
4 changes: 2 additions & 2 deletions flang/test/Semantics/call07.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ subroutine s04(p)
end subroutine

subroutine test
!ERROR: CONTIGUOUS entity 'a01' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'a01' should be an array pointer, assumed-shape, or assumed-rank
real, pointer, contiguous :: a01 ! C830
real, pointer :: a02(:)
real, target :: a03(10)
real :: a04(10) ! not TARGET
!ERROR: CONTIGUOUS entity 'scalar' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'scalar' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous :: scalar
call s01(a03) ! ok
!WARNING: Target of CONTIGUOUS pointer association is not known to be contiguous
Expand Down
16 changes: 8 additions & 8 deletions flang/test/Semantics/contiguous01.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
module m0
real, pointer, contiguous :: p1(:) ! ok
real, pointer :: p2(:)
Expand All @@ -9,26 +9,26 @@ module m
contiguous p1
!ERROR: Cannot change CONTIGUOUS attribute on use-associated 'p2'
contiguous p2
!ERROR: CONTIGUOUS entity 'x' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'x' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous :: x
!ERROR: CONTIGUOUS entity 'scalar' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'scalar' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous, pointer :: scalar
!ERROR: CONTIGUOUS entity 'allocatable' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'allocatable' should be an array pointer, assumed-shape, or assumed-rank
real, contiguous, allocatable :: allocatable
contains
!ERROR: CONTIGUOUS entity 'func' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'func' should be an array pointer, assumed-shape, or assumed-rank
function func(ashape,arank) result(r)
real, contiguous :: ashape(:) ! ok
real, contiguous :: arank(..) ! ok
!ERROR: CONTIGUOUS entity 'r' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'r' should be an array pointer, assumed-shape, or assumed-rank
real :: r(10)
!ERROR: CONTIGUOUS entity 'r2' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'r2' should be an array pointer, assumed-shape, or assumed-rank
real :: r2(10)
contiguous func
contiguous r
contiguous e
contiguous r2
!ERROR: CONTIGUOUS entity 'e' must be an array pointer, assumed-shape, or assumed-rank
!PORTABILITY: CONTIGUOUS entity 'e' should be an array pointer, assumed-shape, or assumed-rank
entry e() result(r2)
end
function fp()
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Semantics/resolve90.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Testing for pointer constant, along with :
! C751 A component shall not have both the ALLOCATABLE and POINTER attributes.
! C752 If the CONTIGUOUS attribute is specified, the component shall be an
Expand All @@ -12,7 +12,7 @@ subroutine s()
!ERROR: 'pointerallocatablefield' may not have both the POINTER and ALLOCATABLE attributes
real, pointer, allocatable :: pointerAllocatableField
real, dimension(:), contiguous, pointer :: goodContigField
!ERROR: CONTIGUOUS component 'badcontigfield' must be an array with the POINTER attribute
!PORTABILITY: CONTIGUOUS component 'badcontigfield' should be an array with the POINTER attribute
real, dimension(:), contiguous, allocatable :: badContigField
character :: charField * 3
!ERROR: A length specifier cannot be used to declare the non-character entity 'realfield'
Expand Down

0 comments on commit 9191738

Please sign in to comment.