196 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic2! Error tests for structure constructors: C1594 violations3! from assigning globally-visible data to POINTER components.4! This test is structconst03.f90 with the type parameters removed.5 6module usefrom7 real, target :: usedfrom18end module usefrom9 10module module111 use usefrom12 implicit none13 type :: has_pointer114 real, pointer :: ptop15 type(has_pointer1), allocatable :: link1 ! don't loop during analysis16 end type has_pointer117 type :: has_pointer218 type(has_pointer1) :: pnested19 type(has_pointer2), allocatable :: link220 end type has_pointer221 type, extends(has_pointer2) :: has_pointer322 type(has_pointer3), allocatable :: link323 end type has_pointer324 type :: t125 real, pointer :: pt126 type(t1), allocatable :: link27 end type t128 type :: t229 type(has_pointer1) :: hp130 type(t2), allocatable :: link31 end type t232 type :: t333 type(has_pointer2) :: hp234 type(t3), allocatable :: link35 end type t336 type :: t437 type(has_pointer3) :: hp338 type(t4), allocatable :: link39 end type t440 real, target :: modulevar1 = 0.41 type(has_pointer1) :: modulevar2 = has_pointer1(modulevar1)42 type(has_pointer2) :: modulevar3 = has_pointer2(has_pointer1(modulevar1))43 type(has_pointer3) :: modulevar4 = has_pointer3(has_pointer1(modulevar1))44 45 contains46 47 pure subroutine ps1(dummy1, dummy2, dummy3, dummy4, co2, co3, co4)48 real, target :: local149 type(t1) :: x150 type(t2) :: x251 type(t3) :: x352 type(t4) :: x453 real, intent(in), target :: dummy154 real, intent(inout), target :: dummy255 real, pointer :: dummy356 real, intent(inout), target :: dummy4[*]57 real, target :: commonvar158 common /cblock/ commonvar159 type(has_pointer1), intent(in out) :: co2[*]60 type(has_pointer2), intent(in out) :: co3[*]61 type(has_pointer3), intent(in out) :: co4[*]62 x1 = t1(local1)63 !ERROR: Externally visible object 'usedfrom1' may not be associated with pointer component 'pt1' in a pure procedure64 x1 = t1(usedfrom1)65 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'pt1' in a pure procedure66 x1 = t1(modulevar1)67 !ERROR: Externally visible object 'cblock' may not be associated with pointer component 'pt1' in a pure procedure68 x1 = t1(commonvar1)69 !ERROR: Externally visible object 'dummy1' may not be associated with pointer component 'pt1' in a pure procedure70 x1 = t1(dummy1)71 x1 = t1(dummy2)72 x1 = t1(dummy3)73! TODO when semantics handles coindexing:74! TODO !ERROR: Externally visible object may not be associated with a pointer in a pure procedure75! TODO x1 = t1(dummy4[0])76 x1 = t1(dummy4)77 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure78 x2 = t2(has_pointer1(modulevar1))79 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure80 x3 = t3(has_pointer2(has_pointer1(modulevar1)))81 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure82 x4 = t4(has_pointer3(has_pointer1(modulevar1)))83 !ERROR: The externally visible object 'modulevar2' may not be used in a pure procedure as the value for component 'hp1' which has the pointer component '%ptop'84 x2 = t2(modulevar2)85 !ERROR: The externally visible object 'modulevar3' may not be used in a pure procedure as the value for component 'hp2' which has the pointer component '%pnested%ptop'86 x3 = t3(modulevar3)87 !ERROR: The externally visible object 'modulevar4' may not be used in a pure procedure as the value for component 'hp3' which has the pointer component '%has_pointer2%pnested%ptop'88 x4 = t4(modulevar4)89 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp1' which has the pointer component '%ptop'90 x2 = t2(co2[1])91 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp2' which has the pointer component '%pnested%ptop'92 x3 = t3(co3[1])93 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp3' which has the pointer component '%has_pointer2%pnested%ptop'94 x4 = t4(co4[1])95 contains96 pure subroutine subr(dummy1a, dummy2a, dummy3a, dummy4a, co2a, co3a, co4a)97 real, target :: local1a98 type(t1) :: x1a99 type(t2) :: x2a100 type(t3) :: x3a101 type(t4) :: x4a102 real, intent(in), target :: dummy1a103 real, intent(inout), target :: dummy2a104 real, pointer :: dummy3a105 real, intent(inout), target :: dummy4a[*]106 type(has_pointer1), intent(in out) :: co2a[*]107 type(has_pointer2), intent(in out) :: co3a[*]108 type(has_pointer3), intent(in out) :: co4a[*]109 x1a = t1(local1a)110 !ERROR: Externally visible object 'usedfrom1' may not be associated with pointer component 'pt1' in a pure procedure111 x1a = t1(usedfrom1)112 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'pt1' in a pure procedure113 x1a = t1(modulevar1)114 !ERROR: Externally visible object 'commonvar1' may not be associated with pointer component 'pt1' in a pure procedure115 x1a = t1(commonvar1)116 !ERROR: Externally visible object 'dummy1' may not be associated with pointer component 'pt1' in a pure procedure117 x1a = t1(dummy1)118 !ERROR: Externally visible object 'dummy1a' may not be associated with pointer component 'pt1' in a pure procedure119 x1a = t1(dummy1a)120 x1a = t1(dummy2a)121 x1a = t1(dummy3)122 x1a = t1(dummy3a)123! TODO when semantics handles coindexing:124! TODO !ERROR: Externally visible object may not be associated with a pointer in a pure procedure125! TODO x1a = t1(dummy4a[0])126 x1a = t1(dummy4a)127 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure128 x2a = t2(has_pointer1(modulevar1))129 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure130 x3a = t3(has_pointer2(has_pointer1(modulevar1)))131 !ERROR: Externally visible object 'modulevar1' may not be associated with pointer component 'ptop' in a pure procedure132 x4a = t4(has_pointer3(has_pointer1(modulevar1)))133 !ERROR: The externally visible object 'modulevar2' may not be used in a pure procedure as the value for component 'hp1' which has the pointer component '%ptop'134 x2a = t2(modulevar2)135 !ERROR: The externally visible object 'modulevar3' may not be used in a pure procedure as the value for component 'hp2' which has the pointer component '%pnested%ptop'136 x3a = t3(modulevar3)137 !ERROR: The externally visible object 'modulevar4' may not be used in a pure procedure as the value for component 'hp3' which has the pointer component '%has_pointer2%pnested%ptop'138 x4a = t4(modulevar4)139 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp1' which has the pointer component '%ptop'140 x2a = t2(co2a[1])141 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp2' which has the pointer component '%pnested%ptop'142 x3a = t3(co3a[1])143 !ERROR: A coindexed object may not be used in a pure procedure as the value for component 'hp3' which has the pointer component '%has_pointer2%pnested%ptop'144 x4a = t4(co4a[1])145 end subroutine subr146 end subroutine147 148 pure integer function pf1(dummy3)149 real, pointer :: dummy3150 type(t1) :: x1151 !ERROR: Externally visible object 'dummy3' may not be associated with pointer component 'pt1' in a pure procedure152 x1 = t1(dummy3)153 contains154 pure subroutine subr(dummy3a)155 real, pointer :: dummy3a156 type(t1) :: x1a157 !ERROR: Externally visible object 'dummy3' may not be associated with pointer component 'pt1' in a pure procedure158 x1a = t1(dummy3)159 x1a = t1(dummy3a)160 end subroutine161 end function162 163 impure real function ipf1(dummy1, dummy2, dummy3, dummy4)164 real, target :: local1165 type(t1) :: x1166 type(t2) :: x2167 type(t3) :: x3168 type(t4) :: x4169 real, intent(in), target :: dummy1170 real, intent(inout), target :: dummy2171 real, pointer :: dummy3172 real, intent(inout), target :: dummy4[*]173 real, target :: commonvar1174 common /cblock/ commonvar1175 ipf1 = 0.176 x1 = t1(local1)177 x1 = t1(usedfrom1)178 x1 = t1(modulevar1)179 x1 = t1(commonvar1)180 !WARNING: Pointer target is not a definable variable [-Wpointer-to-undefinable]181 !BECAUSE: 'dummy1' is an INTENT(IN) dummy argument182 x1 = t1(dummy1)183 x1 = t1(dummy2)184 x1 = t1(dummy3)185! TODO when semantics handles coindexing:186! TODO x1 = t1(dummy4[0])187 x1 = t1(dummy4)188 x2 = t2(has_pointer1(modulevar1))189 x3 = t3(has_pointer2(has_pointer1(modulevar1)))190 x4 = t4(has_pointer3(has_pointer1(modulevar1)))191 x2 = t2(modulevar2)192 x3 = t3(modulevar3)193 x4 = t4(modulevar4)194 end function ipf1195end module module1196