Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/establish-errors-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 /* For simplicity, point descriptors at a static buffer. BUFSIZE should
10 be large enough for any of the standard types and we'll use DIM0 and DIM1
11 for array dimensions. */
12 #define BUFSIZE 64
13 #define DIM0 3
14 #define DIM1 10
15 #define ARRAYBUFSIZE BUFSIZE * DIM0 * DIM1
16 static char *buf[ARRAYBUFSIZE] __attribute__ ((aligned (8)));
17 static CFI_index_t extents[] = {DIM0, DIM1};
18
19 /* Magic number to use for elem_len field. */
20 #define MAGIC_ELEM_LEN 20
21
22
23 /* External entry point. */
24 extern void ctest (void);
25
26 void
27 ctest (void)
28 {
29 int bad = 0;
30 int status;
31 CFI_CDESC_T(2) desc;
32 CFI_cdesc_t *a = (CFI_cdesc_t *) &desc;
33
34 /* If the attribute argument is CFI_attribute_allocatable,
35 base_addr shall be a null pointer. */
36 status = CFI_establish (a, (void *)buf, CFI_attribute_allocatable,
37 CFI_type_int, 0, 2, extents);
38 if (status == CFI_SUCCESS)
39 {
40 fprintf (stderr,
41 "no error for non-null pointer with CFI_attribute_allocatable\n");
42 bad ++;
43 }
44
45 /* type shall have the value of one of the type codes in Table 18.4,
46 or have a positive value corresponding to an interoperable C type. */
47 status = CFI_establish (a, (void *)buf, CFI_attribute_other,
48 CFI_type_other - 1, 0, 2, extents);
49 if (status == CFI_SUCCESS)
50 {
51 fprintf (stderr,
52 "no error for invalid negative type code\n");
53 bad ++;
54 }
55
56 /* If the type is CFI_type_struct, CFI_type_other, or a Fortran
57 character type, elem_len shall be greater than zero and equal to
58 the storage size in bytes of an element of the object. */
59 status = CFI_establish (a, (void *)buf, CFI_attribute_other,
60 CFI_type_struct, 0, 2, extents);
61 if (status == CFI_SUCCESS)
62 {
63 fprintf (stderr,
64 "no error for invalid size with CFI_type_struct\n");
65 bad ++;
66 }
67
68 status = CFI_establish (a, (void *)buf, CFI_attribute_other,
69 CFI_type_char, 0, 2, extents);
70 if (status == CFI_SUCCESS)
71 {
72 fprintf (stderr,
73 "no error for invalid size with CFI_type_char\n");
74 bad ++;
75 }
76
77 /* Rank shall be between 0 and CFI_MAX_RANK inclusive. */
78 status = CFI_establish (a, NULL, CFI_attribute_allocatable,
79 CFI_type_int, 0, -1, extents);
80 if (status == CFI_SUCCESS)
81 {
82 fprintf (stderr,
83 "no error for negative rank\n");
84 bad ++;
85 }
86 status = CFI_establish (a, NULL, CFI_attribute_allocatable,
87 CFI_type_int, 0, CFI_MAX_RANK + 1, extents);
88 if (status == CFI_SUCCESS)
89 {
90 fprintf (stderr,
91 "no error for rank > CFI_MAX_RANK\n");
92 bad ++;
93 }
94
95 /* extents is ignored if the rank r is zero or if base_addr is a
96 null pointer. Otherwise, it shall be the address of an array... */
97 status = CFI_establish (a, (void *)buf, CFI_attribute_other,
98 CFI_type_int, 0, 2, NULL);
99 if (status == CFI_SUCCESS)
100 {
101 fprintf (stderr,
102 "no error for null extents\n");
103 bad ++;
104 }
105
106 /* Extents shall all be nonnegative. */
107 extents[1] = -extents[1];
108 status = CFI_establish (a, (void *)buf, CFI_attribute_other,
109 CFI_type_int, 0, 2, extents);
110 if (status == CFI_SUCCESS)
111 {
112 fprintf (stderr,
113 "no error for negative extents\n");
114 bad ++;
115 }
116
117 if (bad)
118 abort ();
119 }
120