brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.1 KiB · 8aeb069 Raw
173 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Check for semantic errors in ALLOCATE statements3 4! TODO: Function Pointer in allocate and derived types!5 6! Rules I should know when working with coarrays and derived type:7 8! C736: If EXTENDS appears and the type being defined has a coarray ultimate9! component, its parent type shall have a coarray ultimate component.10 11! C746: (R737) If a coarray-spec appears, it shall be a deferred-coshape-spec-list12! and the component shall have the ALLOCATABLE attribute.13 14! C747: If a coarray-spec appears, the component shall not be of type C_PTR or15! C_FUNPTR from the intrinsic module ISO_C_BINDING (18.2), or of type TEAM_TYPE from the16! intrinsic module ISO_FORTRAN_ENV (16.10.2).17 18! C748: A data component whose type has a coarray ultimate component shall be a19! nonpointer nonallocatable scalar and shall not be a coarray.20 21! 7.5.4.3 Coarray components22! 7.5.6 Final subroutines: C78623 24 25! C825 An entity whose type has a coarray ultimate component shall be a26! nonpointer nonallocatable scalar, shall not be a coarray, and shall not be a function result.27 28! C826 A coarray or an object with a coarray ultimate component shall be an29! associate name, a dummy argument, or have the ALLOCATABLE or SAVE attribute.30 31subroutine C937(var)32! Type-spec shall not specify a type that has a coarray ultimate component.33 34 35  type A36    real, allocatable :: x[:]37  end type38 39  type B40    type(A) y41    !ERROR: Allocatable or array component 'forward' may not have a coarray ultimate component '%y%x'42    type(B), allocatable :: forward43    real :: u44  end type45 46  type B247    type(A) y48    !ERROR: Pointer 'forward' may not have a coarray potential component '%y%x'49    type(B), pointer :: forward50    real :: u51  end type52 53  type C54    type(B) z55  end type56 57  type D58    !ERROR: Allocatable or array component 'potential' may not have a coarray ultimate component '%x'59    type(A), allocatable :: potential60  end type61 62  type D263    !ERROR: Pointer 'potential' may not have a coarray potential component '%x'64    type(A), pointer :: potential65  end type66 67  class(*), allocatable :: var68  ! unlimited polymorphic is the ONLY way to get an allocatable/pointer 'var' that can be69  ! allocated with a type-spec T that has coarray ultimate component without70  ! violating other rules than C937.71  ! Rationale:72  !   C934 => var must be type compatible with T.73  !        => var type is T, a type P extended by T, or unlimited polymorphic74  !   C825 => var cannot be of type T.75  !   C736 => all parent types P of T must have a coarray ultimate component76  !        => var cannot be of type P (C825)77  !        => if var can be defined, it can only be unlimited polymorphic78 79  ! Also, as per C826 or C852, var can only be an allocatable, not a pointer80 81  ! OK, x is not an ultimate component82  allocate(D:: var)83 84  !ERROR: Type-spec in ALLOCATE must not specify a type with a coarray ultimate component85  allocate(A:: var)86  !ERROR: Type-spec in ALLOCATE must not specify a type with a coarray ultimate component87  allocate(B:: var)88  !ERROR: Type-spec in ALLOCATE must not specify a type with a coarray ultimate component89  allocate(C:: var)90end subroutine91 92!TODO: type extending team_type !? subcomponents !?93 94subroutine C938_C947(var2, ptr, ptr2, fptr, my_team, srca)95! If an allocate-object is a coarray, type-spec shall not specify type C_PTR or96! C_FUNPTR from the intrinsic module ISO_C_BINDING, or type TEAM_TYPE from the intrinsic module97! ISO_FORTRAN_ENV.98  use ISO_FORTRAN_ENV99  use ISO_C_BINDING100 101  type A(k, l)102    integer, kind :: k103    integer, len :: l104    real(kind=k) x(l,l)105  end type106 107! Again, I do not see any other way to violate this rule and not others without108! having var being an unlimited polymorphic.109! Suppose var of type P and T, the type in type-spec110! Per C934, P must be compatible with T. P cannot be a forbidden type per C824.111! Per C728 and 7.5.7.1, P cannot extend a c_ptr or _c_funptr. hence, P has to be112! unlimited polymorphic or a type that extends TEAM_TYPE.113  class(*), allocatable :: var[:], var2(:)[:]114  class(*), allocatable :: varok, varok2(:)115 116  Type(C_PTR) :: ptr, ptr2(2:10)117  Type(C_FUNPTR) fptr118  Type(TEAM_TYPE) my_team119  Type(A(4, 10)) :: srca120 121  ! Valid constructs122  allocate(real:: var[5:*])123  allocate(A(4, 10):: var[5:*])124  allocate(TEAM_TYPE:: varok, varok2(2))125  allocate(C_PTR:: varok, varok2(2))126  allocate(C_FUNPTR:: varok, varok2(2))127 128  !ERROR: Type-Spec in ALLOCATE must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray129  allocate(TEAM_TYPE:: var[5:*])130  !ERROR: Type-Spec in ALLOCATE must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray131  allocate(C_PTR:: varok, var[5:*])132  !ERROR: Type-Spec in ALLOCATE must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray133  allocate(C_FUNPTR:: var[5:*])134  !ERROR: Type-Spec in ALLOCATE must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray135  allocate(TEAM_TYPE:: var2(2)[5:*])136  !ERROR: Type-Spec in ALLOCATE must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray137  allocate(C_PTR:: var2(2)[5:*])138  !ERROR: Type-Spec in ALLOCATE must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray139  allocate(C_FUNPTR:: varok2(2), var2(2)[5:*])140 141 142! C947: The declared type of source-expr shall not be C_PTR or C_FUNPTR from the143! intrinsic module ISO_C_BINDING, or TEAM_TYPE from the intrinsic module144! ISO_FORTRAN_ENV, if an allocateobject is a coarray.145!146!  ! Valid constructs147  allocate(var[5:*], SOURCE=cos(0.5_4))148  allocate(var[5:*], MOLD=srca)149  allocate(varok, varok2(2), SOURCE=ptr)150  allocate(varok2, MOLD=ptr2)151  allocate(varok, varok2(2), SOURCE=my_team)152  allocate(varok, varok2(2), MOLD=fptr)153 154  !ERROR: SOURCE or MOLD expression type must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray155  allocate(var[5:*], SOURCE=my_team)156  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray157  allocate(var[5:*], SOURCE=ptr)158  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray159  allocate(varok, var[5:*], MOLD=ptr2(2))160  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray161  allocate(var[5:*], MOLD=fptr)162  !ERROR: SOURCE or MOLD expression type must not be TEAM_TYPE from ISO_FORTRAN_ENV when an allocatable object is a coarray163  allocate(var2(2)[5:*], MOLD=my_team)164  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray165  allocate(var2(2)[5:*], MOLD=ptr)166  !ERROR: Allocation has extent 2 on dimension 1, but SOURCE= has extent 9167  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray168  allocate(var2(2)[5:*], SOURCE=ptr2)169  !ERROR: SOURCE or MOLD expression type must not be C_PTR or C_FUNPTR from ISO_C_BINDING when an allocatable object is a coarray170  allocate(varok2(2), var2(2)[5:*], SOURCE=fptr)171 172end subroutine173