llvm-project/flang/test/Semantics/allocate10.f90

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
7.2 KiB
Fortran
Raw Normal View History

[flang] A rework of the cmake build components for in and out of tree builds. In general all the basic functionality seems to work and removes some redundancy and more complicated features in favor of borrowing infrastructure from LLVM build configurations. Here's a quick summary of details and remaining issues: * Testing has spanned Ubuntu 18.04 & 19.10, CentOS 7, RHEL 8, and MacOS/darwin. Architectures include x86_64 and Arm. Without access to Window nothing has been tested there yet. * As we change file and directory naming schemes (i.e., capitalization) some odd things can occur on MacOS systems with case preserving but not case senstive file system configurations. Can be painful and certainly something to watch out for as any any such changes continue. * Testing infrastructure still needs to be tuned up and worked on. Note that there do appear to be cases of some tests hanging (on MacOS in particular). They appear unrelated to the build process. * Shared library configurations need testing (and probably fixing). * Tested both standalone and 'in-mono repo' builds. Changes for supporting the mono repo builds will require LLVM-level changes that are straightforward when the time comes. * The configuration contains a work-around for LLVM's C++ standard mode passing down into Flang/F18 builds (i.e., LLVM CMake configuration would force a -std=c++11 flag to show up in command line arguments. The current configuration removes that automatically and is more strict in following new CMake guidelines for enforcing C++17 mode across all the CMake files. * Cleaned up a lot of repetition in the command line arguments. It is likely that more work is still needed to both allow for customization and working around CMake defailts (or those inherited from LLVM's configuration files). On some platforms agressive optimization flags (e.g. -O3) can actually break builds due to the inlining of templates in .cpp source files that then no longer are available for use cases outside those source files (shows up as link errors). Sticking at -O2 appears to fix this. Currently this CMake configuration forces this in release mode but at the cost of stomping on any CMake, or user customized, settings for the release flags. * Made the lit tests non-source directory dependent where appropriate. This is done by configuring certain test shell files to refer to the correct paths whether an in or out of tree build is being performed. These configured files are output in the build directory. A %B substitution is introduced in lit to refer to the build directory, mirroring the %S substitution for the source directory, so that the tests can refer to the configured shell scripts. Co-authored-by: David Truby <david.truby@arm.com> Original-commit: flang-compiler/f18@d1c7184159b2d3c542a8f36c58a0c817e7506845 Reviewed-on: https://github.com/flang-compiler/f18/pull/1045
2020-02-26 07:22:14 +08:00
! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
! Check for semantic errors in ALLOCATE statements
!TODO: mixing expr and source-expr?
!TODO: using subcomponent in source expressions
subroutine C939_C942a_C945b(xsrc1a, xsrc1c, xsrc0, xsrc2a, xsrc2c, pos)
! C939: If an allocate-object is an array, either allocate-shape-spec-list shall
! appear in its allocation, or source-expr shall appear in the ALLOCATE
! statement and have the same rank as the allocate-object.
type A
real, pointer :: x(:)
end type
real, allocatable :: x0
real, allocatable :: x1(:)
real, pointer :: x2(:, :, :)
type(A) a1
type(A), allocatable :: a2(:, :)
real xsrc0
real xsrc1a(*)
real xsrc1b(2:7)
real, pointer :: xsrc1c(:)
real xsrc2a(4:8, 12, *)
real xsrc2b(2:7, 5, 9)
real, pointer :: xsrc2c(:, :, :)
integer pos
allocate(x1(5))
allocate(x1(2:7))
allocate(x1, SOURCE=xsrc1a(2:7))
allocate(x1, MOLD=xsrc1b)
allocate(x1, SOURCE=xsrc1c)
allocate(x2(2,3,4))
allocate(x2(2:7,3:8,4:9))
allocate(x2, SOURCE=xsrc2a(4:8, 1:12, 2:5))
allocate(x2, MOLD=cos(xsrc2b))
allocate(x2, SOURCE=xsrc2c)
allocate(x1(5), x2(2,3,4), a1%x(5), a2(1,2)%x(4))
allocate(x1, a1%x, a2(1,2)%x, SOURCE=xsrc1a(2:7))
allocate(x1, a1%x, a2(1,2)%x, MOLD=xsrc1b)
allocate(x1, a1%x, a2(1,2)%x, SOURCE=xsrc1c)
allocate(x0, x1(5), x2(2,3,4), a1%x(5), SOURCE=xsrc0)
! There are NO requirements that mold expression rank match the
! allocated-objects when allocate-shape-spec-lists are given.
! If it is not needed, the shape of MOLD should be simply ignored.
allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc0)
allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc1b)
allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc2b)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x1)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x1, SOURCE=xsrc0)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x1, MOLD=xsrc2c)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x2, SOURCE=xsrc1a(2:7))
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x2, MOLD=xsrc1b)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x2, SOURCE=xsrc1c)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(a1%x)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(a2(5,3)%x)
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x1(5), x2(2,3,4), a1%x, a2(1,2)%x(4))
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(x2, a2(1,2)%x, SOURCE=xsrc2a(4:8, 1:12, 2:5))
!ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD
allocate(a1%x, MOLD=xsrc0)
!C942a: The number of allocate-shape-specs in an allocate-shape-spec-list shall
!be the same as the rank of the allocate-object. [...] (co-array stuffs).
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x1(5, 5))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x1(2:3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x2(pos))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x2(2, 3, pos+1, 5))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x1(5), x2(2,4), a1%x(5), a2(1,2)%x(4))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x1(2), a1%x(2,5), a2(1,2)%x(2))
! Test the check is not influenced by SOURCE
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(a1%x(5, 4, 3), SOURCE=xsrc2a(1:5, 1:4, 1:3))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x2(5), MOLD=xsrc1a(1:5))
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(a1%x(5, 4, 3), MOLD=xsrc1b)
!ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object
allocate(x2(5), SOURCE=xsrc2b)
! C945b: If SOURCE= appears, source-expr shall be a scalar or have the same
! rank as each allocate-object.
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x0, SOURCE=xsrc1b)
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x2(2, 5, 7), SOURCE=xsrc1a(2:7))
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x2(2, 5, 7), SOURCE=xsrc1c)
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x1(5), SOURCE=xsrc2a(4:8, 1:12, 2:5))
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x1(3), SOURCE=cos(xsrc2b))
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(x1(100), SOURCE=xsrc2c)
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(a1%x(10), x2(20, 30, 40), a2(1,2)%x(50), SOURCE=xsrc1c)
!ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE
allocate(a1%x(25), SOURCE=xsrc2b)
end subroutine
subroutine C940(a1, pos)
! If allocate-object is scalar, allocate-shape-spec-list shall not appear.
type A
integer(kind=8), allocatable :: i
end type
type B(k, l1, l2, l3)
integer, kind :: k
integer, len :: l1, l2, l3
real(kind=k) x(-1:l1, 0:l2, 1:l3)
end type
integer pos
class(A), allocatable :: a1(:)
real, pointer :: x
type(B(8,4,5,6)), allocatable :: b1
! Nominal
allocate(x)
allocate(a1(pos)%i)
allocate(b1)
!ERROR: Shape specifications must not appear when allocatable object is scalar
allocate(x(pos))
!ERROR: Shape specifications must not appear when allocatable object is scalar
allocate(a1(pos)%i(5:2))
!ERROR: Shape specifications must not appear when allocatable object is scalar
allocate(b1(1))
end subroutine