xref: /llvm-project/flang/test/Semantics/argshape01.f90 (revision e86591b37d4eb92ffca21b43b224d155ec688337)
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
2! Detect incompatible argument shapes
3module m
4  integer :: ha = 1
5 contains
6  subroutine s1(a)
7    real, intent(in) :: a(2,3)
8  end
9  subroutine s2(a)
10    real, intent(in) :: a(3,2)
11  end
12  subroutine s3(a)
13    real, intent(in) :: a(3,*)
14  end
15  subroutine s4(a)
16    real, intent(in) :: a(:,:)
17  end
18  subroutine s5(a)
19    real, intent(in) :: a(..)
20  end
21  subroutine s6(a,n,m)
22    integer, intent(in) :: n, m
23    real, intent(in) :: a(n, m)
24  end
25  subroutine s6b(a,nn,mm)
26    integer, intent(in) :: nn, mm
27    real, intent(in) :: a(nn, mm)
28  end
29  subroutine s7(a,n,m)
30    integer, intent(in) :: n, m
31    real, intent(in) :: a(m, n)
32  end
33  subroutine s8(a,n,m)
34    integer, intent(in) :: n, m
35    real, intent(in) :: a(n+1,m+1)
36  end
37  subroutine s8b(a,n,m)
38    integer, intent(in) :: n, m
39    real, intent(in) :: a(n-1,m+2)
40  end
41  subroutine s9(a)
42    real, intent(in) :: a(ha,ha)
43  end
44  subroutine s9b(a)
45    real, intent(in) :: a(ha,ha)
46  end
47  subroutine s1c(s)
48    procedure(s1) :: s
49  end
50  subroutine s2c(s)
51    procedure(s2) :: s
52  end
53  subroutine s3c(s)
54    procedure(s3) :: s
55  end
56  subroutine s4c(s)
57    procedure(s4) :: s
58  end
59  subroutine s5c(s)
60    procedure(s5) :: s
61  end
62  subroutine s6c(s)
63    procedure(s6) :: s
64  end
65  subroutine s7c(s)
66    procedure(s7) :: s
67  end
68  subroutine s8c(s)
69    procedure(s8) :: s
70  end
71  subroutine s9c(s)
72    procedure(s9) :: s
73  end
74end
75
76program main
77  use m
78  procedure(s1), pointer :: ps1
79  procedure(s2), pointer :: ps2
80  procedure(s3), pointer :: ps3
81  procedure(s4), pointer :: ps4
82  procedure(s5), pointer :: ps5
83  procedure(s6), pointer :: ps6
84  procedure(s7), pointer :: ps7
85  procedure(s8), pointer :: ps8
86  procedure(s9), pointer :: ps9
87  call s1c(s1)
88  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
89  call s1c(s2)
90  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
91  call s1c(s3)
92  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
93  call s1c(s4)
94  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
95  call s1c(s5)
96  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': distinct numbers of dummy arguments
97  call s1c(s6)
98  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
99  call s2c(s1)
100  call s2c(s2)
101  call s6c(s6)
102  call s6c(s6b)
103  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
104  call s6c(s7)
105  !WARNING: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
106  call s6c(s8)
107  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
108  call s7c(s6)
109  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
110  call s7c(s8)
111  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
112  call s8c(s6)
113  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
114  call s8c(s7)
115  call s8c(s8)
116  !WARNING: Actual procedure argument has possible interface incompatibility with dummy argument 's=': possibly incompatible dummy argument #1: distinct dummy data object shapes
117  call s8c(s8b)
118  call s9c(s9)
119  call s9c(s9b)
120  ps1 => s1
121  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's2': incompatible dummy argument #1: incompatible dummy data object shapes
122  ps1 => s2
123  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's3': incompatible dummy argument #1: incompatible dummy data object shapes
124  ps1 => s3
125  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's4': incompatible dummy argument #1: incompatible dummy data object shapes
126  ps1 => s4
127  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's5': incompatible dummy argument #1: incompatible dummy data object shapes
128  ps1 => s5
129  !ERROR: Procedure pointer 'ps1' associated with incompatible procedure designator 's6': distinct numbers of dummy arguments
130  ps1 => s6
131  !ERROR: Procedure pointer 'ps2' associated with incompatible procedure designator 's1': incompatible dummy argument #1: incompatible dummy data object shapes
132  ps2 => s1
133  ps2 => s2
134  call s1c(ps1)
135  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
136  call s1c(ps2)
137  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
138  call s1c(ps3)
139  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
140  call s1c(ps4)
141  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
142  call s1c(ps5)
143  !ERROR: Actual procedure argument has interface incompatible with dummy argument 's=': incompatible dummy argument #1: incompatible dummy data object shapes
144  call s2c(ps1)
145  call s2c(ps2)
146  ps6 => s6
147  ps6 => s6b
148  !ERROR: Procedure pointer 'ps6' associated with incompatible procedure designator 's7': incompatible dummy argument #1: incompatible dummy data object shapes
149  ps6 => s7
150  !ERROR: Procedure pointer 'ps6' associated with incompatible procedure designator 's8': incompatible dummy argument #1: incompatible dummy data object shapes
151  ps6 => s8
152  !ERROR: Procedure pointer 'ps7' associated with incompatible procedure designator 's6': incompatible dummy argument #1: incompatible dummy data object shapes
153  ps7 => s6
154  !ERROR: Procedure pointer 'ps7' associated with incompatible procedure designator 's8': incompatible dummy argument #1: incompatible dummy data object shapes
155  ps7 => s8
156  ps8 => s8
157  !WARNING: pointer 'ps8' and s8b may not be completely compatible procedures: possibly incompatible dummy argument #1: distinct dummy data object shapes
158  ps8 => s8b
159  !ERROR: Procedure pointer 'ps8' associated with incompatible procedure designator 's6': incompatible dummy argument #1: incompatible dummy data object shapes
160  ps8 => s6
161  !WARNING: Procedure pointer 'ps8' associated with incompatible procedure designator 's7': incompatible dummy argument #1: incompatible dummy data object shapes
162  ps8 => s7
163end
164