brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.5 KiB · c447078 Raw
253 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Pointer assignment constraints 10.2.2.23 4module m15  type :: t(k)6    integer, kind :: k7  end type8  type t29    sequence10    real :: t2Field11    real, pointer :: t2FieldPtr12  end type13  type t314    type(t2) :: t3Field15    type(t2), pointer :: t3FieldPtr16  end type17contains18 19  ! C85220  subroutine s021    !ERROR: 'p1' may not have both the POINTER and TARGET attributes22    real, pointer :: p1, p323    !ERROR: 'p2' may not have both the POINTER and ALLOCATABLE attributes24    allocatable :: p225    !ERROR: 'sin' may not have both the POINTER and INTRINSIC attributes26    real, intrinsic, pointer :: sin27    target :: p128    pointer :: p229    !ERROR: 'a' may not have the POINTER attribute because it is a coarray30    real, pointer :: a(:)[*]31  end32 33  ! C101534  subroutine s135    real, target :: r36    real(8), target :: r837    logical, target :: l38    real, pointer :: p39    p => r40    !ERROR: Target type REAL(8) is not compatible with pointer type REAL(4)41    p => r842    !ERROR: Target type LOGICAL(4) is not compatible with pointer type REAL(4)43    p => l44  end45 46  ! C101947  subroutine s248    real, target :: r1(4), r2(4,4)49    real, pointer :: p(:)50    p => r151    !ERROR: Pointer has rank 1 but target has rank 252    p => r253  end54 55  ! C101556  subroutine s357    type(t(1)), target :: x158    type(t(2)), target :: x259    type(t(1)), pointer :: p60    p => x161    !ERROR: Target type t(k=2_4) is not compatible with pointer type t(k=1_4)62    p => x263  end64 65  ! C101666  subroutine s4(x)67    class(*), target :: x68    type(t(1)), pointer :: p169    type(t2), pointer :: p270    class(*), pointer :: p371    real, pointer :: p472    p2 => x  ! OK - not extensible73    p3 => x  ! OK - unlimited polymorphic74    !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic75    p1 => x76    !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic77    p4 => x78  end79 80  ! C102081  subroutine s582    real, target, save :: x[*]83    real, target, volatile, save :: y[*]84    real, pointer :: p85    real, pointer, volatile :: q86    p => x87    !ERROR: Pointer must be VOLATILE when target is a VOLATILE coarray88    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]89    p => y90    !ERROR: Pointer may not be VOLATILE when target is a non-VOLATILE coarray91    q => x92    q => y93  end94 95  ! C1021, C102396  subroutine s697    real, target :: x98    real :: p99    type :: tp100      real, pointer :: a101      real :: b102    end type103    type(tp) :: y104    !ERROR: The left-hand side of a pointer assignment is not definable105    !BECAUSE: 'p' is not a pointer106    p => x107    y%a => x108    !ERROR: The left-hand side of a pointer assignment is not definable109    !BECAUSE: 'b' is not a pointer110    y%b => x111  end112 113  !C1025 (R1037) The expr shall be a designator that designates a114  !variable with either the TARGET or POINTER attribute and is not115  !an array section with a vector subscript, or it shall be a reference116  !to a function that returns a data pointer.117  subroutine s7118    real, target :: a119    real, pointer :: b120    real, pointer :: c121    real :: d122    b => a123    c => b124    !ERROR: In assignment to object pointer 'b', the target 'd' is not an object with POINTER or TARGET attributes125    b => d126  end127 128  ! C1025129  subroutine s8130    real :: a(10)131    integer :: b(10)132    real, pointer :: p(:)133    !ERROR: An array section with a vector subscript may not be a pointer target134    p => a(b)135  end136 137  ! C1025138  subroutine s9139    real, target :: x140    real, pointer :: p141    p => f1()142    !ERROR: pointer 'p' is associated with the result of a reference to function 'f2' that is not a pointer143    p => f2()144  contains145    function f1()146      real, pointer :: f1147      f1 => x148    end149    function f2()150      real :: f2151      f2 = x152    end153  end154 155  ! F'2023 C1029 A data-target shall not be a coindexed object.156  subroutine s10157    real, target, save :: a[*]158    real, pointer :: b159    !ERROR: A coindexed object may not be a pointer target160    b => a[1]161  end162 163  ! F'2023 C1027 the LHS may not be coindexed164  subroutine s11165    type t166      real, pointer :: p167    end type168    type(t), save :: ca[*]169    real, target :: x170    !ERROR: The left-hand side of a pointer assignment must not be coindexed171    ca[1]%p => x172  end173 174  subroutine s12175    real, volatile, target :: x176    real, pointer :: p177    real, pointer, volatile :: q178    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]179    p => x180    q => x181  end182 183  subroutine s13184    type(t3), target, volatile :: y = t3(t2(4.4))185    real, pointer :: p1186    type(t2), pointer :: p2187    type(t3), pointer :: p3188    real, pointer, volatile :: q1189    type(t2), pointer, volatile :: q2190    type(t3), pointer, volatile :: q3191    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]192    p1 => y%t3Field%t2Field193    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]194    p2 => y%t3Field195    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]196    p3 => y197    !OK:198    q1 => y%t3Field%t2Field199    !OK:200    q2 => y%t3Field201    !OK:202    q3 => y203    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]204    p3%t3FieldPtr => y%t3Field205    !ERROR: VOLATILE target associated with non-VOLATILE pointer [-Wnon-volatile-pointer-to-volatile]206    p3%t3FieldPtr%t2FieldPtr => y%t3Field%t2Field207    !OK208    q3%t3FieldPtr => y%t3Field209    !OK210    q3%t3FieldPtr%t2FieldPtr => y%t3Field%t2Field211  end212end213 214module m2215  type :: t1216    real :: a217  end type218  type :: t2219    type(t1) :: b220    type(t1), pointer :: c221    real :: d222  end type223end224 225subroutine s2226  use m2227  real, pointer :: p228  type(t2), target :: x229  type(t2) :: y230  !OK: x has TARGET attribute231  p => x%b%a232  !OK: c has POINTER attribute233  p => y%c%a234  !ERROR: In assignment to object pointer 'p', the target 'y%b%a' is not an object with POINTER or TARGET attributes235  p => y%b%a236  associate(z => x%b)237    !OK: x has TARGET attribute238    p => z%a239  end associate240  associate(z => y%c)241    !OK: c has POINTER attribute242    p => z%a243  end associate244  associate(z => y%b)245    !ERROR: In assignment to object pointer 'p', the target 'z%a' is not an object with POINTER or TARGET attributes246    p => z%a247  end associate248  associate(z => y%b%a)249    !ERROR: In assignment to object pointer 'p', the target 'z' is not an object with POINTER or TARGET attributes250    p => z251  end associate252end253