1 #include <ISO_Fortran_binding.h>
9 typedef struct loc_t (*ftn_fn
) (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
10 struct loc_t
char_assumed_size_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
11 struct loc_t
char_assumed_size_in_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
12 struct loc_t
char_expl_size_f (CFI_cdesc_t
*,CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
13 struct loc_t
char_expl_size_in_f (CFI_cdesc_t
*,CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
14 struct loc_t
char_assumed_rank_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
15 struct loc_t
char_assumed_rank_in_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
16 struct loc_t
char_assumed_rank_cont_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
17 struct loc_t
char_assumed_rank_cont_in_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
18 struct loc_t
char_assumed_shape_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
19 struct loc_t
char_assumed_shape_in_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
20 struct loc_t
char_assumed_shape_cont_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
21 struct loc_t
char_assumed_shape_cont_in_f (CFI_cdesc_t
*, CFI_cdesc_t
*, CFI_cdesc_t
*, int, int);
24 basic_check(CFI_cdesc_t
*x
, bool is_cont
)
28 if (x
->elem_len
!= 3*sizeof(char))
30 if (x
->version
!= CFI_VERSION
)
34 if (x
->attribute
!= CFI_attribute_other
)
36 if (x
->type
!= CFI_type_char
)
38 if (x
->dim
[0].lower_bound
!= 0)
40 if (x
->dim
[0].extent
!= 3)
42 if (CFI_is_contiguous (x
) != (x
->elem_len
== x
->dim
[0].sm
))
44 if (is_cont
!= CFI_is_contiguous (x
))
49 print_str (void *p
, size_t len
)
51 __builtin_printf ("DEBUG: >");
52 for (size_t i
= 0; i
< len
; ++i
)
53 __builtin_printf ("%c", ((const char*) p
)[i
]);
54 __builtin_printf ("<\n");
58 check_str (CFI_cdesc_t
*x
, const char *str
, const CFI_index_t subscripts
[])
60 /* Avoid checking for '\0'. */
61 if (strncmp ((const char*) CFI_address (x
, subscripts
), str
, strlen(str
)) != 0)
66 set_str (CFI_cdesc_t
*x
, const char *str
, const CFI_index_t subscripts
[])
68 char *p
= CFI_address (x
, subscripts
);
69 size_t len
= strlen (str
);
70 if (x
->elem_len
!= len
)
72 for (size_t i
= 0; i
< len
; ++i
)
77 do_call (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
78 int k
, int num
, bool intent_in
, ftn_fn fn
, bool is_cont
, bool fort_cont
)
80 const CFI_index_t zero
[1] = { 0 };
81 const CFI_index_t one
[1] = { 1 };
82 const CFI_index_t two
[1] = { 2 };
83 struct loc_t addr1
, addr2
;
95 addr2
= fn (x
, y
, z
, 3, num
);
96 if (addr2
.x
!= -1 || addr2
.y
!= -1 || addr2
.z
!= -1)
106 basic_check (x
, is_cont
|| num
== 2);
107 basic_check (y
, is_cont
|| num
== 2);
108 basic_check (z
, is_cont
|| num
== 2);
109 if (!is_cont
&& num
== 1)
111 check_str (x
, "abc", zero
);
112 check_str (x
, "ghi", one
);
113 check_str (x
, "nop", two
);
114 check_str (y
, "abc", zero
);
115 check_str (y
, "ghi", one
);
116 check_str (y
, "nop", two
);
117 check_str (z
, "abc", zero
);
118 check_str (z
, "ghi", one
);
119 check_str (z
, "nop", two
);
123 if (strncmp ((const char*) x
->base_addr
, "abcghinop", 9) != 0)
125 if (strncmp ((const char*) y
->base_addr
, "abcghinop", 9) != 0)
127 if (strncmp ((const char*) z
->base_addr
, "abcghinop", 9) != 0)
132 if (strncmp ((const char*) x
->base_addr
, "defghijlm", 9) != 0)
134 if (strncmp ((const char*) y
->base_addr
, "defghijlm", 9) != 0)
136 if (strncmp ((const char*) z
->base_addr
, "defghijlm", 9) != 0)
141 addr1
.x
= (intptr_t) x
->base_addr
;
142 addr1
.y
= (intptr_t) y
->base_addr
;
143 addr1
.z
= (intptr_t) z
->base_addr
;
144 addr2
= fn (x
, y
, z
, 3, num
);
145 if (!CFI_is_contiguous (x
) && fort_cont
)
147 /* Check for callee copy in/copy out. */
148 if (addr1
.x
== addr2
.x
|| addr1
.x
!= (intptr_t) x
->base_addr
)
150 if (addr1
.y
== addr2
.y
|| addr1
.y
!= (intptr_t) y
->base_addr
)
152 if (addr1
.z
== addr2
.z
|| addr1
.z
!= (intptr_t) z
->base_addr
)
157 if (addr1
.x
!= addr2
.x
|| addr1
.x
!= (intptr_t) x
->base_addr
)
159 if (addr1
.y
!= addr2
.y
|| addr1
.y
!= (intptr_t) y
->base_addr
)
161 if (addr1
.z
!= addr2
.z
|| addr1
.z
!= (intptr_t) z
->base_addr
)
165 if (intent_in
&& !is_cont
&& num
== 1)
167 check_str (x
, "abc", zero
);
168 check_str (x
, "ghi", one
);
169 check_str (x
, "nop", two
);
170 check_str (y
, "abc", zero
);
171 check_str (y
, "ghi", one
);
172 check_str (y
, "nop", two
);
173 check_str (z
, "abc", zero
);
174 check_str (z
, "ghi", one
);
175 check_str (z
, "nop", two
);
177 else if (intent_in
&& num
== 1)
179 if (strncmp ((const char*) x
->base_addr
, "abcghinop", 9) != 0)
181 if (strncmp ((const char*) y
->base_addr
, "abcghinop", 9) != 0)
183 if (strncmp ((const char*) z
->base_addr
, "abcghinop", 9) != 0)
186 else if (intent_in
&& num
== 2)
188 if (strncmp ((const char*) x
->base_addr
, "defghijlm", 9) != 0)
190 if (strncmp ((const char*) y
->base_addr
, "defghijlm", 9) != 0)
192 if (strncmp ((const char*) z
->base_addr
, "defghijlm", 9) != 0)
199 if (is_cont
&& num
== 1)
201 /* Copy in - set the value to check that no copy out is done. */
202 memcpy ((char*) x
->base_addr
, "123456789", 9);
203 memcpy ((char*) y
->base_addr
, "123456789", 9);
204 memcpy ((char*) z
->base_addr
, "123456789", 9);
209 if (!is_cont
&& num
== 1)
211 check_str (x
, "ABC", zero
);
212 check_str (x
, "DEF", one
);
213 check_str (x
, "GHI", two
);
214 check_str (y
, "ABC", zero
);
215 check_str (y
, "DEF", one
);
216 check_str (y
, "GHI", two
);
217 check_str (z
, "ABC", zero
);
218 check_str (z
, "DEF", one
);
219 check_str (z
, "GHI", two
);
223 if (strncmp ((const char*) x
->base_addr
, "ABCDEFGHI", 9) != 0)
225 if (strncmp ((const char*) y
->base_addr
, "ABCDEFGHI", 9) != 0)
227 if (strncmp ((const char*) z
->base_addr
, "ABCDEFGHI", 9) != 0)
234 char_assumed_size_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
237 return do_call (x
, y
, z
, k
, num
, false, char_assumed_size_f
, true, false);
241 char_assumed_size_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
244 return do_call (x
, y
, z
, k
, num
, true, char_assumed_size_in_f
, true, false);
248 char_expl_size_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
251 return do_call (x
, y
, z
, k
, num
, false, char_expl_size_f
, true, false);
255 char_expl_size_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
258 return do_call (x
, y
, z
, k
, num
, true, char_expl_size_in_f
, true, false);
262 char_assumed_rank_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
265 return do_call (x
, y
, z
, k
, num
, false, char_assumed_rank_f
, false, false);
269 char_assumed_rank_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
272 return do_call (x
, y
, z
, k
, num
, true, char_assumed_rank_in_f
, false, false);
276 char_assumed_rank_cont_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
279 return do_call (x
, y
, z
, k
, num
, false, char_assumed_rank_cont_f
, true, false);
283 char_assumed_rank_cont_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
286 return do_call (x
, y
, z
, k
, num
, true, char_assumed_rank_cont_in_f
, true, false);
290 reset_var (CFI_cdesc_t
*x
, int num
)
292 const CFI_index_t zero
[1] = { 0 };
293 const CFI_index_t one
[1] = { 1 };
294 const CFI_index_t two
[1] = { 2 };
298 set_str (x
, "abc", zero
);
299 set_str (x
, "ghi", one
);
300 set_str (x
, "nop", two
);
304 set_str (x
, "def", zero
);
305 set_str (x
, "ghi", one
);
306 set_str (x
, "jlm", two
);
318 reset_vars (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
, int num
)
326 char_assumed_shape_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
329 /* Make use of having a noncontiguous argument to check that the callee
330 handles noncontiguous variables. */
331 do_call (x
, y
, z
, k
, num
, false, char_assumed_size_f
, false, true);
332 reset_vars (x
, y
, z
, num
);
333 do_call (x
, y
, z
, k
, num
, true, char_assumed_size_in_f
, false, true);
334 reset_vars (x
, y
, z
, num
);
335 do_call (x
, y
, z
, k
, num
, false, char_expl_size_f
, false, true);
336 reset_vars (x
, y
, z
, num
);
337 do_call (x
, y
, z
, k
, num
, true, char_expl_size_in_f
, false, true);
338 reset_vars (x
, y
, z
, num
);
339 do_call (x
, y
, z
, k
, num
, false, char_assumed_rank_cont_f
, false, true);
340 reset_vars (x
, y
, z
, num
);
341 do_call (x
, y
, z
, k
, num
, true, char_assumed_rank_cont_in_f
, false, true);
342 reset_vars (x
, y
, z
, num
);
343 do_call (x
, y
, z
, k
, num
, false, char_assumed_shape_cont_f
, false, true);
344 reset_vars (x
, y
, z
, num
);
345 do_call (x
, y
, z
, k
, num
, true, char_assumed_shape_cont_in_f
, false, true);
346 /* Actual func call. */
347 reset_vars (x
, y
, z
, num
);
348 return do_call (x
, y
, z
, k
, num
, false, char_assumed_shape_f
, false, false);
352 char_assumed_shape_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
355 return do_call (x
, y
, z
, k
, num
, true, char_assumed_shape_in_f
, false, false);
359 char_assumed_shape_cont_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
362 return do_call (x
, y
, z
, k
, num
, false, char_assumed_shape_cont_f
, true, false);
366 char_assumed_shape_cont_in_c (CFI_cdesc_t
*x
, CFI_cdesc_t
*y
, CFI_cdesc_t
*z
,
369 return do_call (x
, y
, z
, k
, num
, true, char_assumed_shape_cont_in_f
, true, false);