Skip gnat.dg/prot7.adb on hppa.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / alloc-8.c
blobbd4e08a6f9182a3116e1f59e3a5ca5fbbe625cc5
1 #include <omp.h>
2 #include <stdint.h>
3 #include <stdlib.h>
5 const omp_alloctrait_t traits2[]
6 = { { omp_atk_alignment, 16 },
7 { omp_atk_sync_hint, omp_atv_default },
8 { omp_atk_access, omp_atv_default },
9 { omp_atk_pool_size, 1024 },
10 { omp_atk_fallback, omp_atv_default_mem_fb },
11 { omp_atk_partition, omp_atv_environment } };
12 omp_alloctrait_t traits3[]
13 = { { omp_atk_sync_hint, omp_atv_uncontended },
14 { omp_atk_alignment, 32 },
15 { omp_atk_access, omp_atv_all },
16 { omp_atk_pool_size, 512 },
17 { omp_atk_fallback, omp_atv_allocator_fb },
18 { omp_atk_fb_data, 0 },
19 { omp_atk_partition, omp_atv_default } };
20 const omp_alloctrait_t traits4[]
21 = { { omp_atk_alignment, 128 },
22 { omp_atk_pool_size, 1024 },
23 { omp_atk_fallback, omp_atv_null_fb } };
25 int
26 main ()
28 int *volatile p = (int *) omp_aligned_calloc (sizeof (int), 3, sizeof (int), omp_default_mem_alloc);
29 int *volatile q;
30 int *volatile r;
31 int i;
32 omp_alloctrait_t traits[3]
33 = { { omp_atk_alignment, 64 },
34 { omp_atk_fallback, omp_atv_null_fb },
35 { omp_atk_pool_size, 4096 } };
36 omp_allocator_handle_t a, a2;
38 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0] || p[1] || p[2])
39 abort ();
40 p[0] = 1;
41 p[1] = 2;
42 p[2] = 3;
43 omp_free (p, omp_default_mem_alloc);
44 p = (int *) omp_aligned_calloc (2 * sizeof (int), 1, 2 * sizeof (int), omp_default_mem_alloc);
45 if ((((uintptr_t) p) % (2 * sizeof (int))) != 0 || p[0] || p[1])
46 abort ();
47 p[0] = 1;
48 p[1] = 2;
49 omp_free (p, omp_null_allocator);
50 omp_set_default_allocator (omp_default_mem_alloc);
51 p = (int *) omp_aligned_calloc (1, 1, sizeof (int), omp_null_allocator);
52 if ((((uintptr_t) p) % __alignof (int)) != 0 || p[0])
53 abort ();
54 p[0] = 3;
55 omp_free (p, omp_get_default_allocator ());
57 a = omp_init_allocator (omp_default_mem_space, 3, traits);
58 if (a == omp_null_allocator)
59 abort ();
60 p = (int *) omp_aligned_calloc (32, 3, 1024, a);
61 if ((((uintptr_t) p) % 64) != 0)
62 abort ();
63 for (i = 0; i < 3072 / sizeof (int); i++)
64 if (p[i])
65 abort ();
66 p[0] = 1;
67 p[3071 / sizeof (int)] = 2;
68 if (omp_aligned_calloc (8, 192, 16, a) != NULL)
69 abort ();
70 omp_free (p, a);
71 p = (int *) omp_aligned_calloc (128, 6, 512, a);
72 if ((((uintptr_t) p) % 128) != 0)
73 abort ();
74 for (i = 0; i < 3072 / sizeof (int); i++)
75 if (p[i])
76 abort ();
77 p[0] = 3;
78 p[3071 / sizeof (int)] = 4;
79 omp_free (p, omp_null_allocator);
80 omp_set_default_allocator (a);
81 if (omp_get_default_allocator () != a)
82 abort ();
83 p = (int *) omp_aligned_calloc (64, 12, 256, omp_null_allocator);
84 for (i = 0; i < 3072 / sizeof (int); i++)
85 if (p[i])
86 abort ();
87 if (omp_aligned_calloc (8, 128, 24, omp_null_allocator) != NULL)
88 abort ();
89 omp_free (p, a);
90 omp_destroy_allocator (a);
92 a = omp_init_allocator (omp_default_mem_space,
93 sizeof (traits2) / sizeof (traits2[0]),
94 traits2);
95 if (a == omp_null_allocator)
96 abort ();
97 if (traits3[5].key != omp_atk_fb_data)
98 abort ();
99 traits3[5].value = (uintptr_t) a;
100 a2 = omp_init_allocator (omp_default_mem_space,
101 sizeof (traits3) / sizeof (traits3[0]),
102 traits3);
103 if (a2 == omp_null_allocator)
104 abort ();
105 p = (int *) omp_aligned_calloc (4, 5, 84, a2);
106 for (i = 0; i < 420 / sizeof (int); i++)
107 if (p[i])
108 abort ();
109 if ((((uintptr_t) p) % 32) != 0)
110 abort ();
111 p[0] = 5;
112 p[419 / sizeof (int)] = 6;
113 q = (int *) omp_aligned_calloc (8, 24, 32, a2);
114 if ((((uintptr_t) q) % 16) != 0)
115 abort ();
116 for (i = 0; i < 768 / sizeof (int); i++)
117 if (q[i])
118 abort ();
119 q[0] = 7;
120 q[767 / sizeof (int)] = 8;
121 r = (int *) omp_aligned_calloc (8, 64, 8, a2);
122 if ((((uintptr_t) r) % 8) != 0)
123 abort ();
124 for (i = 0; i < 512 / sizeof (int); i++)
125 if (r[i])
126 abort ();
127 r[0] = 9;
128 r[511 / sizeof (int)] = 10;
129 omp_free (p, omp_null_allocator);
130 omp_free (q, a2);
131 omp_free (r, omp_null_allocator);
132 omp_destroy_allocator (a2);
133 omp_destroy_allocator (a);
135 a = omp_init_allocator (omp_default_mem_space,
136 sizeof (traits4) / sizeof (traits4[0]),
137 traits4);
138 if (a == omp_null_allocator)
139 abort ();
140 if (traits3[5].key != omp_atk_fb_data)
141 abort ();
142 traits3[5].value = (uintptr_t) a;
143 a2 = omp_init_allocator (omp_default_mem_space,
144 sizeof (traits3) / sizeof (traits3[0]),
145 traits3);
146 if (a2 == omp_null_allocator)
147 abort ();
148 omp_set_default_allocator (a2);
149 #ifdef __cplusplus
150 p = static_cast <int *> (omp_aligned_calloc (4, 21, 20));
151 #else
152 p = (int *) omp_aligned_calloc (4, 21, 20, omp_null_allocator);
153 #endif
154 if ((((uintptr_t) p) % 32) != 0)
155 abort ();
156 for (i = 0; i < 420 / sizeof (int); i++)
157 if (p[i])
158 abort ();
159 p[0] = 5;
160 p[419 / sizeof (int)] = 6;
161 q = (int *) omp_aligned_calloc (64, 12, 64, omp_null_allocator);
162 if ((((uintptr_t) q) % 128) != 0)
163 abort ();
164 for (i = 0; i < 768 / sizeof (int); i++)
165 if (q[i])
166 abort ();
167 q[0] = 7;
168 q[767 / sizeof (int)] = 8;
169 if (omp_aligned_calloc (8, 24, 32, omp_null_allocator) != NULL)
170 abort ();
171 #ifdef __cplusplus
172 omp_free (p);
173 omp_free (q);
174 omp_free (NULL);
175 #else
176 omp_free (p, omp_null_allocator);
177 omp_free (q, omp_null_allocator);
178 omp_free (NULL, omp_null_allocator);
179 #endif
180 omp_free (NULL, omp_null_allocator);
181 omp_destroy_allocator (a2);
182 omp_destroy_allocator (a);
183 return 0;