159 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Check for semantic errors in ALLOCATE statements3 4!TODO: mixing expr and source-expr?5!TODO: using subcomponent in source expressions6 7subroutine C939_C942a_C945b(xsrc1a, xsrc1c, xsrc0, xsrc2a, xsrc2c, pos)8! C939: If an allocate-object is an array, either allocate-shape-spec-list shall9! appear in its allocation, or source-expr shall appear in the ALLOCATE10! statement and have the same rank as the allocate-object.11 type A12 real, pointer :: x(:)13 end type14 real, allocatable :: x015 real, allocatable :: x1(:)16 real, pointer :: x2(:, :, :)17 type(A) a118 type(A), allocatable :: a2(:, :)19 20 real xsrc021 real xsrc1a(*)22 real xsrc1b(2:7)23 real, pointer :: xsrc1c(:)24 real xsrc2a(4:8, 12, *)25 real xsrc2b(2:7, 5, 9)26 real, pointer :: xsrc2c(:, :, :)27 integer pos28 29 allocate(x1(5))30 allocate(x1(2:7))31 allocate(x1, SOURCE=xsrc1a(2:7))32 allocate(x1, MOLD=xsrc1b)33 allocate(x1, SOURCE=xsrc1c)34 35 allocate(x2(2,3,4))36 allocate(x2(2:7,3:8,4:9))37 allocate(x2, SOURCE=xsrc2a(4:8, 1:12, 2:5))38 allocate(x2, MOLD=cos(xsrc2b))39 allocate(x2, SOURCE=xsrc2c)40 41 allocate(x1(5), x2(2,3,4), a1%x(5), a2(1,2)%x(4))42 allocate(x1, a1%x, a2(1,2)%x, SOURCE=xsrc1a(2:7))43 allocate(x1, a1%x, a2(1,2)%x, MOLD=xsrc1b)44 allocate(x1, a1%x, a2(1,2)%x, SOURCE=xsrc1c)45 46 allocate(x0, x1(5), x2(2,3,4), a1%x(5), SOURCE=xsrc0)47 48 ! There are NO requirements that mold expression rank match the49 ! allocated-objects when allocate-shape-spec-lists are given.50 ! If it is not needed, the shape of MOLD should be simply ignored.51 allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc0)52 allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc1b)53 allocate(x0, x1(5), x2(2,3,4), a1%x(5), MOLD=xsrc2b)54 55 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD56 allocate(x1)57 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD58 allocate(x1, SOURCE=xsrc0)59 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD60 allocate(x1, MOLD=xsrc2c)61 62 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD63 allocate(x2, SOURCE=xsrc1a(2:7))64 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD65 allocate(x2, MOLD=xsrc1b)66 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD67 allocate(x2, SOURCE=xsrc1c)68 69 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD70 allocate(a1%x)71 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD72 allocate(a2(5,3)%x)73 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD74 allocate(x1(5), x2(2,3,4), a1%x, a2(1,2)%x(4))75 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD76 allocate(x2, a2(1,2)%x, SOURCE=xsrc2a(4:8, 1:12, 2:5))77 !ERROR: Arrays in ALLOCATE must have a shape specification or an expression of the same rank must appear in SOURCE or MOLD78 allocate(a1%x, MOLD=xsrc0)79 80 !C942a: The number of allocate-shape-specs in an allocate-shape-spec-list shall81 !be the same as the rank of the allocate-object. [...] (co-array stuffs).82 83 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object84 allocate(x1(5, 5))85 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object86 allocate(x1(2:3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2))87 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object88 allocate(x2(pos))89 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object90 allocate(x2(2, 3, pos+1, 5))91 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object92 allocate(x1(5), x2(2,4), a1%x(5), a2(1,2)%x(4))93 94 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object95 allocate(x1(2), a1%x(2,5), a2(1,2)%x(2))96 97 ! Test the check is not influenced by SOURCE98 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object99 allocate(a1%x(5, 4, 3), SOURCE=xsrc2a(4:8, 1:4, 1:3))100 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object101 allocate(x2(5), MOLD=xsrc1a(1:5))102 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object103 allocate(a1%x(5, 4, 3), MOLD=xsrc1b)104 !ERROR: The number of shape specifications, when they appear, must match the rank of allocatable object105 allocate(x2(5), SOURCE=xsrc2b)106 107 ! C945b: If SOURCE= appears, source-expr shall be a scalar or have the same108 ! rank as each allocate-object.109 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE110 allocate(x0, SOURCE=xsrc1b)111 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE112 allocate(x2(2, 5, 7), SOURCE=xsrc1a(2:7))113 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE114 allocate(x2(2, 5, 7), SOURCE=xsrc1c)115 116 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE117 allocate(x1(5), SOURCE=xsrc2a(4:8, 1:12, 2:5))118 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE119 allocate(x1(3), SOURCE=cos(xsrc2b))120 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE121 allocate(x1(100), SOURCE=xsrc2c)122 123 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE124 allocate(a1%x(10), x2(20, 30, 40), a2(1,2)%x(50), SOURCE=xsrc1c)125 !ERROR: If SOURCE appears, the related expression must be scalar or have the same rank as each allocatable object in ALLOCATE126 allocate(a1%x(25), SOURCE=xsrc2b)127 128end subroutine129 130subroutine C940(a1, pos)131! If allocate-object is scalar, allocate-shape-spec-list shall not appear.132 type A133 integer(kind=8), allocatable :: i134 end type135 136 type B(k, l1, l2, l3)137 integer, kind :: k138 integer, len :: l1, l2, l3139 real(kind=k) x(-1:l1, 0:l2, 1:l3)140 end type141 142 integer pos143 class(A), allocatable :: a1(:)144 real, pointer :: x145 type(B(8,4,5,6)), allocatable :: b1146 147 ! Nominal148 allocate(x)149 allocate(a1(pos)%i)150 allocate(b1)151 152 !ERROR: Shape specifications must not appear when allocatable object is scalar153 allocate(x(pos))154 !ERROR: Shape specifications must not appear when allocatable object is scalar155 allocate(a1(pos)%i(5:2))156 !ERROR: Shape specifications must not appear when allocatable object is scalar157 allocate(b1(1))158end subroutine159