Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/setpointer-c.c

raw
1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 #include <ISO_Fortran_binding.h>
7 #include "dump-descriptors.h"
8
9 static int a[10][5][3];
10 static CFI_index_t extents[] = {3, 5, 10};
11 static CFI_index_t lb1[] = {1, 2, 3};
12 static CFI_index_t lb2[] = {0, 1, -10};
13
14 /* External entry point. */
15 extern void ctest (void);
16
17 void
18 ctest (void)
19 {
20 CFI_CDESC_T(3) sdesc;
21 CFI_cdesc_t *source = (CFI_cdesc_t *) &sdesc;
22 CFI_CDESC_T(3) rdesc;
23 CFI_cdesc_t *result = (CFI_cdesc_t *) &rdesc;
24
25 /* Create descriptors. */
26 check_CFI_status ("CFI_establish",
27 CFI_establish (source, (void *)a, CFI_attribute_pointer,
28 CFI_type_int, 0, 3, extents));
29 check_CFI_status ("CFI_establish",
30 CFI_establish (result, NULL, CFI_attribute_pointer,
31 CFI_type_int, 0, 3, NULL));
32
33 /* Use setpointer to adjust the bounds of source in place. */
34 check_CFI_status ("CFI_setpointer",
35 CFI_setpointer (source, source, lb1));
36 dump_CFI_cdesc_t (source);
37 if (source->dim[0].lower_bound != lb1[0])
38 abort ();
39 if (source->dim[1].lower_bound != lb1[1])
40 abort ();
41 if (source->dim[2].lower_bound != lb1[2])
42 abort ();
43
44 /* Use setpointer to copy the pointer and bounds from source. */
45 check_CFI_status ("CFI_setpointer",
46 CFI_setpointer (result, source, NULL));
47 dump_CFI_cdesc_t (result);
48 if (result->base_addr != source->base_addr)
49 abort ();
50 if (result->dim[0].lower_bound != source->dim[0].lower_bound)
51 abort ();
52 if (result->dim[1].lower_bound != source->dim[1].lower_bound)
53 abort ();
54 if (result->dim[2].lower_bound != source->dim[2].lower_bound)
55 abort ();
56
57 /* Use setpointer to nullify result. */
58 check_CFI_status ("CFI_setpointer",
59 CFI_setpointer (result, NULL, NULL));
60 dump_CFI_cdesc_t (result);
61 if (result->base_addr)
62 abort ();
63
64 /* Use setpointer to copy the pointer from source, but use
65 different bounds. */
66 check_CFI_status ("CFI_setpointer",
67 CFI_setpointer (result, source, lb2));
68 dump_CFI_cdesc_t (source);
69 if (result->base_addr != source->base_addr)
70 abort ();
71 if (result->dim[0].lower_bound != lb2[0])
72 abort ();
73 if (result->dim[1].lower_bound != lb2[1])
74 abort ();
75 if (result->dim[2].lower_bound != lb2[2])
76 abort ();
77 }
78