Branch data Line data Source code
1 : : /* Backend support for Fortran 95 basic types and derived types.
2 : : Copyright (C) 2002-2024 Free Software Foundation, Inc.
3 : : Contributed by Paul Brook <paul@nowt.org>
4 : : and Steven Bosscher <s.bosscher@student.tudelft.nl>
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify it under
9 : : the terms of the GNU General Public License as published by the Free
10 : : Software Foundation; either version 3, or (at your option) any later
11 : : version.
12 : :
13 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 : : for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : /* trans-types.cc -- gfortran backend types */
23 : :
24 : : #include "config.h"
25 : : #include "system.h"
26 : : #include "coretypes.h"
27 : : #include "target.h"
28 : : #include "tree.h"
29 : : #include "gfortran.h"
30 : : #include "trans.h"
31 : : #include "stringpool.h"
32 : : #include "fold-const.h"
33 : : #include "stor-layout.h"
34 : : #include "langhooks.h" /* For iso-c-bindings.def. */
35 : : #include "toplev.h" /* For rest_of_decl_compilation. */
36 : : #include "trans-types.h"
37 : : #include "trans-const.h"
38 : : #include "trans-array.h"
39 : : #include "dwarf2out.h" /* For struct array_descr_info. */
40 : : #include "attribs.h"
41 : : #include "alias.h"
42 : :
43 : :
44 : : #if (GFC_MAX_DIMENSIONS < 10)
45 : : #define GFC_RANK_DIGITS 1
46 : : #define GFC_RANK_PRINTF_FORMAT "%01d"
47 : : #elif (GFC_MAX_DIMENSIONS < 100)
48 : : #define GFC_RANK_DIGITS 2
49 : : #define GFC_RANK_PRINTF_FORMAT "%02d"
50 : : #else
51 : : #error If you really need >99 dimensions, continue the sequence above...
52 : : #endif
53 : :
54 : : /* array of structs so we don't have to worry about xmalloc or free */
55 : : CInteropKind_t c_interop_kinds_table[ISOCBINDING_NUMBER];
56 : :
57 : : tree gfc_array_index_type;
58 : : tree gfc_array_range_type;
59 : : tree gfc_character1_type_node;
60 : : tree pvoid_type_node;
61 : : tree prvoid_type_node;
62 : : tree ppvoid_type_node;
63 : : tree pchar_type_node;
64 : : static tree pfunc_type_node;
65 : :
66 : : tree logical_type_node;
67 : : tree logical_true_node;
68 : : tree logical_false_node;
69 : : tree gfc_charlen_type_node;
70 : :
71 : : tree gfc_float128_type_node = NULL_TREE;
72 : : tree gfc_complex_float128_type_node = NULL_TREE;
73 : :
74 : : bool gfc_real16_is_float128 = false;
75 : : bool gfc_real16_use_iec_60559 = false;
76 : :
77 : : static GTY(()) tree gfc_desc_dim_type;
78 : : static GTY(()) tree gfc_max_array_element_size;
79 : : static GTY(()) tree gfc_array_descriptor_base[2 * (GFC_MAX_DIMENSIONS+1)];
80 : : static GTY(()) tree gfc_array_descriptor_base_caf[2 * (GFC_MAX_DIMENSIONS+1)];
81 : : static GTY(()) tree gfc_cfi_descriptor_base[2 * (CFI_MAX_RANK + 2)];
82 : :
83 : : /* Arrays for all integral and real kinds. We'll fill this in at runtime
84 : : after the target has a chance to process command-line options. */
85 : :
86 : : #define MAX_INT_KINDS 5
87 : : gfc_integer_info gfc_integer_kinds[MAX_INT_KINDS + 1];
88 : : gfc_logical_info gfc_logical_kinds[MAX_INT_KINDS + 1];
89 : : gfc_unsigned_info gfc_unsigned_kinds[MAX_INT_KINDS + 1];
90 : : static GTY(()) tree gfc_integer_types[MAX_INT_KINDS + 1];
91 : : static GTY(()) tree gfc_logical_types[MAX_INT_KINDS + 1];
92 : : static GTY(()) tree gfc_unsigned_types[MAX_INT_KINDS + 1];
93 : :
94 : : #define MAX_REAL_KINDS 5
95 : : gfc_real_info gfc_real_kinds[MAX_REAL_KINDS + 1];
96 : : static GTY(()) tree gfc_real_types[MAX_REAL_KINDS + 1];
97 : : static GTY(()) tree gfc_complex_types[MAX_REAL_KINDS + 1];
98 : :
99 : : #define MAX_CHARACTER_KINDS 2
100 : : gfc_character_info gfc_character_kinds[MAX_CHARACTER_KINDS + 1];
101 : : static GTY(()) tree gfc_character_types[MAX_CHARACTER_KINDS + 1];
102 : : static GTY(()) tree gfc_pcharacter_types[MAX_CHARACTER_KINDS + 1];
103 : :
104 : : static tree gfc_add_field_to_struct_1 (tree, tree, tree, tree **);
105 : :
106 : : /* The integer kind to use for array indices. This will be set to the
107 : : proper value based on target information from the backend. */
108 : :
109 : : int gfc_index_integer_kind;
110 : :
111 : : /* The default kinds of the various types. */
112 : :
113 : : int gfc_default_integer_kind;
114 : : int gfc_default_unsigned_kind;
115 : : int gfc_max_integer_kind;
116 : : int gfc_default_real_kind;
117 : : int gfc_default_double_kind;
118 : : int gfc_default_character_kind;
119 : : int gfc_default_logical_kind;
120 : : int gfc_default_complex_kind;
121 : : int gfc_c_int_kind;
122 : : int gfc_c_intptr_kind;
123 : : int gfc_atomic_int_kind;
124 : : int gfc_atomic_logical_kind;
125 : :
126 : : /* The kind size used for record offsets. If the target system supports
127 : : kind=8, this will be set to 8, otherwise it is set to 4. */
128 : : int gfc_intio_kind;
129 : :
130 : : /* The integer kind used to store character lengths. */
131 : : int gfc_charlen_int_kind;
132 : :
133 : : /* Kind of internal integer for storing object sizes. */
134 : : int gfc_size_kind;
135 : :
136 : : /* The size of the numeric storage unit and character storage unit. */
137 : : int gfc_numeric_storage_size;
138 : : int gfc_character_storage_size;
139 : :
140 : : static tree dtype_type_node = NULL_TREE;
141 : :
142 : :
143 : : /* Build the dtype_type_node if necessary. */
144 : 381926 : tree get_dtype_type_node (void)
145 : : {
146 : 381926 : tree field;
147 : 381926 : tree dtype_node;
148 : 381926 : tree *dtype_chain = NULL;
149 : :
150 : 381926 : if (dtype_type_node == NULL_TREE)
151 : : {
152 : 30148 : dtype_node = make_node (RECORD_TYPE);
153 : 30148 : TYPE_NAME (dtype_node) = get_identifier ("dtype_type");
154 : 30148 : TYPE_NAMELESS (dtype_node) = 1;
155 : 30148 : field = gfc_add_field_to_struct_1 (dtype_node,
156 : : get_identifier ("elem_len"),
157 : : size_type_node, &dtype_chain);
158 : 30148 : suppress_warning (field);
159 : 30148 : field = gfc_add_field_to_struct_1 (dtype_node,
160 : : get_identifier ("version"),
161 : : integer_type_node, &dtype_chain);
162 : 30148 : suppress_warning (field);
163 : 30148 : field = gfc_add_field_to_struct_1 (dtype_node,
164 : : get_identifier ("rank"),
165 : : signed_char_type_node, &dtype_chain);
166 : 30148 : suppress_warning (field);
167 : 30148 : field = gfc_add_field_to_struct_1 (dtype_node,
168 : : get_identifier ("type"),
169 : : signed_char_type_node, &dtype_chain);
170 : 30148 : suppress_warning (field);
171 : 30148 : field = gfc_add_field_to_struct_1 (dtype_node,
172 : : get_identifier ("attribute"),
173 : : short_integer_type_node, &dtype_chain);
174 : 30148 : suppress_warning (field);
175 : 30148 : gfc_finish_type (dtype_node);
176 : 30148 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (dtype_node)) = 1;
177 : 30148 : dtype_type_node = dtype_node;
178 : : }
179 : 381926 : return dtype_type_node;
180 : : }
181 : :
182 : : static int
183 : 241304 : get_real_kind_from_node (tree type)
184 : : {
185 : 241304 : int i;
186 : :
187 : 603260 : for (i = 0; gfc_real_kinds[i].kind != 0; i++)
188 : 603260 : if (gfc_real_kinds[i].mode_precision == TYPE_PRECISION (type))
189 : : {
190 : : /* On Power, we have three 128-bit scalar floating-point modes
191 : : and all of their types have 128 bit type precision, so we
192 : : should check underlying real format details further. */
193 : : #if defined(HAVE_TFmode) && defined(HAVE_IFmode) && defined(HAVE_KFmode)
194 : : if (gfc_real_kinds[i].kind == 16)
195 : : {
196 : : machine_mode mode = TYPE_MODE (type);
197 : : const struct real_format *fmt = REAL_MODE_FORMAT (mode);
198 : : if (fmt->p != gfc_real_kinds[i].digits)
199 : : continue;
200 : : }
201 : : #endif
202 : 241304 : return gfc_real_kinds[i].kind;
203 : : }
204 : :
205 : : return -4;
206 : : }
207 : :
208 : : static int
209 : 784238 : get_int_kind_from_node (tree type)
210 : : {
211 : 784238 : int i;
212 : :
213 : 784238 : if (!type)
214 : : return -2;
215 : :
216 : 2528808 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
217 : 2528808 : if (gfc_integer_kinds[i].bit_size == TYPE_PRECISION (type))
218 : 784238 : return gfc_integer_kinds[i].kind;
219 : :
220 : : return -1;
221 : : }
222 : :
223 : : static int
224 : 482608 : get_int_kind_from_name (const char *name)
225 : : {
226 : 482608 : return get_int_kind_from_node (get_typenode_from_name (name));
227 : : }
228 : :
229 : :
230 : : /* Get the kind number corresponding to an integer of given size,
231 : : following the required return values for ISO_FORTRAN_ENV INT* constants:
232 : : -2 is returned if we support a kind of larger size, -1 otherwise. */
233 : : int
234 : 3736 : gfc_get_int_kind_from_width_isofortranenv (int size)
235 : : {
236 : 3736 : int i;
237 : :
238 : : /* Look for a kind with matching storage size. */
239 : 9340 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
240 : 9340 : if (gfc_integer_kinds[i].bit_size == size)
241 : 3736 : return gfc_integer_kinds[i].kind;
242 : :
243 : : /* Look for a kind with larger storage size. */
244 : 0 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
245 : 0 : if (gfc_integer_kinds[i].bit_size > size)
246 : : return -2;
247 : :
248 : : return -1;
249 : : }
250 : :
251 : :
252 : : /* Get the kind number corresponding to a real of a given storage size.
253 : : If two real's have the same storage size, then choose the real with
254 : : the largest precision. If a kind type is unavailable and a real
255 : : exists with wider storage, then return -2; otherwise, return -1. */
256 : :
257 : : int
258 : 1868 : gfc_get_real_kind_from_width_isofortranenv (int size)
259 : : {
260 : 1868 : int digits, i, kind;
261 : :
262 : 1868 : size /= 8;
263 : :
264 : 1868 : kind = -1;
265 : 1868 : digits = 0;
266 : :
267 : : /* Look for a kind with matching storage size. */
268 : 9340 : for (i = 0; gfc_real_kinds[i].kind != 0; i++)
269 : 7472 : if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds[i].kind)) == size)
270 : : {
271 : 1864 : if (gfc_real_kinds[i].digits > digits)
272 : : {
273 : 1864 : digits = gfc_real_kinds[i].digits;
274 : 1864 : kind = gfc_real_kinds[i].kind;
275 : : }
276 : : }
277 : :
278 : 1868 : if (kind != -1)
279 : : return kind;
280 : :
281 : : /* Look for a kind with larger storage size. */
282 : 2335 : for (i = 0; gfc_real_kinds[i].kind != 0; i++)
283 : 1868 : if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds[i].kind)) > size)
284 : 1868 : kind = -2;
285 : :
286 : : return kind;
287 : : }
288 : :
289 : :
290 : :
291 : : static int
292 : 150815 : get_int_kind_from_width (int size)
293 : : {
294 : 150815 : int i;
295 : :
296 : 452445 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
297 : 451631 : if (gfc_integer_kinds[i].bit_size == size)
298 : 0 : return gfc_integer_kinds[i].kind;
299 : :
300 : : return -2;
301 : : }
302 : :
303 : : static int
304 : 30163 : get_int_kind_from_minimal_width (int size)
305 : : {
306 : 30163 : int i;
307 : :
308 : 150815 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
309 : 150408 : if (gfc_integer_kinds[i].bit_size >= size)
310 : 0 : return gfc_integer_kinds[i].kind;
311 : :
312 : : return -2;
313 : : }
314 : :
315 : :
316 : : /* Generate the CInteropKind_t objects for the C interoperable
317 : : kinds. */
318 : :
319 : : void
320 : 30163 : gfc_init_c_interop_kinds (void)
321 : : {
322 : 30163 : int i;
323 : :
324 : : /* init all pointers in the list to NULL */
325 : 1598639 : for (i = 0; i < ISOCBINDING_NUMBER; i++)
326 : : {
327 : : /* Initialize the name and value fields. */
328 : 1568476 : c_interop_kinds_table[i].name[0] = '\0';
329 : 1568476 : c_interop_kinds_table[i].value = -100;
330 : 1568476 : c_interop_kinds_table[i].f90_type = BT_UNKNOWN;
331 : : }
332 : :
333 : : #define NAMED_INTCST(a,b,c,d) \
334 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
335 : : c_interop_kinds_table[a].f90_type = BT_INTEGER; \
336 : : c_interop_kinds_table[a].value = c;
337 : : #define NAMED_REALCST(a,b,c,d) \
338 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
339 : : c_interop_kinds_table[a].f90_type = BT_REAL; \
340 : : c_interop_kinds_table[a].value = c;
341 : : #define NAMED_CMPXCST(a,b,c,d) \
342 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
343 : : c_interop_kinds_table[a].f90_type = BT_COMPLEX; \
344 : : c_interop_kinds_table[a].value = c;
345 : : #define NAMED_LOGCST(a,b,c) \
346 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
347 : : c_interop_kinds_table[a].f90_type = BT_LOGICAL; \
348 : : c_interop_kinds_table[a].value = c;
349 : : #define NAMED_CHARKNDCST(a,b,c) \
350 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
351 : : c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
352 : : c_interop_kinds_table[a].value = c;
353 : : #define NAMED_CHARCST(a,b,c) \
354 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
355 : : c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
356 : : c_interop_kinds_table[a].value = c;
357 : : #define DERIVED_TYPE(a,b,c) \
358 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
359 : : c_interop_kinds_table[a].f90_type = BT_DERIVED; \
360 : : c_interop_kinds_table[a].value = c;
361 : : #define NAMED_FUNCTION(a,b,c,d) \
362 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
363 : : c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
364 : : c_interop_kinds_table[a].value = c;
365 : : #define NAMED_SUBROUTINE(a,b,c,d) \
366 : : strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
367 : : c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
368 : : c_interop_kinds_table[a].value = c;
369 : : #include "iso-c-binding.def"
370 : 30163 : }
371 : :
372 : :
373 : : /* Query the target to determine which machine modes are available for
374 : : computation. Choose KIND numbers for them. */
375 : :
376 : : void
377 : 30163 : gfc_init_kinds (void)
378 : : {
379 : 30163 : opt_scalar_int_mode int_mode_iter;
380 : 30163 : opt_scalar_float_mode float_mode_iter;
381 : 30163 : int i_index, r_index, kind;
382 : 30163 : bool saw_i4 = false, saw_i8 = false;
383 : 30163 : bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false;
384 : 30163 : scalar_mode r16_mode = QImode;
385 : 30163 : scalar_mode composite_mode = QImode;
386 : :
387 : 30163 : i_index = 0;
388 : 241304 : FOR_EACH_MODE_IN_CLASS (int_mode_iter, MODE_INT)
389 : : {
390 : 211141 : scalar_int_mode mode = int_mode_iter.require ();
391 : 211141 : int kind, bitsize;
392 : :
393 : 211141 : if (!targetm.scalar_mode_supported_p (mode))
394 : 211141 : continue;
395 : :
396 : : /* The middle end doesn't support constants larger than 2*HWI.
397 : : Perhaps the target hook shouldn't have accepted these either,
398 : : but just to be safe... */
399 : 150408 : bitsize = GET_MODE_BITSIZE (mode);
400 : 150408 : if (bitsize > 2*HOST_BITS_PER_WIDE_INT)
401 : 0 : continue;
402 : :
403 : 150408 : gcc_assert (i_index != MAX_INT_KINDS);
404 : :
405 : : /* Let the kind equal the bit size divided by 8. This insulates the
406 : : programmer from the underlying byte size. */
407 : 150408 : kind = bitsize / 8;
408 : :
409 : 150408 : if (kind == 4)
410 : : saw_i4 = true;
411 : 120245 : if (kind == 8)
412 : 30163 : saw_i8 = true;
413 : :
414 : 150408 : gfc_integer_kinds[i_index].kind = kind;
415 : 150408 : gfc_integer_kinds[i_index].radix = 2;
416 : 150408 : gfc_integer_kinds[i_index].digits = bitsize - 1;
417 : 150408 : gfc_integer_kinds[i_index].bit_size = bitsize;
418 : :
419 : 150408 : if (flag_unsigned)
420 : : {
421 : 770 : gfc_unsigned_kinds[i_index].kind = kind;
422 : 770 : gfc_unsigned_kinds[i_index].radix = 2;
423 : 770 : gfc_unsigned_kinds[i_index].digits = bitsize;
424 : 770 : gfc_unsigned_kinds[i_index].bit_size = bitsize;
425 : : }
426 : :
427 : 150408 : gfc_logical_kinds[i_index].kind = kind;
428 : 150408 : gfc_logical_kinds[i_index].bit_size = bitsize;
429 : :
430 : 150408 : i_index += 1;
431 : : }
432 : :
433 : : /* Set the kind used to match GFC_INT_IO in libgfortran. This is
434 : : used for large file access. */
435 : :
436 : 30163 : if (saw_i8)
437 : 30163 : gfc_intio_kind = 8;
438 : : else
439 : 0 : gfc_intio_kind = 4;
440 : :
441 : : /* If we do not at least have kind = 4, everything is pointless. */
442 : 30163 : gcc_assert(saw_i4);
443 : :
444 : : /* Set the maximum integer kind. Used with at least BOZ constants. */
445 : 30163 : gfc_max_integer_kind = gfc_integer_kinds[i_index - 1].kind;
446 : :
447 : 30163 : r_index = 0;
448 : 211141 : FOR_EACH_MODE_IN_CLASS (float_mode_iter, MODE_FLOAT)
449 : : {
450 : 180978 : scalar_float_mode mode = float_mode_iter.require ();
451 : 180978 : const struct real_format *fmt = REAL_MODE_FORMAT (mode);
452 : 180978 : int kind;
453 : :
454 : 180978 : if (fmt == NULL)
455 : 180978 : continue;
456 : 180978 : if (!targetm.scalar_mode_supported_p (mode))
457 : 0 : continue;
458 : :
459 : 1266846 : if (MODE_COMPOSITE_P (mode)
460 : 0 : && (GET_MODE_PRECISION (mode) + 7) / 8 == 16)
461 : 0 : composite_mode = mode;
462 : :
463 : : /* Only let float, double, long double and TFmode go through.
464 : : Runtime support for others is not provided, so they would be
465 : : useless. */
466 : 180978 : if (!targetm.libgcc_floating_mode_supported_p (mode))
467 : 0 : continue;
468 : 180978 : if (mode != TYPE_MODE (float_type_node)
469 : 150815 : && (mode != TYPE_MODE (double_type_node))
470 : 120652 : && (mode != TYPE_MODE (long_double_type_node))
471 : : #if defined(HAVE_TFmode) && defined(ENABLE_LIBQUADMATH_SUPPORT)
472 : 271467 : && (mode != TFmode)
473 : : #endif
474 : : )
475 : 60326 : continue;
476 : :
477 : : /* Let the kind equal the precision divided by 8, rounding up. Again,
478 : : this insulates the programmer from the underlying byte size.
479 : :
480 : : Also, it effectively deals with IEEE extended formats. There, the
481 : : total size of the type may equal 16, but it's got 6 bytes of padding
482 : : and the increased size can get in the way of a real IEEE quad format
483 : : which may also be supported by the target.
484 : :
485 : : We round up so as to handle IA-64 __floatreg (RFmode), which is an
486 : : 82 bit type. Not to be confused with __float80 (XFmode), which is
487 : : an 80 bit type also supported by IA-64. So XFmode should come out
488 : : to be kind=10, and RFmode should come out to be kind=11. Egads.
489 : :
490 : : TODO: The kind calculation has to be modified to support all
491 : : three 128-bit floating-point modes on PowerPC as IFmode, KFmode,
492 : : and TFmode since the following line would all map to kind=16.
493 : : However, currently only float, double, long double, and TFmode
494 : : reach this code.
495 : : */
496 : :
497 : 120652 : kind = (GET_MODE_PRECISION (mode) + 7) / 8;
498 : :
499 : 120652 : if (kind == 4)
500 : : saw_r4 = true;
501 : 90489 : if (kind == 8)
502 : : saw_r8 = true;
503 : 90489 : if (kind == 10)
504 : : saw_r10 = true;
505 : 90489 : if (kind == 16)
506 : : {
507 : 30163 : saw_r16 = true;
508 : 30163 : r16_mode = mode;
509 : : }
510 : :
511 : : /* Careful we don't stumble a weird internal mode. */
512 : 120652 : gcc_assert (r_index <= 0 || gfc_real_kinds[r_index-1].kind != kind);
513 : : /* Or have too many modes for the allocated space. */
514 : 90489 : gcc_assert (r_index != MAX_REAL_KINDS);
515 : :
516 : 120652 : gfc_real_kinds[r_index].kind = kind;
517 : 120652 : gfc_real_kinds[r_index].abi_kind = kind;
518 : 120652 : gfc_real_kinds[r_index].radix = fmt->b;
519 : 120652 : gfc_real_kinds[r_index].digits = fmt->p;
520 : 120652 : gfc_real_kinds[r_index].min_exponent = fmt->emin;
521 : 120652 : gfc_real_kinds[r_index].max_exponent = fmt->emax;
522 : 120652 : if (fmt->pnan < fmt->p)
523 : : /* This is an IBM extended double format (or the MIPS variant)
524 : : made up of two IEEE doubles. The value of the long double is
525 : : the sum of the values of the two parts. The most significant
526 : : part is required to be the value of the long double rounded
527 : : to the nearest double. If we use emax of 1024 then we can't
528 : : represent huge(x) = (1 - b**(-p)) * b**(emax-1) * b, because
529 : : rounding will make the most significant part overflow. */
530 : 0 : gfc_real_kinds[r_index].max_exponent = fmt->emax - 1;
531 : 120652 : gfc_real_kinds[r_index].mode_precision = GET_MODE_PRECISION (mode);
532 : 120652 : r_index += 1;
533 : : }
534 : :
535 : : /* Detect the powerpc64le-linux case with -mabi=ieeelongdouble, where
536 : : the long double type is non-MODE_COMPOSITE_P TFmode but one can use
537 : : -mabi=ibmlongdouble too and get MODE_COMPOSITE_P TFmode with the same
538 : : precision. For libgfortran calls pretend the IEEE 754 quad TFmode has
539 : : kind 17 rather than 16 and use kind 16 for the IBM extended format
540 : : TFmode. */
541 : 30163 : if (composite_mode != QImode && saw_r16 && !MODE_COMPOSITE_P (r16_mode))
542 : : {
543 : 0 : for (int i = 0; i < r_index; ++i)
544 : 0 : if (gfc_real_kinds[i].kind == 16)
545 : : {
546 : 0 : gfc_real_kinds[i].abi_kind = 17;
547 : 0 : if (flag_building_libgfortran
548 : : && (TARGET_GLIBC_MAJOR < 2
549 : : || (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR < 32)))
550 : : {
551 : : if (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR >= 26)
552 : : {
553 : : gfc_real16_use_iec_60559 = true;
554 : : gfc_real_kinds[i].use_iec_60559 = 1;
555 : : }
556 : : gfc_real16_is_float128 = true;
557 : : gfc_real_kinds[i].c_float128 = 1;
558 : : }
559 : : }
560 : : }
561 : 30163 : else if ((flag_convert & (GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM)) != 0)
562 : 0 : gfc_fatal_error ("%<-fconvert=r16_ieee%> or %<-fconvert=r16_ibm%> not "
563 : : "supported on this architecture");
564 : :
565 : : /* Choose the default integer kind. We choose 4 unless the user directs us
566 : : otherwise. Even if the user specified that the default integer kind is 8,
567 : : the numeric storage size is not 64 bits. In this case, a warning will be
568 : : issued when NUMERIC_STORAGE_SIZE is used. Set NUMERIC_STORAGE_SIZE to 32. */
569 : :
570 : 30163 : gfc_numeric_storage_size = 4 * 8;
571 : :
572 : 30163 : if (flag_default_integer)
573 : : {
574 : 98 : if (!saw_i8)
575 : 0 : gfc_fatal_error ("INTEGER(KIND=8) is not available for "
576 : : "%<-fdefault-integer-8%> option");
577 : :
578 : 98 : gfc_default_integer_kind = 8;
579 : :
580 : : }
581 : 30065 : else if (flag_integer4_kind == 8)
582 : : {
583 : 0 : if (!saw_i8)
584 : 0 : gfc_fatal_error ("INTEGER(KIND=8) is not available for "
585 : : "%<-finteger-4-integer-8%> option");
586 : :
587 : 0 : gfc_default_integer_kind = 8;
588 : : }
589 : 30065 : else if (saw_i4)
590 : : {
591 : 30065 : gfc_default_integer_kind = 4;
592 : : }
593 : : else
594 : : {
595 : : gfc_default_integer_kind = gfc_integer_kinds[i_index - 1].kind;
596 : : gfc_numeric_storage_size = gfc_integer_kinds[i_index - 1].bit_size;
597 : : }
598 : :
599 : 30163 : gfc_default_unsigned_kind = gfc_default_integer_kind;
600 : :
601 : : /* Choose the default real kind. Again, we choose 4 when possible. */
602 : 30163 : if (flag_default_real_8)
603 : : {
604 : 2 : if (!saw_r8)
605 : 0 : gfc_fatal_error ("REAL(KIND=8) is not available for "
606 : : "%<-fdefault-real-8%> option");
607 : :
608 : 2 : gfc_default_real_kind = 8;
609 : : }
610 : 30161 : else if (flag_default_real_10)
611 : : {
612 : 6 : if (!saw_r10)
613 : 0 : gfc_fatal_error ("REAL(KIND=10) is not available for "
614 : : "%<-fdefault-real-10%> option");
615 : :
616 : 6 : gfc_default_real_kind = 10;
617 : : }
618 : 30155 : else if (flag_default_real_16)
619 : : {
620 : 6 : if (!saw_r16)
621 : 0 : gfc_fatal_error ("REAL(KIND=16) is not available for "
622 : : "%<-fdefault-real-16%> option");
623 : :
624 : 6 : gfc_default_real_kind = 16;
625 : : }
626 : 30149 : else if (flag_real4_kind == 8)
627 : : {
628 : 24 : if (!saw_r8)
629 : 0 : gfc_fatal_error ("REAL(KIND=8) is not available for %<-freal-4-real-8%> "
630 : : "option");
631 : :
632 : 24 : gfc_default_real_kind = 8;
633 : : }
634 : 30125 : else if (flag_real4_kind == 10)
635 : : {
636 : 24 : if (!saw_r10)
637 : 0 : gfc_fatal_error ("REAL(KIND=10) is not available for "
638 : : "%<-freal-4-real-10%> option");
639 : :
640 : 24 : gfc_default_real_kind = 10;
641 : : }
642 : 30101 : else if (flag_real4_kind == 16)
643 : : {
644 : 24 : if (!saw_r16)
645 : 0 : gfc_fatal_error ("REAL(KIND=16) is not available for "
646 : : "%<-freal-4-real-16%> option");
647 : :
648 : 24 : gfc_default_real_kind = 16;
649 : : }
650 : 30077 : else if (saw_r4)
651 : 30077 : gfc_default_real_kind = 4;
652 : : else
653 : 0 : gfc_default_real_kind = gfc_real_kinds[0].kind;
654 : :
655 : : /* Choose the default double kind. If -fdefault-real and -fdefault-double
656 : : are specified, we use kind=8, if it's available. If -fdefault-real is
657 : : specified without -fdefault-double, we use kind=16, if it's available.
658 : : Otherwise we do not change anything. */
659 : 30163 : if (flag_default_double && saw_r8)
660 : 0 : gfc_default_double_kind = 8;
661 : 30163 : else if (flag_default_real_8 || flag_default_real_10 || flag_default_real_16)
662 : : {
663 : : /* Use largest available kind. */
664 : 14 : if (saw_r16)
665 : 14 : gfc_default_double_kind = 16;
666 : 0 : else if (saw_r10)
667 : 0 : gfc_default_double_kind = 10;
668 : 0 : else if (saw_r8)
669 : 0 : gfc_default_double_kind = 8;
670 : : else
671 : 0 : gfc_default_double_kind = gfc_default_real_kind;
672 : : }
673 : 30149 : else if (flag_real8_kind == 4)
674 : : {
675 : 24 : if (!saw_r4)
676 : 0 : gfc_fatal_error ("REAL(KIND=4) is not available for "
677 : : "%<-freal-8-real-4%> option");
678 : :
679 : 24 : gfc_default_double_kind = 4;
680 : : }
681 : 30125 : else if (flag_real8_kind == 10 )
682 : : {
683 : 24 : if (!saw_r10)
684 : 0 : gfc_fatal_error ("REAL(KIND=10) is not available for "
685 : : "%<-freal-8-real-10%> option");
686 : :
687 : 24 : gfc_default_double_kind = 10;
688 : : }
689 : 30101 : else if (flag_real8_kind == 16 )
690 : : {
691 : 24 : if (!saw_r16)
692 : 0 : gfc_fatal_error ("REAL(KIND=10) is not available for "
693 : : "%<-freal-8-real-16%> option");
694 : :
695 : 24 : gfc_default_double_kind = 16;
696 : : }
697 : 30077 : else if (saw_r4 && saw_r8)
698 : 30077 : gfc_default_double_kind = 8;
699 : : else
700 : : {
701 : : /* F95 14.6.3.1: A nonpointer scalar object of type double precision
702 : : real ... occupies two contiguous numeric storage units.
703 : :
704 : : Therefore we must be supplied a kind twice as large as we chose
705 : : for single precision. There are loopholes, in that double
706 : : precision must *occupy* two storage units, though it doesn't have
707 : : to *use* two storage units. Which means that you can make this
708 : : kind artificially wide by padding it. But at present there are
709 : : no GCC targets for which a two-word type does not exist, so we
710 : : just let gfc_validate_kind abort and tell us if something breaks. */
711 : :
712 : 0 : gfc_default_double_kind
713 : 0 : = gfc_validate_kind (BT_REAL, gfc_default_real_kind * 2, false);
714 : : }
715 : :
716 : : /* The default logical kind is constrained to be the same as the
717 : : default integer kind. Similarly with complex and real. */
718 : 30163 : gfc_default_logical_kind = gfc_default_integer_kind;
719 : 30163 : gfc_default_complex_kind = gfc_default_real_kind;
720 : :
721 : : /* We only have two character kinds: ASCII and UCS-4.
722 : : ASCII corresponds to a 8-bit integer type, if one is available.
723 : : UCS-4 corresponds to a 32-bit integer type, if one is available. */
724 : 30163 : i_index = 0;
725 : 60326 : if ((kind = get_int_kind_from_width (8)) > 0)
726 : : {
727 : 30163 : gfc_character_kinds[i_index].kind = kind;
728 : 30163 : gfc_character_kinds[i_index].bit_size = 8;
729 : 30163 : gfc_character_kinds[i_index].name = "ascii";
730 : 30163 : i_index++;
731 : : }
732 : 60326 : if ((kind = get_int_kind_from_width (32)) > 0)
733 : : {
734 : 30163 : gfc_character_kinds[i_index].kind = kind;
735 : 30163 : gfc_character_kinds[i_index].bit_size = 32;
736 : 30163 : gfc_character_kinds[i_index].name = "iso_10646";
737 : 30163 : i_index++;
738 : : }
739 : :
740 : : /* Choose the smallest integer kind for our default character. */
741 : 30163 : gfc_default_character_kind = gfc_character_kinds[0].kind;
742 : 30163 : gfc_character_storage_size = gfc_default_character_kind * 8;
743 : :
744 : 30570 : gfc_index_integer_kind = get_int_kind_from_name (PTRDIFF_TYPE);
745 : :
746 : : /* Pick a kind the same size as the C "int" type. */
747 : 30163 : gfc_c_int_kind = INT_TYPE_SIZE / 8;
748 : :
749 : : /* Choose atomic kinds to match C's int. */
750 : 30163 : gfc_atomic_int_kind = gfc_c_int_kind;
751 : 30163 : gfc_atomic_logical_kind = gfc_c_int_kind;
752 : :
753 : 30163 : gfc_c_intptr_kind = POINTER_SIZE / 8;
754 : 30163 : }
755 : :
756 : :
757 : : /* Make sure that a valid kind is present. Returns an index into the
758 : : associated kinds array, -1 if the kind is not present. */
759 : :
760 : : static int
761 : 0 : validate_integer (int kind)
762 : : {
763 : 0 : int i;
764 : :
765 : 76483353 : for (i = 0; gfc_integer_kinds[i].kind != 0; i++)
766 : 76481298 : if (gfc_integer_kinds[i].kind == kind)
767 : 0 : return i;
768 : :
769 : : return -1;
770 : : }
771 : :
772 : : static int
773 : 0 : validate_unsigned (int kind)
774 : : {
775 : 0 : int i;
776 : :
777 : 80694 : for (i = 0; gfc_unsigned_kinds[i].kind != 0; i++)
778 : 80694 : if (gfc_unsigned_kinds[i].kind == kind)
779 : 0 : return i;
780 : :
781 : : return -1;
782 : : }
783 : :
784 : : static int
785 : 0 : validate_real (int kind)
786 : : {
787 : 0 : int i;
788 : :
789 : 4927114 : for (i = 0; gfc_real_kinds[i].kind != 0; i++)
790 : 4927104 : if (gfc_real_kinds[i].kind == kind)
791 : 0 : return i;
792 : :
793 : : return -1;
794 : : }
795 : :
796 : : static int
797 : 0 : validate_logical (int kind)
798 : : {
799 : 0 : int i;
800 : :
801 : 1500311 : for (i = 0; gfc_logical_kinds[i].kind; i++)
802 : 1500303 : if (gfc_logical_kinds[i].kind == kind)
803 : 0 : return i;
804 : :
805 : : return -1;
806 : : }
807 : :
808 : : static int
809 : 0 : validate_character (int kind)
810 : : {
811 : 0 : int i;
812 : :
813 : 1327351 : for (i = 0; gfc_character_kinds[i].kind; i++)
814 : 1327337 : if (gfc_character_kinds[i].kind == kind)
815 : 0 : return i;
816 : :
817 : : return -1;
818 : : }
819 : :
820 : : /* Validate a kind given a basic type. The return value is the same
821 : : for the child functions, with -1 indicating nonexistence of the
822 : : type. If MAY_FAIL is false, then -1 is never returned, and we ICE. */
823 : :
824 : : int
825 : 28874706 : gfc_validate_kind (bt type, int kind, bool may_fail)
826 : : {
827 : 28874706 : int rc;
828 : :
829 : 28874706 : switch (type)
830 : : {
831 : : case BT_REAL: /* Fall through */
832 : : case BT_COMPLEX:
833 : 28874706 : rc = validate_real (kind);
834 : : break;
835 : : case BT_INTEGER:
836 : 28874706 : rc = validate_integer (kind);
837 : : break;
838 : : case BT_UNSIGNED:
839 : 28874706 : rc = validate_unsigned (kind);
840 : : break;
841 : : case BT_LOGICAL:
842 : 28874706 : rc = validate_logical (kind);
843 : : break;
844 : : case BT_CHARACTER:
845 : 28874706 : rc = validate_character (kind);
846 : : break;
847 : :
848 : 0 : default:
849 : 0 : gfc_internal_error ("gfc_validate_kind(): Got bad type");
850 : : }
851 : :
852 : 28874706 : if (rc < 0 && !may_fail)
853 : 0 : gfc_internal_error ("gfc_validate_kind(): Got bad kind");
854 : :
855 : 28874706 : return rc;
856 : : }
857 : :
858 : :
859 : : /* Four subroutines of gfc_init_types. Create type nodes for the given kind.
860 : : Reuse common type nodes where possible. Recognize if the kind matches up
861 : : with a C type. This will be used later in determining which routines may
862 : : be scarfed from libm. */
863 : :
864 : : static tree
865 : 150408 : gfc_build_int_type (gfc_integer_info *info)
866 : : {
867 : 150408 : int mode_precision = info->bit_size;
868 : :
869 : 150408 : if (mode_precision == CHAR_TYPE_SIZE)
870 : 30163 : info->c_char = 1;
871 : 150408 : if (mode_precision == SHORT_TYPE_SIZE)
872 : 30163 : info->c_short = 1;
873 : 150408 : if (mode_precision == INT_TYPE_SIZE)
874 : 30163 : info->c_int = 1;
875 : 152036 : if (mode_precision == LONG_TYPE_SIZE)
876 : 30163 : info->c_long = 1;
877 : 150408 : if (mode_precision == LONG_LONG_TYPE_SIZE)
878 : 30163 : info->c_long_long = 1;
879 : :
880 : 150408 : if (TYPE_PRECISION (intQI_type_node) == mode_precision)
881 : : return intQI_type_node;
882 : 120245 : if (TYPE_PRECISION (intHI_type_node) == mode_precision)
883 : : return intHI_type_node;
884 : 90082 : if (TYPE_PRECISION (intSI_type_node) == mode_precision)
885 : : return intSI_type_node;
886 : 59919 : if (TYPE_PRECISION (intDI_type_node) == mode_precision)
887 : : return intDI_type_node;
888 : 29756 : if (TYPE_PRECISION (intTI_type_node) == mode_precision)
889 : : return intTI_type_node;
890 : :
891 : 0 : return make_signed_type (mode_precision);
892 : : }
893 : :
894 : : tree
895 : 61688 : gfc_build_uint_type (int size)
896 : : {
897 : 61688 : if (size == CHAR_TYPE_SIZE)
898 : 30443 : return unsigned_char_type_node;
899 : 31245 : if (size == SHORT_TYPE_SIZE)
900 : 280 : return short_unsigned_type_node;
901 : 30965 : if (size == INT_TYPE_SIZE)
902 : 30397 : return unsigned_type_node;
903 : 568 : if (size == LONG_TYPE_SIZE)
904 : 280 : return long_unsigned_type_node;
905 : 288 : if (size == LONG_LONG_TYPE_SIZE)
906 : 0 : return long_long_unsigned_type_node;
907 : :
908 : 288 : return make_unsigned_type (size);
909 : : }
910 : :
911 : : static tree
912 : 616 : gfc_build_unsigned_type (gfc_unsigned_info *info)
913 : : {
914 : 616 : int mode_precision = info->bit_size;
915 : :
916 : 616 : if (mode_precision == CHAR_TYPE_SIZE)
917 : 154 : info->c_unsigned_char = 1;
918 : 616 : if (mode_precision == SHORT_TYPE_SIZE)
919 : 154 : info->c_unsigned_short = 1;
920 : 616 : if (mode_precision == INT_TYPE_SIZE)
921 : 0 : info->c_unsigned_int = 1;
922 : 616 : if (mode_precision == LONG_TYPE_SIZE)
923 : 154 : info->c_unsigned_long = 1;
924 : 616 : if (mode_precision == LONG_LONG_TYPE_SIZE)
925 : 154 : info->c_unsigned_long_long = 1;
926 : :
927 : 616 : return gfc_build_uint_type (mode_precision);
928 : : }
929 : :
930 : : static tree
931 : 120652 : gfc_build_real_type (gfc_real_info *info)
932 : : {
933 : 120652 : int mode_precision = info->mode_precision;
934 : 120652 : tree new_type;
935 : :
936 : 120652 : if (mode_precision == TYPE_PRECISION (float_type_node))
937 : 30163 : info->c_float = 1;
938 : 120652 : if (mode_precision == TYPE_PRECISION (double_type_node))
939 : 30163 : info->c_double = 1;
940 : 120652 : if (mode_precision == TYPE_PRECISION (long_double_type_node)
941 : 120652 : && !info->c_float128)
942 : 30163 : info->c_long_double = 1;
943 : 120652 : if (mode_precision != TYPE_PRECISION (long_double_type_node)
944 : 120652 : && mode_precision == 128)
945 : : {
946 : : /* TODO: see PR101835. */
947 : 30163 : info->c_float128 = 1;
948 : 30163 : gfc_real16_is_float128 = true;
949 : 30163 : if (TARGET_GLIBC_MAJOR > 2
950 : : || (TARGET_GLIBC_MAJOR == 2 && TARGET_GLIBC_MINOR >= 26))
951 : : {
952 : 30163 : info->use_iec_60559 = 1;
953 : 30163 : gfc_real16_use_iec_60559 = true;
954 : : }
955 : : }
956 : :
957 : 120652 : if (TYPE_PRECISION (float_type_node) == mode_precision)
958 : : return float_type_node;
959 : 90489 : if (TYPE_PRECISION (double_type_node) == mode_precision)
960 : : return double_type_node;
961 : 60326 : if (TYPE_PRECISION (long_double_type_node) == mode_precision)
962 : : return long_double_type_node;
963 : :
964 : 30163 : new_type = make_node (REAL_TYPE);
965 : 30163 : TYPE_PRECISION (new_type) = mode_precision;
966 : 30163 : layout_type (new_type);
967 : 30163 : return new_type;
968 : : }
969 : :
970 : : static tree
971 : 120652 : gfc_build_complex_type (tree scalar_type)
972 : : {
973 : 120652 : tree new_type;
974 : :
975 : 120652 : if (scalar_type == NULL)
976 : : return NULL;
977 : 120652 : if (scalar_type == float_type_node)
978 : 30163 : return complex_float_type_node;
979 : 90489 : if (scalar_type == double_type_node)
980 : 30163 : return complex_double_type_node;
981 : 60326 : if (scalar_type == long_double_type_node)
982 : 30163 : return complex_long_double_type_node;
983 : :
984 : 30163 : new_type = make_node (COMPLEX_TYPE);
985 : 30163 : TREE_TYPE (new_type) = scalar_type;
986 : 30163 : layout_type (new_type);
987 : 30163 : return new_type;
988 : : }
989 : :
990 : : static tree
991 : 150408 : gfc_build_logical_type (gfc_logical_info *info)
992 : : {
993 : 150408 : int bit_size = info->bit_size;
994 : 150408 : tree new_type;
995 : :
996 : 150408 : if (bit_size == BOOL_TYPE_SIZE)
997 : : {
998 : 30163 : info->c_bool = 1;
999 : 30163 : return boolean_type_node;
1000 : : }
1001 : :
1002 : 120245 : new_type = make_unsigned_type (bit_size);
1003 : 120245 : TREE_SET_CODE (new_type, BOOLEAN_TYPE);
1004 : 120245 : TYPE_MAX_VALUE (new_type) = build_int_cst (new_type, 1);
1005 : 120245 : TYPE_PRECISION (new_type) = 1;
1006 : :
1007 : 120245 : return new_type;
1008 : : }
1009 : :
1010 : :
1011 : : /* Create the backend type nodes. We map them to their
1012 : : equivalent C type, at least for now. We also give
1013 : : names to the types here, and we push them in the
1014 : : global binding level context.*/
1015 : :
1016 : : void
1017 : 30163 : gfc_init_types (void)
1018 : : {
1019 : 30163 : char name_buf[26];
1020 : 30163 : int index;
1021 : 30163 : tree type;
1022 : 30163 : unsigned n;
1023 : :
1024 : : /* Create and name the types. */
1025 : : #define PUSH_TYPE(name, node) \
1026 : : pushdecl (build_decl (input_location, \
1027 : : TYPE_DECL, get_identifier (name), node))
1028 : :
1029 : 180571 : for (index = 0; gfc_integer_kinds[index].kind != 0; ++index)
1030 : : {
1031 : 150408 : type = gfc_build_int_type (&gfc_integer_kinds[index]);
1032 : : /* Ensure integer(kind=1) doesn't have TYPE_STRING_FLAG set. */
1033 : 150408 : if (TYPE_STRING_FLAG (type))
1034 : 30163 : type = make_signed_type (gfc_integer_kinds[index].bit_size);
1035 : 150408 : gfc_integer_types[index] = type;
1036 : 150408 : snprintf (name_buf, sizeof(name_buf), "integer(kind=%d)",
1037 : : gfc_integer_kinds[index].kind);
1038 : 150408 : PUSH_TYPE (name_buf, type);
1039 : : }
1040 : :
1041 : 180571 : for (index = 0; gfc_logical_kinds[index].kind != 0; ++index)
1042 : : {
1043 : 150408 : type = gfc_build_logical_type (&gfc_logical_kinds[index]);
1044 : 150408 : gfc_logical_types[index] = type;
1045 : 150408 : snprintf (name_buf, sizeof(name_buf), "logical(kind=%d)",
1046 : : gfc_logical_kinds[index].kind);
1047 : 150408 : PUSH_TYPE (name_buf, type);
1048 : : }
1049 : :
1050 : 150815 : for (index = 0; gfc_real_kinds[index].kind != 0; index++)
1051 : : {
1052 : 120652 : type = gfc_build_real_type (&gfc_real_kinds[index]);
1053 : 120652 : gfc_real_types[index] = type;
1054 : 120652 : snprintf (name_buf, sizeof(name_buf), "real(kind=%d)",
1055 : : gfc_real_kinds[index].kind);
1056 : 120652 : PUSH_TYPE (name_buf, type);
1057 : :
1058 : 120652 : if (gfc_real_kinds[index].c_float128)
1059 : 30163 : gfc_float128_type_node = type;
1060 : :
1061 : 120652 : type = gfc_build_complex_type (type);
1062 : 120652 : gfc_complex_types[index] = type;
1063 : 120652 : snprintf (name_buf, sizeof(name_buf), "complex(kind=%d)",
1064 : : gfc_real_kinds[index].kind);
1065 : 120652 : PUSH_TYPE (name_buf, type);
1066 : :
1067 : 120652 : if (gfc_real_kinds[index].c_float128)
1068 : 30163 : gfc_complex_float128_type_node = type;
1069 : : }
1070 : :
1071 : 90489 : for (index = 0; gfc_character_kinds[index].kind != 0; ++index)
1072 : : {
1073 : 60326 : type = gfc_build_uint_type (gfc_character_kinds[index].bit_size);
1074 : 60326 : type = build_qualified_type (type, TYPE_UNQUALIFIED);
1075 : 60326 : snprintf (name_buf, sizeof(name_buf), "character(kind=%d)",
1076 : : gfc_character_kinds[index].kind);
1077 : 60326 : PUSH_TYPE (name_buf, type);
1078 : 60326 : gfc_character_types[index] = type;
1079 : 60326 : gfc_pcharacter_types[index] = build_pointer_type (type);
1080 : : }
1081 : 30163 : gfc_character1_type_node = gfc_character_types[0];
1082 : :
1083 : : /* The middle end only recognizes a single unsigned type. For
1084 : : compatibility of existing test cases, let's just use the
1085 : : character type. The reader of tree dumps is expected to be able
1086 : : to deal with this. */
1087 : :
1088 : 30163 : if (flag_unsigned)
1089 : : {
1090 : 924 : for (index = 0; gfc_unsigned_kinds[index].kind != 0;++index)
1091 : : {
1092 : 1848 : int index_char = -1;
1093 : 1848 : for (int i=0; gfc_character_kinds[i].kind != 0; i++)
1094 : : {
1095 : 1386 : if (gfc_character_kinds[i].bit_size
1096 : 1386 : == gfc_unsigned_kinds[index].bit_size)
1097 : : {
1098 : : index_char = i;
1099 : : break;
1100 : : }
1101 : : }
1102 : 770 : if (index_char > 0)
1103 : : {
1104 : 154 : gfc_unsigned_types[index] = gfc_character_types[index_char];
1105 : : }
1106 : : else
1107 : : {
1108 : 616 : type = gfc_build_unsigned_type (&gfc_unsigned_kinds[index]);
1109 : 616 : gfc_unsigned_types[index] = type;
1110 : 616 : snprintf (name_buf, sizeof(name_buf), "unsigned(kind=%d)",
1111 : : gfc_integer_kinds[index].kind);
1112 : 616 : PUSH_TYPE (name_buf, type);
1113 : : }
1114 : : }
1115 : : }
1116 : :
1117 : 30163 : PUSH_TYPE ("byte", unsigned_char_type_node);
1118 : 30163 : PUSH_TYPE ("void", void_type_node);
1119 : :
1120 : : /* DBX debugging output gets upset if these aren't set. */
1121 : 30163 : if (!TYPE_NAME (integer_type_node))
1122 : 0 : PUSH_TYPE ("c_integer", integer_type_node);
1123 : 30163 : if (!TYPE_NAME (char_type_node))
1124 : 30163 : PUSH_TYPE ("c_char", char_type_node);
1125 : :
1126 : : #undef PUSH_TYPE
1127 : :
1128 : 30163 : pvoid_type_node = build_pointer_type (void_type_node);
1129 : 30163 : prvoid_type_node = build_qualified_type (pvoid_type_node, TYPE_QUAL_RESTRICT);
1130 : 30163 : ppvoid_type_node = build_pointer_type (pvoid_type_node);
1131 : 30163 : pchar_type_node = build_pointer_type (gfc_character1_type_node);
1132 : 30163 : pfunc_type_node
1133 : 30163 : = build_pointer_type (build_function_type_list (void_type_node, NULL_TREE));
1134 : :
1135 : 30163 : gfc_array_index_type = gfc_get_int_type (gfc_index_integer_kind);
1136 : : /* We cannot use gfc_index_zero_node in definition of gfc_array_range_type,
1137 : : since this function is called before gfc_init_constants. */
1138 : 30163 : gfc_array_range_type
1139 : 30163 : = build_range_type (gfc_array_index_type,
1140 : 30163 : build_int_cst (gfc_array_index_type, 0),
1141 : : NULL_TREE);
1142 : :
1143 : : /* The maximum array element size that can be handled is determined
1144 : : by the number of bits available to store this field in the array
1145 : : descriptor. */
1146 : :
1147 : 30163 : n = TYPE_PRECISION (size_type_node);
1148 : 30163 : gfc_max_array_element_size
1149 : 30163 : = wide_int_to_tree (size_type_node,
1150 : 30163 : wi::mask (n, UNSIGNED,
1151 : 30163 : TYPE_PRECISION (size_type_node)));
1152 : :
1153 : 30163 : logical_type_node = gfc_get_logical_type (gfc_default_logical_kind);
1154 : 30163 : logical_true_node = build_int_cst (logical_type_node, 1);
1155 : 30163 : logical_false_node = build_int_cst (logical_type_node, 0);
1156 : :
1157 : : /* Character lengths are of type size_t, except signed. */
1158 : 30163 : gfc_charlen_int_kind = get_int_kind_from_node (size_type_node);
1159 : 30163 : gfc_charlen_type_node = gfc_get_int_type (gfc_charlen_int_kind);
1160 : :
1161 : : /* Fortran kind number of size_type_node (size_t). This is used for
1162 : : the _size member in vtables. */
1163 : 30163 : gfc_size_kind = get_int_kind_from_node (size_type_node);
1164 : 30163 : }
1165 : :
1166 : : /* Get the type node for the given type and kind. */
1167 : :
1168 : : tree
1169 : 5085687 : gfc_get_int_type (int kind)
1170 : : {
1171 : 5085687 : int index = gfc_validate_kind (BT_INTEGER, kind, true);
1172 : 5085687 : return index < 0 ? 0 : gfc_integer_types[index];
1173 : : }
1174 : :
1175 : : tree
1176 : 4279 : gfc_get_unsigned_type (int kind)
1177 : : {
1178 : 4279 : int index = gfc_validate_kind (BT_UNSIGNED, kind, true);
1179 : 4279 : return index < 0 ? 0 : gfc_unsigned_types[index];
1180 : : }
1181 : :
1182 : : tree
1183 : 699912 : gfc_get_real_type (int kind)
1184 : : {
1185 : 699912 : int index = gfc_validate_kind (BT_REAL, kind, true);
1186 : 699912 : return index < 0 ? 0 : gfc_real_types[index];
1187 : : }
1188 : :
1189 : : tree
1190 : 447589 : gfc_get_complex_type (int kind)
1191 : : {
1192 : 447589 : int index = gfc_validate_kind (BT_COMPLEX, kind, true);
1193 : 447589 : return index < 0 ? 0 : gfc_complex_types[index];
1194 : : }
1195 : :
1196 : : tree
1197 : 450167 : gfc_get_logical_type (int kind)
1198 : : {
1199 : 450167 : int index = gfc_validate_kind (BT_LOGICAL, kind, true);
1200 : 450167 : return index < 0 ? 0 : gfc_logical_types[index];
1201 : : }
1202 : :
1203 : : tree
1204 : 407455 : gfc_get_char_type (int kind)
1205 : : {
1206 : 407455 : int index = gfc_validate_kind (BT_CHARACTER, kind, true);
1207 : 407455 : return index < 0 ? 0 : gfc_character_types[index];
1208 : : }
1209 : :
1210 : : tree
1211 : 156398 : gfc_get_pchar_type (int kind)
1212 : : {
1213 : 156398 : int index = gfc_validate_kind (BT_CHARACTER, kind, true);
1214 : 156398 : return index < 0 ? 0 : gfc_pcharacter_types[index];
1215 : : }
1216 : :
1217 : :
1218 : : /* Create a character type with the given kind and length. */
1219 : :
1220 : : tree
1221 : 86141 : gfc_get_character_type_len_for_eltype (tree eltype, tree len)
1222 : : {
1223 : 86141 : tree bounds, type;
1224 : :
1225 : 86141 : bounds = build_range_type (gfc_charlen_type_node, gfc_index_one_node, len);
1226 : 86141 : type = build_array_type (eltype, bounds);
1227 : 86141 : TYPE_STRING_FLAG (type) = 1;
1228 : :
1229 : 86141 : return type;
1230 : : }
1231 : :
1232 : : tree
1233 : 78900 : gfc_get_character_type_len (int kind, tree len)
1234 : : {
1235 : 78900 : gfc_validate_kind (BT_CHARACTER, kind, false);
1236 : 78900 : return gfc_get_character_type_len_for_eltype (gfc_get_char_type (kind), len);
1237 : : }
1238 : :
1239 : :
1240 : : /* Get a type node for a character kind. */
1241 : :
1242 : : tree
1243 : 68911 : gfc_get_character_type (int kind, gfc_charlen * cl)
1244 : : {
1245 : 68911 : tree len;
1246 : :
1247 : 68911 : len = (cl == NULL) ? NULL_TREE : cl->backend_decl;
1248 : 67780 : if (len && POINTER_TYPE_P (TREE_TYPE (len)))
1249 : 0 : len = build_fold_indirect_ref (len);
1250 : :
1251 : 68911 : return gfc_get_character_type_len (kind, len);
1252 : : }
1253 : :
1254 : : /* Convert a basic type. This will be an array for character types. */
1255 : :
1256 : : tree
1257 : 1062637 : gfc_typenode_for_spec (gfc_typespec * spec, int codim)
1258 : : {
1259 : 1062637 : tree basetype;
1260 : :
1261 : 1062637 : switch (spec->type)
1262 : : {
1263 : 0 : case BT_UNKNOWN:
1264 : 0 : gcc_unreachable ();
1265 : :
1266 : 402043 : case BT_INTEGER:
1267 : : /* We use INTEGER(c_intptr_t) for C_PTR and C_FUNPTR once the symbol
1268 : : has been resolved. This is done so we can convert C_PTR and
1269 : : C_FUNPTR to simple variables that get translated to (void *). */
1270 : 402043 : if (spec->f90_type == BT_VOID)
1271 : : {
1272 : 343 : if (spec->u.derived
1273 : 343 : && spec->u.derived->intmod_sym_id == ISOCBINDING_PTR)
1274 : 262 : basetype = ptr_type_node;
1275 : : else
1276 : 81 : basetype = pfunc_type_node;
1277 : : }
1278 : : else
1279 : 401700 : basetype = gfc_get_int_type (spec->kind);
1280 : : break;
1281 : :
1282 : 1009 : case BT_UNSIGNED:
1283 : 1009 : basetype = gfc_get_unsigned_type (spec->kind);
1284 : 1009 : break;
1285 : :
1286 : 129870 : case BT_REAL:
1287 : 129870 : basetype = gfc_get_real_type (spec->kind);
1288 : 129870 : break;
1289 : :
1290 : 24924 : case BT_COMPLEX:
1291 : 24924 : basetype = gfc_get_complex_type (spec->kind);
1292 : 24924 : break;
1293 : :
1294 : 308720 : case BT_LOGICAL:
1295 : 308720 : basetype = gfc_get_logical_type (spec->kind);
1296 : 308720 : break;
1297 : :
1298 : 57634 : case BT_CHARACTER:
1299 : 57634 : basetype = gfc_get_character_type (spec->kind, spec->u.cl);
1300 : 57634 : break;
1301 : :
1302 : 12 : case BT_HOLLERITH:
1303 : : /* Since this cannot be used, return a length one character. */
1304 : 12 : basetype = gfc_get_character_type_len (gfc_default_character_kind,
1305 : : gfc_index_one_node);
1306 : 12 : break;
1307 : :
1308 : 116 : case BT_UNION:
1309 : 116 : basetype = gfc_get_union_type (spec->u.derived);
1310 : 116 : break;
1311 : :
1312 : 135525 : case BT_DERIVED:
1313 : 135525 : case BT_CLASS:
1314 : 135525 : basetype = gfc_get_derived_type (spec->u.derived, codim);
1315 : :
1316 : 135525 : if (spec->type == BT_CLASS)
1317 : 27097 : GFC_CLASS_TYPE_P (basetype) = 1;
1318 : :
1319 : : /* If we're dealing with either C_PTR or C_FUNPTR, we modified the
1320 : : type and kind to fit a (void *) and the basetype returned was a
1321 : : ptr_type_node. We need to pass up this new information to the
1322 : : symbol that was declared of type C_PTR or C_FUNPTR. */
1323 : 135525 : if (spec->u.derived->ts.f90_type == BT_VOID)
1324 : : {
1325 : 10963 : spec->type = BT_INTEGER;
1326 : 10963 : spec->kind = gfc_index_integer_kind;
1327 : 10963 : spec->f90_type = BT_VOID;
1328 : 10963 : spec->is_c_interop = 1; /* Mark as escaping later. */
1329 : : }
1330 : : break;
1331 : 2764 : case BT_VOID:
1332 : 2764 : case BT_ASSUMED:
1333 : : /* This is for the second arg to c_f_pointer and c_f_procpointer
1334 : : of the iso_c_binding module, to accept any ptr type. */
1335 : 2764 : basetype = ptr_type_node;
1336 : 2764 : if (spec->f90_type == BT_VOID)
1337 : : {
1338 : 338 : if (spec->u.derived
1339 : 0 : && spec->u.derived->intmod_sym_id == ISOCBINDING_PTR)
1340 : : basetype = ptr_type_node;
1341 : : else
1342 : 338 : basetype = pfunc_type_node;
1343 : : }
1344 : : break;
1345 : 20 : case BT_PROCEDURE:
1346 : 20 : basetype = pfunc_type_node;
1347 : 20 : break;
1348 : 0 : default:
1349 : 0 : gcc_unreachable ();
1350 : : }
1351 : 1062637 : return basetype;
1352 : : }
1353 : :
1354 : : /* Build an INT_CST for constant expressions, otherwise return NULL_TREE. */
1355 : :
1356 : : static tree
1357 : 95224 : gfc_conv_array_bound (gfc_expr * expr)
1358 : : {
1359 : : /* If expr is an integer constant, return that. */
1360 : 95224 : if (expr != NULL && expr->expr_type == EXPR_CONSTANT)
1361 : 12862 : return gfc_conv_mpz_to_tree (expr->value.integer, gfc_index_integer_kind);
1362 : :
1363 : : /* Otherwise return NULL. */
1364 : : return NULL_TREE;
1365 : : }
1366 : :
1367 : : /* Return the type of an element of the array. Note that scalar coarrays
1368 : : are special. In particular, for GFC_ARRAY_TYPE_P, the original argument
1369 : : (with POINTER_TYPE stripped) is returned. */
1370 : :
1371 : : tree
1372 : 290916 : gfc_get_element_type (tree type)
1373 : : {
1374 : 290916 : tree element;
1375 : :
1376 : 290916 : if (GFC_ARRAY_TYPE_P (type))
1377 : : {
1378 : 111001 : if (TREE_CODE (type) == POINTER_TYPE)
1379 : 19671 : type = TREE_TYPE (type);
1380 : 111001 : if (GFC_TYPE_ARRAY_RANK (type) == 0)
1381 : : {
1382 : 294 : gcc_assert (GFC_TYPE_ARRAY_CORANK (type) > 0);
1383 : : element = type;
1384 : : }
1385 : : else
1386 : : {
1387 : 110707 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
1388 : 110707 : element = TREE_TYPE (type);
1389 : : }
1390 : : }
1391 : : else
1392 : : {
1393 : 179915 : gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
1394 : 179915 : element = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
1395 : :
1396 : 179915 : gcc_assert (TREE_CODE (element) == POINTER_TYPE);
1397 : 179915 : element = TREE_TYPE (element);
1398 : :
1399 : : /* For arrays, which are not scalar coarrays. */
1400 : 179915 : if (TREE_CODE (element) == ARRAY_TYPE && !TYPE_STRING_FLAG (element))
1401 : 178654 : element = TREE_TYPE (element);
1402 : : }
1403 : :
1404 : 290916 : return element;
1405 : : }
1406 : :
1407 : : /* Build an array. This function is called from gfc_sym_type().
1408 : : Actually returns array descriptor type.
1409 : :
1410 : : Format of array descriptors is as follows:
1411 : :
1412 : : struct gfc_array_descriptor
1413 : : {
1414 : : array *data;
1415 : : index offset;
1416 : : struct dtype_type dtype;
1417 : : struct descriptor_dimension dimension[N_DIM];
1418 : : }
1419 : :
1420 : : struct dtype_type
1421 : : {
1422 : : size_t elem_len;
1423 : : int version;
1424 : : signed char rank;
1425 : : signed char type;
1426 : : signed short attribute;
1427 : : }
1428 : :
1429 : : struct descriptor_dimension
1430 : : {
1431 : : index stride;
1432 : : index lbound;
1433 : : index ubound;
1434 : : }
1435 : :
1436 : : Translation code should use gfc_conv_descriptor_* rather than
1437 : : accessing the descriptor directly. Any changes to the array
1438 : : descriptor type will require changes in gfc_conv_descriptor_* and
1439 : : gfc_build_array_initializer.
1440 : :
1441 : : This is represented internally as a RECORD_TYPE. The index nodes
1442 : : are gfc_array_index_type and the data node is a pointer to the
1443 : : data. See below for the handling of character types.
1444 : :
1445 : : I originally used nested ARRAY_TYPE nodes to represent arrays, but
1446 : : this generated poor code for assumed/deferred size arrays. These
1447 : : require use of PLACEHOLDER_EXPR/WITH_RECORD_EXPR, which isn't part
1448 : : of the GENERIC grammar. Also, there is no way to explicitly set
1449 : : the array stride, so all data must be packed(1). I've tried to
1450 : : mark all the functions which would require modification with a GCC
1451 : : ARRAYS comment.
1452 : :
1453 : : The data component points to the first element in the array. The
1454 : : offset field is the position of the origin of the array (i.e. element
1455 : : (0, 0 ...)). This may be outside the bounds of the array.
1456 : :
1457 : : An element is accessed by
1458 : : data[offset + index0*stride0 + index1*stride1 + index2*stride2]
1459 : : This gives good performance as the computation does not involve the
1460 : : bounds of the array. For packed arrays, this is optimized further
1461 : : by substituting the known strides.
1462 : :
1463 : : This system has one problem: all array bounds must be within 2^31
1464 : : elements of the origin (2^63 on 64-bit machines). For example
1465 : : integer, dimension (80000:90000, 80000:90000, 2) :: array
1466 : : may not work properly on 32-bit machines because 80000*80000 >
1467 : : 2^31, so the calculation for stride2 would overflow. This may
1468 : : still work, but I haven't checked, and it relies on the overflow
1469 : : doing the right thing.
1470 : :
1471 : : The way to fix this problem is to access elements as follows:
1472 : : data[(index0-lbound0)*stride0 + (index1-lbound1)*stride1]
1473 : : Obviously this is much slower. I will make this a compile time
1474 : : option, something like -fsmall-array-offsets. Mixing code compiled
1475 : : with and without this switch will work.
1476 : :
1477 : : (1) This can be worked around by modifying the upper bound of the
1478 : : previous dimension. This requires extra fields in the descriptor
1479 : : (both real_ubound and fake_ubound). */
1480 : :
1481 : :
1482 : : /* Returns true if the array sym does not require a descriptor. */
1483 : :
1484 : : bool
1485 : 97610 : gfc_is_nodesc_array (gfc_symbol * sym)
1486 : : {
1487 : 97610 : symbol_attribute *array_attr;
1488 : 97610 : gfc_array_spec *as;
1489 : 97610 : bool is_classarray = IS_CLASS_COARRAY_OR_ARRAY (sym);
1490 : :
1491 : 97610 : array_attr = is_classarray ? &CLASS_DATA (sym)->attr : &sym->attr;
1492 : 97610 : as = is_classarray ? CLASS_DATA (sym)->as : sym->as;
1493 : :
1494 : 97610 : gcc_assert (array_attr->dimension || array_attr->codimension);
1495 : :
1496 : : /* We only want local arrays. */
1497 : 97610 : if ((sym->ts.type != BT_CLASS && sym->attr.pointer)
1498 : 91109 : || (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->attr.class_pointer)
1499 : 91109 : || array_attr->allocatable)
1500 : : return 0;
1501 : :
1502 : : /* We want a descriptor for associate-name arrays that do not have an
1503 : : explicitly known shape already. */
1504 : 81736 : if (sym->assoc && as->type != AS_EXPLICIT)
1505 : : return 0;
1506 : :
1507 : : /* The dummy is stored in sym and not in the component. */
1508 : 80112 : if (sym->attr.dummy)
1509 : 35272 : return as->type != AS_ASSUMED_SHAPE
1510 : 52747 : && as->type != AS_ASSUMED_RANK;
1511 : :
1512 : 44840 : if (sym->attr.result || sym->attr.function)
1513 : : return 0;
1514 : :
1515 : 36049 : gcc_assert (as->type == AS_EXPLICIT || as->cp_was_assumed);
1516 : :
1517 : : return 1;
1518 : : }
1519 : :
1520 : :
1521 : : /* Create an array descriptor type. */
1522 : :
1523 : : static tree
1524 : 43773 : gfc_build_array_type (tree type, gfc_array_spec * as,
1525 : : enum gfc_array_kind akind, bool restricted,
1526 : : bool contiguous, int codim)
1527 : : {
1528 : 43773 : tree lbound[GFC_MAX_DIMENSIONS];
1529 : 43773 : tree ubound[GFC_MAX_DIMENSIONS];
1530 : 43773 : int n, corank;
1531 : :
1532 : : /* Assumed-shape arrays do not have codimension information stored in the
1533 : : descriptor. */
1534 : 43773 : corank = MAX (as->corank, codim);
1535 : 43773 : if (as->type == AS_ASSUMED_SHAPE ||
1536 : 6574 : (as->type == AS_ASSUMED_RANK && akind == GFC_ARRAY_ALLOCATABLE))
1537 : 43773 : corank = codim;
1538 : :
1539 : 43773 : if (as->type == AS_ASSUMED_RANK)
1540 : 105184 : for (n = 0; n < GFC_MAX_DIMENSIONS; n++)
1541 : : {
1542 : 98610 : lbound[n] = NULL_TREE;
1543 : 98610 : ubound[n] = NULL_TREE;
1544 : : }
1545 : :
1546 : 97913 : for (n = 0; n < as->rank; n++)
1547 : : {
1548 : : /* Create expressions for the known bounds of the array. */
1549 : 54140 : if (as->type == AS_ASSUMED_SHAPE && as->lower[n] == NULL)
1550 : 14029 : lbound[n] = gfc_index_one_node;
1551 : : else
1552 : 40111 : lbound[n] = gfc_conv_array_bound (as->lower[n]);
1553 : 54140 : ubound[n] = gfc_conv_array_bound (as->upper[n]);
1554 : : }
1555 : :
1556 : 44607 : for (n = as->rank; n < as->rank + corank; n++)
1557 : : {
1558 : 834 : if (as->type != AS_DEFERRED && as->lower[n] == NULL)
1559 : 16 : lbound[n] = gfc_index_one_node;
1560 : : else
1561 : 818 : lbound[n] = gfc_conv_array_bound (as->lower[n]);
1562 : :
1563 : 834 : if (n < as->rank + corank - 1)
1564 : 155 : ubound[n] = gfc_conv_array_bound (as->upper[n]);
1565 : : }
1566 : :
1567 : 43773 : if (as->type == AS_ASSUMED_SHAPE)
1568 : 14913 : akind = contiguous ? GFC_ARRAY_ASSUMED_SHAPE_CONT
1569 : : : GFC_ARRAY_ASSUMED_SHAPE;
1570 : 28860 : else if (as->type == AS_ASSUMED_RANK)
1571 : 6574 : akind = contiguous ? GFC_ARRAY_ASSUMED_RANK_CONT
1572 : : : GFC_ARRAY_ASSUMED_RANK;
1573 : 80972 : return gfc_get_array_type_bounds (type, as->rank == -1
1574 : : ? GFC_MAX_DIMENSIONS : as->rank,
1575 : : corank, lbound, ubound, 0, akind,
1576 : 43773 : restricted);
1577 : : }
1578 : :
1579 : : /* Returns the struct descriptor_dimension type. */
1580 : :
1581 : : static tree
1582 : 28018 : gfc_get_desc_dim_type (void)
1583 : : {
1584 : 28018 : tree type;
1585 : 28018 : tree decl, *chain = NULL;
1586 : :
1587 : 28018 : if (gfc_desc_dim_type)
1588 : : return gfc_desc_dim_type;
1589 : :
1590 : : /* Build the type node. */
1591 : 10996 : type = make_node (RECORD_TYPE);
1592 : :
1593 : 10996 : TYPE_NAME (type) = get_identifier ("descriptor_dimension");
1594 : 10996 : TYPE_PACKED (type) = 1;
1595 : :
1596 : : /* Consists of the stride, lbound and ubound members. */
1597 : 10996 : decl = gfc_add_field_to_struct_1 (type,
1598 : : get_identifier ("stride"),
1599 : : gfc_array_index_type, &chain);
1600 : 10996 : suppress_warning (decl);
1601 : :
1602 : 10996 : decl = gfc_add_field_to_struct_1 (type,
1603 : : get_identifier ("lbound"),
1604 : : gfc_array_index_type, &chain);
1605 : 10996 : suppress_warning (decl);
1606 : :
1607 : 10996 : decl = gfc_add_field_to_struct_1 (type,
1608 : : get_identifier ("ubound"),
1609 : : gfc_array_index_type, &chain);
1610 : 10996 : suppress_warning (decl);
1611 : :
1612 : : /* Finish off the type. */
1613 : 10996 : gfc_finish_type (type);
1614 : 10996 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) = 1;
1615 : :
1616 : 10996 : gfc_desc_dim_type = type;
1617 : 10996 : return type;
1618 : : }
1619 : :
1620 : :
1621 : : /* Return the DTYPE for an array. This describes the type and type parameters
1622 : : of the array. */
1623 : : /* TODO: Only call this when the value is actually used, and make all the
1624 : : unknown cases abort. */
1625 : :
1626 : : tree
1627 : 125692 : gfc_get_dtype_rank_type (int rank, tree etype)
1628 : : {
1629 : 125692 : tree ptype;
1630 : 125692 : tree size;
1631 : 125692 : int n;
1632 : 125692 : tree tmp;
1633 : 125692 : tree dtype;
1634 : 125692 : tree field;
1635 : 125692 : vec<constructor_elt, va_gc> *v = NULL;
1636 : :
1637 : 125692 : ptype = etype;
1638 : 125692 : while (TREE_CODE (etype) == POINTER_TYPE
1639 : 153340 : || TREE_CODE (etype) == ARRAY_TYPE)
1640 : : {
1641 : 27648 : ptype = etype;
1642 : 27648 : etype = TREE_TYPE (etype);
1643 : : }
1644 : :
1645 : 125692 : gcc_assert (etype);
1646 : :
1647 : 125692 : switch (TREE_CODE (etype))
1648 : : {
1649 : 74099 : case INTEGER_TYPE:
1650 : 74099 : if (TREE_CODE (ptype) == ARRAY_TYPE
1651 : 74099 : && TYPE_STRING_FLAG (ptype))
1652 : : n = BT_CHARACTER;
1653 : : else
1654 : : {
1655 : 52094 : if (TYPE_UNSIGNED (etype))
1656 : : n = BT_UNSIGNED;
1657 : : else
1658 : : n = BT_INTEGER;
1659 : : }
1660 : : break;
1661 : :
1662 : : case BOOLEAN_TYPE:
1663 : : n = BT_LOGICAL;
1664 : : break;
1665 : :
1666 : : case REAL_TYPE:
1667 : : n = BT_REAL;
1668 : : break;
1669 : :
1670 : : case COMPLEX_TYPE:
1671 : : n = BT_COMPLEX;
1672 : : break;
1673 : :
1674 : 17473 : case RECORD_TYPE:
1675 : 17473 : if (GFC_CLASS_TYPE_P (etype))
1676 : : n = BT_CLASS;
1677 : : else
1678 : : n = BT_DERIVED;
1679 : : break;
1680 : :
1681 : 1687 : case FUNCTION_TYPE:
1682 : 1687 : case VOID_TYPE:
1683 : 1687 : n = BT_VOID;
1684 : 1687 : break;
1685 : :
1686 : 0 : default:
1687 : : /* TODO: Don't do dtype for temporary descriptorless arrays. */
1688 : : /* We can encounter strange array types for temporary arrays. */
1689 : 0 : gcc_unreachable ();
1690 : : }
1691 : :
1692 : 23692 : switch (n)
1693 : : {
1694 : 22005 : case BT_CHARACTER:
1695 : 22005 : gcc_assert (TREE_CODE (ptype) == ARRAY_TYPE);
1696 : 22005 : size = gfc_get_character_len_in_bytes (ptype);
1697 : 22005 : break;
1698 : 1687 : case BT_VOID:
1699 : 1687 : gcc_assert (TREE_CODE (ptype) == POINTER_TYPE);
1700 : 1687 : size = size_in_bytes (ptype);
1701 : 1687 : break;
1702 : 102000 : default:
1703 : 102000 : size = size_in_bytes (etype);
1704 : 102000 : break;
1705 : : }
1706 : :
1707 : 125692 : gcc_assert (size);
1708 : :
1709 : 125692 : STRIP_NOPS (size);
1710 : 125692 : size = fold_convert (size_type_node, size);
1711 : 125692 : tmp = get_dtype_type_node ();
1712 : 125692 : field = gfc_advance_chain (TYPE_FIELDS (tmp),
1713 : : GFC_DTYPE_ELEM_LEN);
1714 : 125692 : CONSTRUCTOR_APPEND_ELT (v, field,
1715 : : fold_convert (TREE_TYPE (field), size));
1716 : 125692 : field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
1717 : : GFC_DTYPE_VERSION);
1718 : 125692 : CONSTRUCTOR_APPEND_ELT (v, field,
1719 : : build_zero_cst (TREE_TYPE (field)));
1720 : :
1721 : 125692 : field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
1722 : : GFC_DTYPE_RANK);
1723 : 125692 : if (rank >= 0)
1724 : 125105 : CONSTRUCTOR_APPEND_ELT (v, field,
1725 : : build_int_cst (TREE_TYPE (field), rank));
1726 : :
1727 : 125692 : field = gfc_advance_chain (TYPE_FIELDS (dtype_type_node),
1728 : : GFC_DTYPE_TYPE);
1729 : 125692 : CONSTRUCTOR_APPEND_ELT (v, field,
1730 : : build_int_cst (TREE_TYPE (field), n));
1731 : :
1732 : 125692 : dtype = build_constructor (tmp, v);
1733 : :
1734 : 125692 : return dtype;
1735 : : }
1736 : :
1737 : :
1738 : : tree
1739 : 101563 : gfc_get_dtype (tree type, int * rank)
1740 : : {
1741 : 101563 : tree dtype;
1742 : 101563 : tree etype;
1743 : 101563 : int irnk;
1744 : :
1745 : 101563 : gcc_assert (GFC_DESCRIPTOR_TYPE_P (type) || GFC_ARRAY_TYPE_P (type));
1746 : :
1747 : 101563 : irnk = (rank) ? (*rank) : (GFC_TYPE_ARRAY_RANK (type));
1748 : 101563 : etype = gfc_get_element_type (type);
1749 : 101563 : dtype = gfc_get_dtype_rank_type (irnk, etype);
1750 : :
1751 : 101563 : GFC_TYPE_ARRAY_DTYPE (type) = dtype;
1752 : 101563 : return dtype;
1753 : : }
1754 : :
1755 : :
1756 : : /* Build an array type for use without a descriptor, packed according
1757 : : to the value of PACKED. */
1758 : :
1759 : : tree
1760 : 100467 : gfc_get_nodesc_array_type (tree etype, gfc_array_spec * as, gfc_packed packed,
1761 : : bool restricted)
1762 : : {
1763 : 100467 : tree range;
1764 : 100467 : tree type;
1765 : 100467 : tree tmp;
1766 : 100467 : int n;
1767 : 100467 : int known_stride;
1768 : 100467 : int known_offset;
1769 : 100467 : mpz_t offset;
1770 : 100467 : mpz_t stride;
1771 : 100467 : mpz_t delta;
1772 : 100467 : gfc_expr *expr;
1773 : :
1774 : 100467 : mpz_init_set_ui (offset, 0);
1775 : 100467 : mpz_init_set_ui (stride, 1);
1776 : 100467 : mpz_init (delta);
1777 : :
1778 : : /* We don't use build_array_type because this does not include
1779 : : lang-specific information (i.e. the bounds of the array) when checking
1780 : : for duplicates. */
1781 : 100467 : if (as->rank)
1782 : 100171 : type = make_node (ARRAY_TYPE);
1783 : : else
1784 : 296 : type = build_variant_type_copy (etype);
1785 : :
1786 : 100467 : GFC_ARRAY_TYPE_P (type) = 1;
1787 : 100467 : TYPE_LANG_SPECIFIC (type) = ggc_cleared_alloc<struct lang_type> ();
1788 : :
1789 : 100467 : known_stride = (packed != PACKED_NO);
1790 : 100467 : known_offset = 1;
1791 : 218144 : for (n = 0; n < as->rank; n++)
1792 : : {
1793 : : /* Fill in the stride and bound components of the type. */
1794 : 117677 : if (known_stride)
1795 : 105081 : tmp = gfc_conv_mpz_to_tree (stride, gfc_index_integer_kind);
1796 : : else
1797 : : tmp = NULL_TREE;
1798 : 117677 : GFC_TYPE_ARRAY_STRIDE (type, n) = tmp;
1799 : :
1800 : 117677 : expr = as->lower[n];
1801 : 117677 : if (expr && expr->expr_type == EXPR_CONSTANT)
1802 : : {
1803 : 116885 : tmp = gfc_conv_mpz_to_tree (expr->value.integer,
1804 : : gfc_index_integer_kind);
1805 : : }
1806 : : else
1807 : : {
1808 : : known_stride = 0;
1809 : : tmp = NULL_TREE;
1810 : : }
1811 : 117677 : GFC_TYPE_ARRAY_LBOUND (type, n) = tmp;
1812 : :
1813 : 117677 : if (known_stride)
1814 : : {
1815 : : /* Calculate the offset. */
1816 : 104620 : mpz_mul (delta, stride, as->lower[n]->value.integer);
1817 : 104620 : mpz_sub (offset, offset, delta);
1818 : : }
1819 : : else
1820 : : known_offset = 0;
1821 : :
1822 : 117677 : expr = as->upper[n];
1823 : 117677 : if (expr && expr->expr_type == EXPR_CONSTANT)
1824 : : {
1825 : 92618 : tmp = gfc_conv_mpz_to_tree (expr->value.integer,
1826 : : gfc_index_integer_kind);
1827 : : }
1828 : : else
1829 : : {
1830 : : tmp = NULL_TREE;
1831 : : known_stride = 0;
1832 : : }
1833 : 117677 : GFC_TYPE_ARRAY_UBOUND (type, n) = tmp;
1834 : :
1835 : 117677 : if (known_stride)
1836 : : {
1837 : : /* Calculate the stride. */
1838 : 91708 : mpz_sub (delta, as->upper[n]->value.integer,
1839 : 91708 : as->lower[n]->value.integer);
1840 : 91708 : mpz_add_ui (delta, delta, 1);
1841 : 91708 : mpz_mul (stride, stride, delta);
1842 : : }
1843 : :
1844 : : /* Only the first stride is known for partial packed arrays. */
1845 : 117677 : if (packed == PACKED_NO || packed == PACKED_PARTIAL)
1846 : 9665 : known_stride = 0;
1847 : : }
1848 : 101258 : for (n = as->rank; n < as->rank + as->corank; n++)
1849 : : {
1850 : 791 : expr = as->lower[n];
1851 : 791 : if (expr && expr->expr_type == EXPR_CONSTANT)
1852 : 695 : tmp = gfc_conv_mpz_to_tree (expr->value.integer,
1853 : : gfc_index_integer_kind);
1854 : : else
1855 : : tmp = NULL_TREE;
1856 : 791 : GFC_TYPE_ARRAY_LBOUND (type, n) = tmp;
1857 : :
1858 : 791 : expr = as->upper[n];
1859 : 791 : if (expr && expr->expr_type == EXPR_CONSTANT)
1860 : 148 : tmp = gfc_conv_mpz_to_tree (expr->value.integer,
1861 : : gfc_index_integer_kind);
1862 : : else
1863 : : tmp = NULL_TREE;
1864 : 791 : if (n < as->rank + as->corank - 1)
1865 : 198 : GFC_TYPE_ARRAY_UBOUND (type, n) = tmp;
1866 : : }
1867 : :
1868 : 100467 : if (known_offset)
1869 : : {
1870 : 90525 : GFC_TYPE_ARRAY_OFFSET (type) =
1871 : 90525 : gfc_conv_mpz_to_tree (offset, gfc_index_integer_kind);
1872 : : }
1873 : : else
1874 : 9942 : GFC_TYPE_ARRAY_OFFSET (type) = NULL_TREE;
1875 : :
1876 : 100467 : if (known_stride)
1877 : : {
1878 : 73795 : GFC_TYPE_ARRAY_SIZE (type) =
1879 : 73795 : gfc_conv_mpz_to_tree (stride, gfc_index_integer_kind);
1880 : : }
1881 : : else
1882 : 26672 : GFC_TYPE_ARRAY_SIZE (type) = NULL_TREE;
1883 : :
1884 : 100467 : GFC_TYPE_ARRAY_RANK (type) = as->rank;
1885 : 100467 : GFC_TYPE_ARRAY_CORANK (type) = as->corank;
1886 : 100467 : GFC_TYPE_ARRAY_DTYPE (type) = NULL_TREE;
1887 : 100467 : range = build_range_type (gfc_array_index_type, gfc_index_zero_node,
1888 : : NULL_TREE);
1889 : : /* TODO: use main type if it is unbounded. */
1890 : 100467 : GFC_TYPE_ARRAY_DATAPTR_TYPE (type) =
1891 : 100467 : build_pointer_type (build_array_type (etype, range));
1892 : 100467 : if (restricted)
1893 : 97521 : GFC_TYPE_ARRAY_DATAPTR_TYPE (type) =
1894 : 97521 : build_qualified_type (GFC_TYPE_ARRAY_DATAPTR_TYPE (type),
1895 : : TYPE_QUAL_RESTRICT);
1896 : :
1897 : 100467 : if (as->rank == 0)
1898 : : {
1899 : 296 : if (packed != PACKED_STATIC || flag_coarray == GFC_FCOARRAY_LIB)
1900 : : {
1901 : 240 : type = build_pointer_type (type);
1902 : :
1903 : 240 : if (restricted)
1904 : 240 : type = build_qualified_type (type, TYPE_QUAL_RESTRICT);
1905 : :
1906 : 240 : GFC_ARRAY_TYPE_P (type) = 1;
1907 : 240 : TYPE_LANG_SPECIFIC (type) = TYPE_LANG_SPECIFIC (TREE_TYPE (type));
1908 : : }
1909 : :
1910 : 296 : goto array_type_done;
1911 : : }
1912 : :
1913 : 100171 : if (known_stride)
1914 : : {
1915 : 73530 : mpz_sub_ui (stride, stride, 1);
1916 : 73530 : range = gfc_conv_mpz_to_tree (stride, gfc_index_integer_kind);
1917 : : }
1918 : : else
1919 : : range = NULL_TREE;
1920 : :
1921 : 100171 : range = build_range_type (gfc_array_index_type, gfc_index_zero_node, range);
1922 : 100171 : TYPE_DOMAIN (type) = range;
1923 : :
1924 : 100171 : build_pointer_type (etype);
1925 : 100171 : TREE_TYPE (type) = etype;
1926 : :
1927 : 100171 : layout_type (type);
1928 : :
1929 : : /* Represent packed arrays as multi-dimensional if they have rank >
1930 : : 1 and with proper bounds, instead of flat arrays. This makes for
1931 : : better debug info. */
1932 : 100171 : if (known_offset)
1933 : : {
1934 : 90229 : tree gtype = etype, rtype, type_decl;
1935 : :
1936 : 192331 : for (n = as->rank - 1; n >= 0; n--)
1937 : : {
1938 : 408408 : rtype = build_range_type (gfc_array_index_type,
1939 : 102102 : GFC_TYPE_ARRAY_LBOUND (type, n),
1940 : 102102 : GFC_TYPE_ARRAY_UBOUND (type, n));
1941 : 102102 : gtype = build_array_type (gtype, rtype);
1942 : : }
1943 : 90229 : TYPE_NAME (type) = type_decl = build_decl (input_location,
1944 : : TYPE_DECL, NULL, gtype);
1945 : 90229 : DECL_ORIGINAL_TYPE (type_decl) = gtype;
1946 : : }
1947 : :
1948 : 100171 : if (packed != PACKED_STATIC || !known_stride
1949 : 69682 : || (as->corank && flag_coarray == GFC_FCOARRAY_LIB))
1950 : : {
1951 : : /* For dummy arrays and automatic (heap allocated) arrays we
1952 : : want a pointer to the array. */
1953 : 30559 : type = build_pointer_type (type);
1954 : 30559 : if (restricted)
1955 : 29382 : type = build_qualified_type (type, TYPE_QUAL_RESTRICT);
1956 : 30559 : GFC_ARRAY_TYPE_P (type) = 1;
1957 : 30559 : TYPE_LANG_SPECIFIC (type) = TYPE_LANG_SPECIFIC (TREE_TYPE (type));
1958 : : }
1959 : :
1960 : 69612 : array_type_done:
1961 : 100467 : mpz_clear (offset);
1962 : 100467 : mpz_clear (stride);
1963 : 100467 : mpz_clear (delta);
1964 : :
1965 : 100467 : return type;
1966 : : }
1967 : :
1968 : :
1969 : : /* Return or create the base type for an array descriptor. */
1970 : :
1971 : : static tree
1972 : 263672 : gfc_get_array_descriptor_base (int dimen, int codimen, bool restricted)
1973 : : {
1974 : 263672 : tree fat_type, decl, arraytype, *chain = NULL;
1975 : 263672 : char name[16 + 2*GFC_RANK_DIGITS + 1 + 1];
1976 : 263672 : int idx;
1977 : :
1978 : : /* Assumed-rank array. */
1979 : 263672 : if (dimen == -1)
1980 : 0 : dimen = GFC_MAX_DIMENSIONS;
1981 : :
1982 : 263672 : idx = 2 * (codimen + dimen) + restricted;
1983 : :
1984 : 263672 : gcc_assert (codimen + dimen >= 0 && codimen + dimen <= GFC_MAX_DIMENSIONS);
1985 : :
1986 : 263672 : if (flag_coarray == GFC_FCOARRAY_LIB && codimen)
1987 : : {
1988 : 858 : if (gfc_array_descriptor_base_caf[idx])
1989 : : return gfc_array_descriptor_base_caf[idx];
1990 : : }
1991 : 262814 : else if (gfc_array_descriptor_base[idx])
1992 : : return gfc_array_descriptor_base[idx];
1993 : :
1994 : : /* Build the type node. */
1995 : 30692 : fat_type = make_node (RECORD_TYPE);
1996 : :
1997 : 30692 : sprintf (name, "array_descriptor" GFC_RANK_PRINTF_FORMAT, dimen + codimen);
1998 : 30692 : TYPE_NAME (fat_type) = get_identifier (name);
1999 : 30692 : TYPE_NAMELESS (fat_type) = 1;
2000 : :
2001 : : /* Add the data member as the first element of the descriptor. */
2002 : 30692 : gfc_add_field_to_struct_1 (fat_type,
2003 : : get_identifier ("data"),
2004 : : (restricted
2005 : : ? prvoid_type_node
2006 : : : ptr_type_node), &chain);
2007 : :
2008 : : /* Add the base component. */
2009 : 30692 : decl = gfc_add_field_to_struct_1 (fat_type,
2010 : : get_identifier ("offset"),
2011 : : gfc_array_index_type, &chain);
2012 : 30692 : suppress_warning (decl);
2013 : :
2014 : : /* Add the dtype component. */
2015 : 30692 : decl = gfc_add_field_to_struct_1 (fat_type,
2016 : : get_identifier ("dtype"),
2017 : : get_dtype_type_node (), &chain);
2018 : 30692 : suppress_warning (decl);
2019 : :
2020 : : /* Add the span component. */
2021 : 30692 : decl = gfc_add_field_to_struct_1 (fat_type,
2022 : : get_identifier ("span"),
2023 : : gfc_array_index_type, &chain);
2024 : 30692 : suppress_warning (decl);
2025 : :
2026 : : /* Build the array type for the stride and bound components. */
2027 : 30692 : if (dimen + codimen > 0)
2028 : : {
2029 : 28018 : arraytype =
2030 : 28018 : build_array_type (gfc_get_desc_dim_type (),
2031 : : build_range_type (gfc_array_index_type,
2032 : : gfc_index_zero_node,
2033 : 28018 : gfc_rank_cst[codimen + dimen - 1]));
2034 : :
2035 : 28018 : decl = gfc_add_field_to_struct_1 (fat_type, get_identifier ("dim"),
2036 : : arraytype, &chain);
2037 : 28018 : suppress_warning (decl);
2038 : : }
2039 : :
2040 : 30692 : if (flag_coarray == GFC_FCOARRAY_LIB)
2041 : : {
2042 : 1065 : decl = gfc_add_field_to_struct_1 (fat_type,
2043 : : get_identifier ("token"),
2044 : : prvoid_type_node, &chain);
2045 : 1065 : suppress_warning (decl);
2046 : : }
2047 : :
2048 : : /* Finish off the type. */
2049 : 30692 : gfc_finish_type (fat_type);
2050 : 30692 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (fat_type)) = 1;
2051 : :
2052 : 30692 : if (flag_coarray == GFC_FCOARRAY_LIB && codimen)
2053 : 288 : gfc_array_descriptor_base_caf[idx] = fat_type;
2054 : : else
2055 : 30404 : gfc_array_descriptor_base[idx] = fat_type;
2056 : :
2057 : : return fat_type;
2058 : : }
2059 : :
2060 : :
2061 : : /* Build an array (descriptor) type with given bounds. */
2062 : :
2063 : : tree
2064 : 131836 : gfc_get_array_type_bounds (tree etype, int dimen, int codimen, tree * lbound,
2065 : : tree * ubound, int packed,
2066 : : enum gfc_array_kind akind, bool restricted)
2067 : : {
2068 : 131836 : char name[8 + 2*GFC_RANK_DIGITS + 1 + GFC_MAX_SYMBOL_LEN];
2069 : 131836 : tree fat_type, base_type, arraytype, lower, upper, stride, tmp, rtype;
2070 : 131836 : const char *type_name;
2071 : 131836 : int n;
2072 : :
2073 : 131836 : base_type = gfc_get_array_descriptor_base (dimen, codimen, restricted);
2074 : 131836 : fat_type = build_distinct_type_copy (base_type);
2075 : : /* Unshare TYPE_FIELDs. */
2076 : 787722 : for (tree *tp = &TYPE_FIELDS (fat_type); *tp; tp = &DECL_CHAIN (*tp))
2077 : : {
2078 : 655886 : tree next = DECL_CHAIN (*tp);
2079 : 655886 : *tp = copy_node (*tp);
2080 : 655886 : DECL_CONTEXT (*tp) = fat_type;
2081 : 655886 : DECL_CHAIN (*tp) = next;
2082 : : }
2083 : : /* Make sure that nontarget and target array type have the same canonical
2084 : : type (and same stub decl for debug info). */
2085 : 131836 : base_type = gfc_get_array_descriptor_base (dimen, codimen, false);
2086 : 131836 : TYPE_CANONICAL (fat_type) = base_type;
2087 : 131836 : TYPE_STUB_DECL (fat_type) = TYPE_STUB_DECL (base_type);
2088 : : /* Arrays of unknown type must alias with all array descriptors. */
2089 : 131836 : TYPE_TYPELESS_STORAGE (base_type) = 1;
2090 : 131836 : TYPE_TYPELESS_STORAGE (fat_type) = 1;
2091 : 131836 : gcc_checking_assert (!get_alias_set (base_type) && !get_alias_set (fat_type));
2092 : :
2093 : 131836 : tmp = etype;
2094 : 131836 : if (TREE_CODE (tmp) == ARRAY_TYPE
2095 : 131836 : && TYPE_STRING_FLAG (tmp))
2096 : 22392 : tmp = TREE_TYPE (etype);
2097 : 131836 : tmp = TYPE_NAME (tmp);
2098 : 131836 : if (tmp && TREE_CODE (tmp) == TYPE_DECL)
2099 : 111067 : tmp = DECL_NAME (tmp);
2100 : 111067 : if (tmp)
2101 : 129096 : type_name = IDENTIFIER_POINTER (tmp);
2102 : : else
2103 : : type_name = "unknown";
2104 : 131836 : sprintf (name, "array" GFC_RANK_PRINTF_FORMAT "_%.*s", dimen + codimen,
2105 : : GFC_MAX_SYMBOL_LEN, type_name);
2106 : 131836 : TYPE_NAME (fat_type) = get_identifier (name);
2107 : 131836 : TYPE_NAMELESS (fat_type) = 1;
2108 : :
2109 : 131836 : GFC_DESCRIPTOR_TYPE_P (fat_type) = 1;
2110 : 131836 : TYPE_LANG_SPECIFIC (fat_type) = ggc_cleared_alloc<struct lang_type> ();
2111 : :
2112 : 131836 : GFC_TYPE_ARRAY_RANK (fat_type) = dimen;
2113 : 131836 : GFC_TYPE_ARRAY_CORANK (fat_type) = codimen;
2114 : 131836 : GFC_TYPE_ARRAY_DTYPE (fat_type) = NULL_TREE;
2115 : 131836 : GFC_TYPE_ARRAY_AKIND (fat_type) = akind;
2116 : :
2117 : : /* Build an array descriptor record type. */
2118 : 131836 : if (packed != 0)
2119 : 30907 : stride = gfc_index_one_node;
2120 : : else
2121 : : stride = NULL_TREE;
2122 : 404146 : for (n = 0; n < dimen + codimen; n++)
2123 : : {
2124 : 273404 : if (n < dimen)
2125 : 271627 : GFC_TYPE_ARRAY_STRIDE (fat_type, n) = stride;
2126 : :
2127 : 273404 : if (lbound)
2128 : 273404 : lower = lbound[n];
2129 : : else
2130 : : lower = NULL_TREE;
2131 : :
2132 : 273404 : if (lower != NULL_TREE)
2133 : : {
2134 : 145644 : if (INTEGER_CST_P (lower))
2135 : 144558 : GFC_TYPE_ARRAY_LBOUND (fat_type, n) = lower;
2136 : : else
2137 : : lower = NULL_TREE;
2138 : : }
2139 : :
2140 : 273404 : if (codimen && n == dimen + codimen - 1)
2141 : : break;
2142 : :
2143 : 272310 : upper = ubound[n];
2144 : 272310 : if (upper != NULL_TREE)
2145 : : {
2146 : 117672 : if (INTEGER_CST_P (upper))
2147 : 89342 : GFC_TYPE_ARRAY_UBOUND (fat_type, n) = upper;
2148 : : else
2149 : : upper = NULL_TREE;
2150 : : }
2151 : :
2152 : 272310 : if (n >= dimen)
2153 : 683 : continue;
2154 : :
2155 : 271627 : if (upper != NULL_TREE && lower != NULL_TREE && stride != NULL_TREE)
2156 : : {
2157 : 24562 : tmp = fold_build2_loc (input_location, MINUS_EXPR,
2158 : : gfc_array_index_type, upper, lower);
2159 : 24562 : tmp = fold_build2_loc (input_location, PLUS_EXPR,
2160 : : gfc_array_index_type, tmp,
2161 : : gfc_index_one_node);
2162 : 24562 : stride = fold_build2_loc (input_location, MULT_EXPR,
2163 : : gfc_array_index_type, tmp, stride);
2164 : : /* Check the folding worked. */
2165 : 24562 : gcc_assert (INTEGER_CST_P (stride));
2166 : : }
2167 : : else
2168 : : stride = NULL_TREE;
2169 : : }
2170 : 131836 : GFC_TYPE_ARRAY_SIZE (fat_type) = stride;
2171 : :
2172 : : /* TODO: known offsets for descriptors. */
2173 : 131836 : GFC_TYPE_ARRAY_OFFSET (fat_type) = NULL_TREE;
2174 : :
2175 : 131836 : if (dimen == 0)
2176 : : {
2177 : 6414 : arraytype = build_pointer_type (etype);
2178 : 6414 : if (restricted)
2179 : 5948 : arraytype = build_qualified_type (arraytype, TYPE_QUAL_RESTRICT);
2180 : :
2181 : 6414 : GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type) = arraytype;
2182 : 6414 : return fat_type;
2183 : : }
2184 : :
2185 : : /* We define data as an array with the correct size if possible.
2186 : : Much better than doing pointer arithmetic. */
2187 : 125422 : if (stride)
2188 : 19473 : rtype = build_range_type (gfc_array_index_type, gfc_index_zero_node,
2189 : : int_const_binop (MINUS_EXPR, stride,
2190 : 38946 : build_int_cst (TREE_TYPE (stride), 1)));
2191 : : else
2192 : 105949 : rtype = gfc_array_range_type;
2193 : 125422 : arraytype = build_array_type (etype, rtype);
2194 : 125422 : arraytype = build_pointer_type (arraytype);
2195 : 125422 : if (restricted)
2196 : 58209 : arraytype = build_qualified_type (arraytype, TYPE_QUAL_RESTRICT);
2197 : 125422 : GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type) = arraytype;
2198 : :
2199 : : /* This will generate the base declarations we need to emit debug
2200 : : information for this type. FIXME: there must be a better way to
2201 : : avoid divergence between compilations with and without debug
2202 : : information. */
2203 : 125422 : {
2204 : 125422 : struct array_descr_info info;
2205 : 125422 : gfc_get_array_descr_info (fat_type, &info);
2206 : 125422 : gfc_get_array_descr_info (build_pointer_type (fat_type), &info);
2207 : : }
2208 : :
2209 : 125422 : return fat_type;
2210 : : }
2211 : :
2212 : : /* Build a pointer type. This function is called from gfc_sym_type(). */
2213 : :
2214 : : static tree
2215 : 14511 : gfc_build_pointer_type (gfc_symbol * sym, tree type)
2216 : : {
2217 : : /* Array pointer types aren't actually pointers. */
2218 : 0 : if (sym->attr.dimension)
2219 : : return type;
2220 : : else
2221 : 14511 : return build_pointer_type (type);
2222 : : }
2223 : :
2224 : : static tree gfc_nonrestricted_type (tree t);
2225 : : /* Given two record or union type nodes TO and FROM, ensure
2226 : : that all fields in FROM have a corresponding field in TO,
2227 : : their type being nonrestrict variants. This accepts a TO
2228 : : node that already has a prefix of the fields in FROM. */
2229 : : static void
2230 : 2596 : mirror_fields (tree to, tree from)
2231 : : {
2232 : 2596 : tree fto, ffrom;
2233 : 2596 : tree *chain;
2234 : :
2235 : : /* Forward to the end of TOs fields. */
2236 : 2596 : fto = TYPE_FIELDS (to);
2237 : 2596 : ffrom = TYPE_FIELDS (from);
2238 : 2596 : chain = &TYPE_FIELDS (to);
2239 : 2596 : while (fto)
2240 : : {
2241 : 0 : gcc_assert (ffrom && DECL_NAME (fto) == DECL_NAME (ffrom));
2242 : 0 : chain = &DECL_CHAIN (fto);
2243 : 0 : fto = DECL_CHAIN (fto);
2244 : 0 : ffrom = DECL_CHAIN (ffrom);
2245 : : }
2246 : :
2247 : : /* Now add all fields remaining in FROM (starting with ffrom). */
2248 : 11323 : for (; ffrom; ffrom = DECL_CHAIN (ffrom))
2249 : : {
2250 : 8727 : tree newfield = copy_node (ffrom);
2251 : 8727 : DECL_CONTEXT (newfield) = to;
2252 : : /* The store to DECL_CHAIN might seem redundant with the
2253 : : stores to *chain, but not clearing it here would mean
2254 : : leaving a chain into the old fields. If ever
2255 : : our called functions would look at them confusion
2256 : : will arise. */
2257 : 8727 : DECL_CHAIN (newfield) = NULL_TREE;
2258 : 8727 : *chain = newfield;
2259 : 8727 : chain = &DECL_CHAIN (newfield);
2260 : :
2261 : 8727 : if (TREE_CODE (ffrom) == FIELD_DECL)
2262 : : {
2263 : 8727 : tree elemtype = gfc_nonrestricted_type (TREE_TYPE (ffrom));
2264 : 8727 : TREE_TYPE (newfield) = elemtype;
2265 : : }
2266 : : }
2267 : 2596 : *chain = NULL_TREE;
2268 : 2596 : }
2269 : :
2270 : : /* Given a type T, returns a different type of the same structure,
2271 : : except that all types it refers to (recursively) are always
2272 : : non-restrict qualified types. */
2273 : : static tree
2274 : 231339 : gfc_nonrestricted_type (tree t)
2275 : : {
2276 : 231339 : tree ret = t;
2277 : :
2278 : : /* If the type isn't laid out yet, don't copy it. If something
2279 : : needs it for real it should wait until the type got finished. */
2280 : 231339 : if (!TYPE_SIZE (t))
2281 : : return t;
2282 : :
2283 : 220167 : if (!TYPE_LANG_SPECIFIC (t))
2284 : 90337 : TYPE_LANG_SPECIFIC (t) = ggc_cleared_alloc<struct lang_type> ();
2285 : : /* If we're dealing with this very node already further up
2286 : : the call chain (recursion via pointers and struct members)
2287 : : we haven't yet determined if we really need a new type node.
2288 : : Assume we don't, return T itself. */
2289 : 220167 : if (TYPE_LANG_SPECIFIC (t)->nonrestricted_type == error_mark_node)
2290 : : return t;
2291 : :
2292 : : /* If we have calculated this all already, just return it. */
2293 : 212763 : if (TYPE_LANG_SPECIFIC (t)->nonrestricted_type)
2294 : 118783 : return TYPE_LANG_SPECIFIC (t)->nonrestricted_type;
2295 : :
2296 : : /* Mark this type. */
2297 : 93980 : TYPE_LANG_SPECIFIC (t)->nonrestricted_type = error_mark_node;
2298 : :
2299 : 93980 : switch (TREE_CODE (t))
2300 : : {
2301 : : default:
2302 : : break;
2303 : :
2304 : 36534 : case POINTER_TYPE:
2305 : 36534 : case REFERENCE_TYPE:
2306 : 36534 : {
2307 : 36534 : tree totype = gfc_nonrestricted_type (TREE_TYPE (t));
2308 : 36534 : if (totype == TREE_TYPE (t))
2309 : : ret = t;
2310 : 1077 : else if (TREE_CODE (t) == POINTER_TYPE)
2311 : 1077 : ret = build_pointer_type (totype);
2312 : : else
2313 : 0 : ret = build_reference_type (totype);
2314 : 73068 : ret = build_qualified_type (ret,
2315 : 36534 : TYPE_QUALS (t) & ~TYPE_QUAL_RESTRICT);
2316 : : }
2317 : 36534 : break;
2318 : :
2319 : 5320 : case ARRAY_TYPE:
2320 : 5320 : {
2321 : 5320 : tree elemtype = gfc_nonrestricted_type (TREE_TYPE (t));
2322 : 5320 : if (elemtype == TREE_TYPE (t))
2323 : : ret = t;
2324 : : else
2325 : : {
2326 : 17 : ret = build_variant_type_copy (t);
2327 : 17 : TREE_TYPE (ret) = elemtype;
2328 : 17 : if (TYPE_LANG_SPECIFIC (t)
2329 : 17 : && GFC_TYPE_ARRAY_DATAPTR_TYPE (t))
2330 : : {
2331 : 17 : tree dataptr_type = GFC_TYPE_ARRAY_DATAPTR_TYPE (t);
2332 : 17 : dataptr_type = gfc_nonrestricted_type (dataptr_type);
2333 : 17 : if (dataptr_type != GFC_TYPE_ARRAY_DATAPTR_TYPE (t))
2334 : : {
2335 : 17 : TYPE_LANG_SPECIFIC (ret)
2336 : 17 : = ggc_cleared_alloc<struct lang_type> ();
2337 : 17 : *TYPE_LANG_SPECIFIC (ret) = *TYPE_LANG_SPECIFIC (t);
2338 : 17 : GFC_TYPE_ARRAY_DATAPTR_TYPE (ret) = dataptr_type;
2339 : : }
2340 : : }
2341 : : }
2342 : : }
2343 : : break;
2344 : :
2345 : 25186 : case RECORD_TYPE:
2346 : 25186 : case UNION_TYPE:
2347 : 25186 : case QUAL_UNION_TYPE:
2348 : 25186 : {
2349 : 25186 : tree field;
2350 : : /* First determine if we need a new type at all.
2351 : : Careful, the two calls to gfc_nonrestricted_type per field
2352 : : might return different values. That happens exactly when
2353 : : one of the fields reaches back to this very record type
2354 : : (via pointers). The first calls will assume that we don't
2355 : : need to copy T (see the error_mark_node marking). If there
2356 : : are any reasons for copying T apart from having to copy T,
2357 : : we'll indeed copy it, and the second calls to
2358 : : gfc_nonrestricted_type will use that new node if they
2359 : : reach back to T. */
2360 : 128887 : for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
2361 : 106297 : if (TREE_CODE (field) == FIELD_DECL)
2362 : : {
2363 : 106297 : tree elemtype = gfc_nonrestricted_type (TREE_TYPE (field));
2364 : 106297 : if (elemtype != TREE_TYPE (field))
2365 : : break;
2366 : : }
2367 : 25186 : if (!field)
2368 : : break;
2369 : 2596 : ret = build_variant_type_copy (t);
2370 : 2596 : TYPE_FIELDS (ret) = NULL_TREE;
2371 : :
2372 : : /* Here we make sure that as soon as we know we have to copy
2373 : : T, that also fields reaching back to us will use the new
2374 : : copy. It's okay if that copy still contains the old fields,
2375 : : we won't look at them. */
2376 : 2596 : TYPE_LANG_SPECIFIC (t)->nonrestricted_type = ret;
2377 : 2596 : mirror_fields (ret, t);
2378 : : }
2379 : 2596 : break;
2380 : : }
2381 : :
2382 : 93980 : TYPE_LANG_SPECIFIC (t)->nonrestricted_type = ret;
2383 : 93980 : return ret;
2384 : : }
2385 : :
2386 : :
2387 : : /* Return the type for a symbol. Special handling is required for character
2388 : : types to get the correct level of indirection.
2389 : : For functions return the return type.
2390 : : For subroutines return void_type_node.
2391 : : Calling this multiple times for the same symbol should be avoided,
2392 : : especially for character and array types. */
2393 : :
2394 : : tree
2395 : 371412 : gfc_sym_type (gfc_symbol * sym, bool is_bind_c)
2396 : : {
2397 : 371412 : tree type;
2398 : 371412 : int byref;
2399 : 371412 : bool restricted;
2400 : :
2401 : : /* Procedure Pointers inside COMMON blocks. */
2402 : 371412 : if (sym->attr.proc_pointer && sym->attr.in_common)
2403 : : {
2404 : : /* Unset proc_pointer as gfc_get_function_type calls gfc_sym_type. */
2405 : 30 : sym->attr.proc_pointer = 0;
2406 : 30 : type = build_pointer_type (gfc_get_function_type (sym));
2407 : 30 : sym->attr.proc_pointer = 1;
2408 : 30 : return type;
2409 : : }
2410 : :
2411 : 371382 : if (sym->attr.flavor == FL_PROCEDURE && !sym->attr.function)
2412 : 0 : return void_type_node;
2413 : :
2414 : : /* In the case of a function the fake result variable may have a
2415 : : type different from the function type, so don't return early in
2416 : : that case. */
2417 : 371382 : if (sym->backend_decl && !sym->attr.function)
2418 : 445 : return TREE_TYPE (sym->backend_decl);
2419 : :
2420 : 370937 : if (sym->attr.result
2421 : 5606 : && sym->ts.type == BT_CHARACTER
2422 : 1131 : && sym->ts.u.cl->backend_decl == NULL_TREE
2423 : 493 : && sym->ns->proc_name
2424 : 487 : && sym->ns->proc_name->ts.u.cl
2425 : 485 : && sym->ns->proc_name->ts.u.cl->backend_decl != NULL_TREE)
2426 : 6 : sym->ts.u.cl->backend_decl = sym->ns->proc_name->ts.u.cl->backend_decl;
2427 : :
2428 : 370937 : if (sym->ts.type == BT_CHARACTER
2429 : 370937 : && ((sym->attr.function && sym->attr.is_bind_c)
2430 : 39449 : || ((sym->attr.result || sym->attr.value)
2431 : 1547 : && sym->ns->proc_name
2432 : 1541 : && sym->ns->proc_name->attr.is_bind_c)
2433 : 39194 : || (sym->ts.deferred
2434 : 3392 : && (!sym->ts.u.cl
2435 : 3392 : || !sym->ts.u.cl->backend_decl
2436 : 2519 : || sym->attr.save))
2437 : 38217 : || (sym->attr.dummy
2438 : 38217 : && sym->attr.value
2439 : 163 : && gfc_length_one_character_type_p (&sym->ts))))
2440 : 1423 : type = gfc_get_char_type (sym->ts.kind);
2441 : : else
2442 : 369514 : type = gfc_typenode_for_spec (&sym->ts, sym->attr.codimension);
2443 : :
2444 : 370937 : if (sym->attr.dummy && !sym->attr.function && !sym->attr.value
2445 : 131696 : && !sym->pass_as_value)
2446 : : byref = 1;
2447 : : else
2448 : 240198 : byref = 0;
2449 : :
2450 : 344093 : restricted = (!sym->attr.target && !IS_POINTER (sym)
2451 : 699325 : && !IS_PROC_POINTER (sym) && !sym->attr.cray_pointee);
2452 : 43224 : if (!restricted)
2453 : 43224 : type = gfc_nonrestricted_type (type);
2454 : :
2455 : : /* Dummy argument to a bind(C) procedure. */
2456 : 370937 : if (is_bind_c && is_CFI_desc (sym, NULL))
2457 : 3610 : type = gfc_get_cfi_type (sym->attr.dimension ? sym->as->rank : 0,
2458 : : /* restricted = */ false);
2459 : 367327 : else if (sym->attr.dimension || sym->attr.codimension)
2460 : : {
2461 : 87340 : if (gfc_is_nodesc_array (sym))
2462 : : {
2463 : : /* If this is a character argument of unknown length, just use the
2464 : : base type. */
2465 : 48431 : if (sym->ts.type != BT_CHARACTER
2466 : 5402 : || !(sym->attr.dummy || sym->attr.function)
2467 : 1591 : || sym->ts.u.cl->backend_decl)
2468 : : {
2469 : 48113 : type = gfc_get_nodesc_array_type (type, sym->as,
2470 : : byref ? PACKED_FULL
2471 : : : PACKED_STATIC,
2472 : : restricted);
2473 : 48113 : byref = 0;
2474 : : }
2475 : : }
2476 : : else
2477 : : {
2478 : 38909 : enum gfc_array_kind akind = GFC_ARRAY_UNKNOWN;
2479 : 38909 : if (sym->attr.pointer)
2480 : 6501 : akind = sym->attr.contiguous ? GFC_ARRAY_POINTER_CONT
2481 : : : GFC_ARRAY_POINTER;
2482 : 32408 : else if (sym->attr.allocatable)
2483 : 9367 : akind = GFC_ARRAY_ALLOCATABLE;
2484 : 38909 : type = gfc_build_array_type (type, sym->as, akind, restricted,
2485 : 38909 : sym->attr.contiguous, sym->as->corank);
2486 : : }
2487 : : }
2488 : : else
2489 : : {
2490 : 279987 : if (sym->attr.allocatable || sym->attr.pointer
2491 : 279987 : || gfc_is_associate_pointer (sym))
2492 : 14511 : type = gfc_build_pointer_type (sym, type);
2493 : : }
2494 : :
2495 : : /* We currently pass all parameters by reference.
2496 : : See f95_get_function_decl. For dummy function parameters return the
2497 : : function type. */
2498 : 370937 : if (byref)
2499 : : {
2500 : : /* We must use pointer types for potentially absent variables. The
2501 : : optimizers assume a reference type argument is never NULL. */
2502 : 118710 : if ((sym->ts.type == BT_CLASS && CLASS_DATA (sym)->attr.optional)
2503 : 118710 : || sym->attr.optional
2504 : 103344 : || (sym->ns->proc_name && sym->ns->proc_name->attr.entry_master))
2505 : 17017 : type = build_pointer_type (type);
2506 : : else
2507 : 101693 : type = build_reference_type (type);
2508 : :
2509 : 118710 : if (restricted)
2510 : 112283 : type = build_qualified_type (type, TYPE_QUAL_RESTRICT);
2511 : : }
2512 : :
2513 : : return (type);
2514 : : }
2515 : :
2516 : : /* Layout and output debug info for a record type. */
2517 : :
2518 : : void
2519 : 317702 : gfc_finish_type (tree type)
2520 : : {
2521 : 317702 : tree decl;
2522 : :
2523 : 317702 : decl = build_decl (input_location,
2524 : : TYPE_DECL, NULL_TREE, type);
2525 : 317702 : TYPE_STUB_DECL (type) = decl;
2526 : 317702 : layout_type (type);
2527 : 317702 : rest_of_type_compilation (type, 1);
2528 : 317702 : rest_of_decl_compilation (decl, 1, 0);
2529 : 317702 : }
2530 : :
2531 : : /* Add a field of given NAME and TYPE to the context of a UNION_TYPE
2532 : : or RECORD_TYPE pointed to by CONTEXT. The new field is chained
2533 : : to the end of the field list pointed to by *CHAIN.
2534 : :
2535 : : Returns a pointer to the new field. */
2536 : :
2537 : : static tree
2538 : 4761911 : gfc_add_field_to_struct_1 (tree context, tree name, tree type, tree **chain)
2539 : : {
2540 : 4761911 : tree decl = build_decl (input_location, FIELD_DECL, name, type);
2541 : :
2542 : 4761911 : DECL_CONTEXT (decl) = context;
2543 : 4761911 : DECL_CHAIN (decl) = NULL_TREE;
2544 : 4761911 : if (TYPE_FIELDS (context) == NULL_TREE)
2545 : 312450 : TYPE_FIELDS (context) = decl;
2546 : 4761911 : if (chain != NULL)
2547 : : {
2548 : 4761911 : if (*chain != NULL)
2549 : 4449461 : **chain = decl;
2550 : 4761911 : *chain = &DECL_CHAIN (decl);
2551 : : }
2552 : :
2553 : 4761911 : return decl;
2554 : : }
2555 : :
2556 : : /* Like `gfc_add_field_to_struct_1', but adds alignment
2557 : : information. */
2558 : :
2559 : : tree
2560 : 4412158 : gfc_add_field_to_struct (tree context, tree name, tree type, tree **chain)
2561 : : {
2562 : 4412158 : tree decl = gfc_add_field_to_struct_1 (context, name, type, chain);
2563 : :
2564 : 4412158 : DECL_INITIAL (decl) = 0;
2565 : 4412158 : SET_DECL_ALIGN (decl, 0);
2566 : 4412158 : DECL_USER_ALIGN (decl) = 0;
2567 : :
2568 : 4412158 : return decl;
2569 : : }
2570 : :
2571 : :
2572 : : /* Copy the backend_decl and component backend_decls if
2573 : : the two derived type symbols are "equal", as described
2574 : : in 4.4.2 and resolved by gfc_compare_derived_types. */
2575 : :
2576 : : bool
2577 : 309655 : gfc_copy_dt_decls_ifequal (gfc_symbol *from, gfc_symbol *to,
2578 : : bool from_gsym)
2579 : : {
2580 : 309655 : gfc_component *to_cm;
2581 : 309655 : gfc_component *from_cm;
2582 : :
2583 : 309655 : if (from == to)
2584 : : return 1;
2585 : :
2586 : 270610 : if (from->backend_decl == NULL
2587 : 270610 : || !gfc_compare_derived_types (from, to))
2588 : 257398 : return 0;
2589 : :
2590 : 13212 : to->backend_decl = from->backend_decl;
2591 : :
2592 : 13212 : to_cm = to->components;
2593 : 13212 : from_cm = from->components;
2594 : :
2595 : : /* Copy the component declarations. If a component is itself
2596 : : a derived type, we need a copy of its component declarations.
2597 : : This is done by recursing into gfc_get_derived_type and
2598 : : ensures that the component's component declarations have
2599 : : been built. If it is a character, we need the character
2600 : : length, as well. */
2601 : 49709 : for (; to_cm; to_cm = to_cm->next, from_cm = from_cm->next)
2602 : : {
2603 : 36497 : to_cm->backend_decl = from_cm->backend_decl;
2604 : 36497 : to_cm->caf_token = from_cm->caf_token;
2605 : 36497 : if (from_cm->ts.type == BT_UNION)
2606 : 28 : gfc_get_union_type (to_cm->ts.u.derived);
2607 : 36469 : else if (from_cm->ts.type == BT_DERIVED
2608 : 12548 : && (!from_cm->attr.pointer || from_gsym))
2609 : 11324 : gfc_get_derived_type (to_cm->ts.u.derived);
2610 : 25145 : else if (from_cm->ts.type == BT_CLASS
2611 : 704 : && (!CLASS_DATA (from_cm)->attr.class_pointer || from_gsym))
2612 : 697 : gfc_get_derived_type (to_cm->ts.u.derived);
2613 : 24448 : else if (from_cm->ts.type == BT_CHARACTER)
2614 : 786 : to_cm->ts.u.cl->backend_decl = from_cm->ts.u.cl->backend_decl;
2615 : : }
2616 : :
2617 : : return 1;
2618 : : }
2619 : :
2620 : :
2621 : : /* Build a tree node for a procedure pointer component. */
2622 : :
2623 : : static tree
2624 : 30675 : gfc_get_ppc_type (gfc_component* c)
2625 : : {
2626 : 30675 : tree t;
2627 : :
2628 : : /* Explicit interface. */
2629 : 30675 : if (c->attr.if_source != IFSRC_UNKNOWN && c->ts.interface)
2630 : 3109 : return build_pointer_type (gfc_get_function_type (c->ts.interface));
2631 : :
2632 : : /* Implicit interface (only return value may be known). */
2633 : 27566 : if (c->attr.function && !c->attr.dimension && c->ts.type != BT_CHARACTER)
2634 : 3 : t = gfc_typenode_for_spec (&c->ts);
2635 : : else
2636 : 27563 : t = void_type_node;
2637 : :
2638 : : /* FIXME: it would be better to provide explicit interfaces in all
2639 : : cases, since they should be known by the compiler. */
2640 : 27566 : return build_pointer_type (build_function_type (t, NULL_TREE));
2641 : : }
2642 : :
2643 : :
2644 : : /* Build a tree node for a union type. Requires building each map
2645 : : structure which is an element of the union. */
2646 : :
2647 : : tree
2648 : 252 : gfc_get_union_type (gfc_symbol *un)
2649 : : {
2650 : 252 : gfc_component *map = NULL;
2651 : 252 : tree typenode = NULL, map_type = NULL, map_field = NULL;
2652 : 252 : tree *chain = NULL;
2653 : :
2654 : 252 : if (un->backend_decl)
2655 : : {
2656 : 130 : if (TYPE_FIELDS (un->backend_decl) || un->attr.proc_pointer_comp)
2657 : : return un->backend_decl;
2658 : : else
2659 : : typenode = un->backend_decl;
2660 : : }
2661 : : else
2662 : : {
2663 : 122 : typenode = make_node (UNION_TYPE);
2664 : 122 : TYPE_NAME (typenode) = get_identifier (un->name);
2665 : : }
2666 : :
2667 : : /* Add each contained MAP as a field. */
2668 : 363 : for (map = un->components; map; map = map->next)
2669 : : {
2670 : 238 : gcc_assert (map->ts.type == BT_DERIVED);
2671 : :
2672 : : /* The map's type node, which is defined within this union's context. */
2673 : 238 : map_type = gfc_get_derived_type (map->ts.u.derived);
2674 : 238 : TYPE_CONTEXT (map_type) = typenode;
2675 : :
2676 : : /* The map field's declaration. */
2677 : 238 : map_field = gfc_add_field_to_struct(typenode, get_identifier(map->name),
2678 : : map_type, &chain);
2679 : 238 : if (map->loc.lb)
2680 : 238 : gfc_set_decl_location (map_field, &map->loc);
2681 : 0 : else if (un->declared_at.lb)
2682 : 0 : gfc_set_decl_location (map_field, &un->declared_at);
2683 : :
2684 : 238 : DECL_PACKED (map_field) |= TYPE_PACKED (typenode);
2685 : 238 : DECL_NAMELESS(map_field) = true;
2686 : :
2687 : : /* We should never clobber another backend declaration for this map,
2688 : : because each map component is unique. */
2689 : 238 : if (!map->backend_decl)
2690 : 238 : map->backend_decl = map_field;
2691 : : }
2692 : :
2693 : 125 : un->backend_decl = typenode;
2694 : 125 : gfc_finish_type (typenode);
2695 : :
2696 : 125 : return typenode;
2697 : : }
2698 : :
2699 : : bool
2700 : 163 : cobounds_match_decl (const gfc_symbol *derived)
2701 : : {
2702 : 163 : tree arrtype, tmp;
2703 : 163 : gfc_array_spec *as;
2704 : :
2705 : 163 : if (!derived->backend_decl)
2706 : : return false;
2707 : : /* Care only about coarray declarations. Everything else is ok with us. */
2708 : 163 : if (!derived->components || strcmp (derived->components->name, "_data") != 0)
2709 : : return true;
2710 : 163 : if (!derived->components->attr.codimension)
2711 : : return true;
2712 : :
2713 : 163 : arrtype = TREE_TYPE (TYPE_FIELDS (derived->backend_decl));
2714 : 163 : as = derived->components->as;
2715 : 163 : if (GFC_TYPE_ARRAY_CORANK (arrtype) != as->corank)
2716 : : return false;
2717 : :
2718 : 208 : for (int dim = as->rank; dim < as->rank + as->corank; ++dim)
2719 : : {
2720 : : /* Check lower bound. */
2721 : 107 : tmp = TYPE_LANG_SPECIFIC (arrtype)->lbound[dim];
2722 : 107 : if (!tmp || !INTEGER_CST_P (tmp))
2723 : : return false;
2724 : 107 : if (as->lower[dim]->expr_type != EXPR_CONSTANT
2725 : 107 : || as->lower[dim]->ts.type != BT_INTEGER)
2726 : : return false;
2727 : 107 : if (*tmp->int_cst.val != mpz_get_si (as->lower[dim]->value.integer))
2728 : : return false;
2729 : :
2730 : : /* Check upper bound. */
2731 : 103 : tmp = TYPE_LANG_SPECIFIC (arrtype)->ubound[dim];
2732 : 103 : if (!tmp && !as->upper[dim])
2733 : 101 : continue;
2734 : :
2735 : 2 : if (!tmp || !INTEGER_CST_P (tmp))
2736 : : return false;
2737 : 2 : if (as->upper[dim]->expr_type != EXPR_CONSTANT
2738 : 2 : || as->upper[dim]->ts.type != BT_INTEGER)
2739 : : return false;
2740 : 2 : if (*tmp->int_cst.val != mpz_get_si (as->upper[dim]->value.integer))
2741 : : return false;
2742 : : }
2743 : :
2744 : : return true;
2745 : : }
2746 : :
2747 : : /* Build a tree node for a derived type. If there are equal
2748 : : derived types, with different local names, these are built
2749 : : at the same time. If an equal derived type has been built
2750 : : in a parent namespace, this is used. */
2751 : :
2752 : : tree
2753 : 168292 : gfc_get_derived_type (gfc_symbol * derived, int codimen)
2754 : : {
2755 : 168292 : tree typenode = NULL, field = NULL, field_type = NULL;
2756 : 168292 : tree canonical = NULL_TREE;
2757 : 168292 : tree *chain = NULL;
2758 : 168292 : bool got_canonical = false;
2759 : 168292 : bool unlimited_entity = false;
2760 : 168292 : gfc_component *c, *last_c = nullptr;
2761 : 168292 : gfc_namespace *ns;
2762 : 168292 : tree tmp;
2763 : 168292 : bool coarray_flag, class_coarray_flag;
2764 : :
2765 : 336584 : coarray_flag = flag_coarray == GFC_FCOARRAY_LIB
2766 : 168292 : && derived->module && !derived->attr.vtype;
2767 : 336584 : class_coarray_flag = derived->components
2768 : 158818 : && derived->components->ts.type == BT_DERIVED
2769 : 51708 : && strcmp (derived->components->name, "_data") == 0
2770 : 30992 : && derived->components->attr.codimension
2771 : 168903 : && derived->components->as->cotype == AS_EXPLICIT;
2772 : :
2773 : 168292 : gcc_assert (!derived->attr.pdt_template);
2774 : :
2775 : 168292 : if (derived->attr.unlimited_polymorphic
2776 : 165208 : || (flag_coarray == GFC_FCOARRAY_LIB
2777 : 2171 : && derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
2778 : 36 : && (derived->intmod_sym_id == ISOFORTRAN_LOCK_TYPE
2779 : : || derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE
2780 : 36 : || derived->intmod_sym_id == ISOFORTRAN_TEAM_TYPE)))
2781 : 3120 : return ptr_type_node;
2782 : :
2783 : 165172 : if (flag_coarray != GFC_FCOARRAY_LIB
2784 : 163037 : && derived->from_intmod == INTMOD_ISO_FORTRAN_ENV
2785 : 410 : && (derived->intmod_sym_id == ISOFORTRAN_EVENT_TYPE
2786 : 410 : || derived->intmod_sym_id == ISOFORTRAN_TEAM_TYPE))
2787 : 298 : return gfc_get_int_type (gfc_default_integer_kind);
2788 : :
2789 : 164874 : if (derived && derived->attr.flavor == FL_PROCEDURE
2790 : 52 : && derived->attr.generic)
2791 : 52 : derived = gfc_find_dt_in_generic (derived);
2792 : :
2793 : : /* See if it's one of the iso_c_binding derived types. */
2794 : 164874 : if (derived->attr.is_iso_c == 1 || derived->ts.f90_type == BT_VOID)
2795 : : {
2796 : 13580 : if (derived->backend_decl)
2797 : : return derived->backend_decl;
2798 : :
2799 : 4963 : if (derived->intmod_sym_id == ISOCBINDING_PTR)
2800 : 2658 : derived->backend_decl = ptr_type_node;
2801 : : else
2802 : 2305 : derived->backend_decl = pfunc_type_node;
2803 : :
2804 : 4963 : derived->ts.kind = gfc_index_integer_kind;
2805 : 4963 : derived->ts.type = BT_INTEGER;
2806 : : /* Set the f90_type to BT_VOID as a way to recognize something of type
2807 : : BT_INTEGER that needs to fit a void * for the purpose of the
2808 : : iso_c_binding derived types. */
2809 : 4963 : derived->ts.f90_type = BT_VOID;
2810 : :
2811 : 4963 : return derived->backend_decl;
2812 : : }
2813 : :
2814 : : /* If use associated, use the module type for this one. */
2815 : 151294 : if (derived->backend_decl == NULL
2816 : 36892 : && (derived->attr.use_assoc || derived->attr.used_in_submodule)
2817 : 9882 : && derived->module
2818 : 161176 : && gfc_get_module_backend_decl (derived))
2819 : 9523 : goto copy_derived_types;
2820 : :
2821 : : /* The derived types from an earlier namespace can be used as the
2822 : : canonical type. */
2823 : 141771 : if (derived->backend_decl == NULL
2824 : : && !derived->attr.use_assoc
2825 : 27369 : && !derived->attr.used_in_submodule
2826 : 27010 : && gfc_global_ns_list)
2827 : : {
2828 : 7319 : for (ns = gfc_global_ns_list;
2829 : 34308 : ns->translated && !got_canonical;
2830 : 7319 : ns = ns->sibling)
2831 : : {
2832 : 7319 : if (ns->derived_types)
2833 : : {
2834 : 26569 : for (gfc_symbol *dt = ns->derived_types; dt && !got_canonical;
2835 : : dt = dt->dt_next)
2836 : : {
2837 : 26351 : gfc_copy_dt_decls_ifequal (dt, derived, true);
2838 : 26351 : if (derived->backend_decl)
2839 : 357 : got_canonical = true;
2840 : 26351 : if (dt->dt_next == ns->derived_types)
2841 : : break;
2842 : : }
2843 : : }
2844 : : }
2845 : : }
2846 : :
2847 : : /* Store up the canonical type to be added to this one. */
2848 : 26989 : if (got_canonical)
2849 : : {
2850 : 357 : if (TYPE_CANONICAL (derived->backend_decl))
2851 : 357 : canonical = TYPE_CANONICAL (derived->backend_decl);
2852 : : else
2853 : : canonical = derived->backend_decl;
2854 : :
2855 : 357 : derived->backend_decl = NULL_TREE;
2856 : : }
2857 : :
2858 : : /* derived->backend_decl != 0 means we saw it before, but its
2859 : : components' backend_decl may have not been built. */
2860 : 141771 : if (derived->backend_decl
2861 : 141771 : && (!class_coarray_flag || cobounds_match_decl (derived)))
2862 : : {
2863 : : /* Its components' backend_decl have been built or we are
2864 : : seeing recursion through the formal arglist of a procedure
2865 : : pointer component. */
2866 : 114340 : if (TYPE_FIELDS (derived->backend_decl))
2867 : : return derived->backend_decl;
2868 : 4424 : else if (derived->attr.abstract
2869 : 4424 : && derived->attr.proc_pointer_comp)
2870 : : {
2871 : : /* If an abstract derived type with procedure pointer
2872 : : components has no other type of component, return the
2873 : : backend_decl. Otherwise build the components if any of the
2874 : : non-procedure pointer components have no backend_decl. */
2875 : 1 : for (c = derived->components; c; c = c->next)
2876 : : {
2877 : 2 : bool same_alloc_type = c->attr.allocatable
2878 : 1 : && derived == c->ts.u.derived;
2879 : 1 : if (!c->attr.proc_pointer
2880 : 1 : && !same_alloc_type
2881 : 1 : && c->backend_decl == NULL)
2882 : : break;
2883 : 0 : else if (c->next == NULL)
2884 : : return derived->backend_decl;
2885 : : }
2886 : : typenode = derived->backend_decl;
2887 : : }
2888 : : else
2889 : : typenode = derived->backend_decl;
2890 : : }
2891 : : else
2892 : : {
2893 : : /* We see this derived type first time, so build the type node. */
2894 : 27431 : typenode = make_node (RECORD_TYPE);
2895 : 27431 : TYPE_NAME (typenode) = get_identifier (derived->name);
2896 : 27431 : TYPE_PACKED (typenode) = flag_pack_derived;
2897 : 27431 : derived->backend_decl = typenode;
2898 : : }
2899 : :
2900 : 31855 : if (derived->components
2901 : 26608 : && derived->components->ts.type == BT_DERIVED
2902 : 9281 : && strcmp (derived->components->name, "_data") == 0
2903 : 6756 : && derived->components->ts.u.derived->attr.unlimited_polymorphic)
2904 : 31855 : unlimited_entity = true;
2905 : :
2906 : : /* Go through the derived type components, building them as
2907 : : necessary. The reason for doing this now is that it is
2908 : : possible to recurse back to this derived type through a
2909 : : pointer component (PR24092). If this happens, the fields
2910 : : will be built and so we can return the type. */
2911 : 132462 : for (c = derived->components; c; c = c->next)
2912 : : {
2913 : 100607 : if (c->ts.type == BT_UNION && c->ts.u.derived->backend_decl == NULL)
2914 : 108 : c->ts.u.derived->backend_decl = gfc_get_union_type (c->ts.u.derived);
2915 : :
2916 : 100607 : if (c->ts.type != BT_DERIVED && c->ts.type != BT_CLASS)
2917 : 65204 : continue;
2918 : :
2919 : 35403 : const bool incomplete_type
2920 : 35403 : = c->ts.u.derived->backend_decl
2921 : 29674 : && TREE_CODE (c->ts.u.derived->backend_decl) == RECORD_TYPE
2922 : 62793 : && !(TYPE_LANG_SPECIFIC (c->ts.u.derived->backend_decl)
2923 : 15848 : && TYPE_LANG_SPECIFIC (c->ts.u.derived->backend_decl)->size);
2924 : 35403 : const bool pointer_component
2925 : 35403 : = c->attr.pointer || c->attr.allocatable || c->attr.proc_pointer;
2926 : :
2927 : : /* Prevent endless recursion on recursive types (i.e. types that reference
2928 : : themself in a component. Break the recursion by not building pointers
2929 : : to incomplete types again, aka types that are already in the build. */
2930 : 35403 : if (c->ts.u.derived->backend_decl == NULL
2931 : 29674 : || (c->attr.codimension && c->as->corank != codimen)
2932 : 29412 : || !(incomplete_type && pointer_component))
2933 : : {
2934 : 9094 : int local_codim = c->attr.codimension ? c->as->corank: codimen;
2935 : 9094 : c->ts.u.derived->backend_decl = gfc_get_derived_type (c->ts.u.derived,
2936 : : local_codim);
2937 : : }
2938 : :
2939 : 35403 : if (c->ts.u.derived->attr.is_iso_c)
2940 : : {
2941 : : /* Need to copy the modified ts from the derived type. The
2942 : : typespec was modified because C_PTR/C_FUNPTR are translated
2943 : : into (void *) from derived types. */
2944 : 22 : c->ts.type = c->ts.u.derived->ts.type;
2945 : 22 : c->ts.kind = c->ts.u.derived->ts.kind;
2946 : 22 : c->ts.f90_type = c->ts.u.derived->ts.f90_type;
2947 : 22 : if (c->initializer)
2948 : : {
2949 : 21 : c->initializer->ts.type = c->ts.type;
2950 : 21 : c->initializer->ts.kind = c->ts.kind;
2951 : 21 : c->initializer->ts.f90_type = c->ts.f90_type;
2952 : 21 : c->initializer->expr_type = EXPR_NULL;
2953 : : }
2954 : : }
2955 : : }
2956 : :
2957 : 31855 : if (!class_coarray_flag && TYPE_FIELDS (derived->backend_decl))
2958 : : return derived->backend_decl;
2959 : :
2960 : : /* Build the type member list. Install the newly created RECORD_TYPE
2961 : : node as DECL_CONTEXT of each FIELD_DECL. In this case we must go
2962 : : through only the top-level linked list of components so we correctly
2963 : : build UNION_TYPE nodes for BT_UNION components. MAPs and other nested
2964 : : types are built as part of gfc_get_union_type. */
2965 : 132281 : for (c = derived->components; c; c = c->next)
2966 : : {
2967 : 200982 : bool same_alloc_type = c->attr.allocatable
2968 : 100491 : && derived == c->ts.u.derived;
2969 : : /* Prevent infinite recursion, when the procedure pointer type is
2970 : : the same as derived, by forcing the procedure pointer component to
2971 : : be built as if the explicit interface does not exist. */
2972 : 100491 : if (c->attr.proc_pointer
2973 : 30713 : && (c->ts.type != BT_DERIVED || (c->ts.u.derived
2974 : 163 : && !gfc_compare_derived_types (derived, c->ts.u.derived)))
2975 : 131180 : && (c->ts.type != BT_CLASS || (CLASS_DATA (c)->ts.u.derived
2976 : 325 : && !gfc_compare_derived_types (derived, CLASS_DATA (c)->ts.u.derived))))
2977 : 30675 : field_type = gfc_get_ppc_type (c);
2978 : 69816 : else if (c->attr.proc_pointer && derived->backend_decl)
2979 : : {
2980 : 38 : tmp = build_function_type (derived->backend_decl, NULL_TREE);
2981 : 38 : field_type = build_pointer_type (tmp);
2982 : : }
2983 : 69778 : else if (c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS)
2984 : 34784 : field_type = c->ts.u.derived->backend_decl;
2985 : 34994 : else if (c->attr.caf_token)
2986 : 107 : field_type = pvoid_type_node;
2987 : : else
2988 : : {
2989 : 34887 : if (c->ts.type == BT_CHARACTER
2990 : 1775 : && !c->ts.deferred && !c->attr.pdt_string)
2991 : : {
2992 : : /* Evaluate the string length. */
2993 : 1361 : gfc_conv_const_charlen (c->ts.u.cl);
2994 : 1361 : gcc_assert (c->ts.u.cl->backend_decl);
2995 : : }
2996 : 33526 : else if (c->ts.type == BT_CHARACTER)
2997 : 414 : c->ts.u.cl->backend_decl
2998 : 414 : = build_int_cst (gfc_charlen_type_node, 0);
2999 : :
3000 : 34887 : field_type = gfc_typenode_for_spec (&c->ts, codimen);
3001 : : }
3002 : :
3003 : : /* This returns an array descriptor type. Initialization may be
3004 : : required. */
3005 : 100491 : if ((c->attr.dimension || c->attr.codimension) && !c->attr.proc_pointer )
3006 : : {
3007 : 6179 : if (c->attr.pointer || c->attr.allocatable || c->attr.pdt_array)
3008 : : {
3009 : 4864 : enum gfc_array_kind akind;
3010 : 4864 : if (c->attr.pointer)
3011 : 1995 : akind = c->attr.contiguous ? GFC_ARRAY_POINTER_CONT
3012 : : : GFC_ARRAY_POINTER;
3013 : : else
3014 : : akind = GFC_ARRAY_ALLOCATABLE;
3015 : : /* Pointers to arrays aren't actually pointer types. The
3016 : : descriptors are separate, but the data is common. Every
3017 : : array pointer in a coarray derived type needs to provide space
3018 : : for the coarray management, too. Therefore treat coarrays
3019 : : and pointers to coarrays in derived types the same. */
3020 : 4864 : field_type = gfc_build_array_type
3021 : 4864 : (
3022 : : field_type, c->as, akind, !c->attr.target && !c->attr.pointer,
3023 : : c->attr.contiguous,
3024 : 4864 : c->attr.codimension || c->attr.pointer ? codimen : 0
3025 : : );
3026 : 4864 : }
3027 : : else
3028 : 1315 : field_type = gfc_get_nodesc_array_type (field_type, c->as,
3029 : : PACKED_STATIC,
3030 : : !c->attr.target);
3031 : : }
3032 : 94312 : else if ((c->attr.pointer || c->attr.allocatable || c->attr.pdt_string)
3033 : 31241 : && !c->attr.proc_pointer
3034 : 31091 : && !(unlimited_entity && c == derived->components))
3035 : 30603 : field_type = build_pointer_type (field_type);
3036 : :
3037 : 100491 : if (c->attr.pointer || same_alloc_type)
3038 : 31220 : field_type = gfc_nonrestricted_type (field_type);
3039 : :
3040 : : /* vtype fields can point to different types to the base type. */
3041 : 100491 : if (c->ts.type == BT_DERIVED
3042 : 34238 : && c->ts.u.derived && c->ts.u.derived->attr.vtype)
3043 : 15381 : field_type = build_pointer_type_for_mode (TREE_TYPE (field_type),
3044 : : ptr_mode, true);
3045 : :
3046 : : /* Ensure that the CLASS language specific flag is set. */
3047 : 100491 : if (c->ts.type == BT_CLASS)
3048 : : {
3049 : 1034 : if (POINTER_TYPE_P (field_type))
3050 : 325 : GFC_CLASS_TYPE_P (TREE_TYPE (field_type)) = 1;
3051 : : else
3052 : 709 : GFC_CLASS_TYPE_P (field_type) = 1;
3053 : : }
3054 : :
3055 : 100491 : field = gfc_add_field_to_struct (typenode,
3056 : : get_identifier (c->name),
3057 : : field_type, &chain);
3058 : 100491 : if (c->loc.lb)
3059 : 100491 : gfc_set_decl_location (field, &c->loc);
3060 : 0 : else if (derived->declared_at.lb)
3061 : 0 : gfc_set_decl_location (field, &derived->declared_at);
3062 : :
3063 : 100491 : gfc_finish_decl_attrs (field, &c->attr);
3064 : :
3065 : 100491 : DECL_PACKED (field) |= TYPE_PACKED (typenode);
3066 : :
3067 : 100491 : gcc_assert (field);
3068 : : /* Overwrite for class array to supply different bounds for different
3069 : : types. */
3070 : 100491 : if (class_coarray_flag || !c->backend_decl)
3071 : 99214 : c->backend_decl = field;
3072 : 100491 : if (c->attr.caf_token && last_c)
3073 : 107 : last_c->caf_token = field;
3074 : :
3075 : 100491 : if (c->attr.pointer && (c->attr.dimension || c->attr.codimension)
3076 : 2003 : && !(c->ts.type == BT_DERIVED && strcmp (c->name, "_data") == 0))
3077 : 554 : GFC_DECL_PTR_ARRAY_P (c->backend_decl) = 1;
3078 : :
3079 : 100491 : last_c = c;
3080 : : }
3081 : :
3082 : : /* Now lay out the derived type, including the fields. */
3083 : 31790 : if (canonical)
3084 : 357 : TYPE_CANONICAL (typenode) = canonical;
3085 : :
3086 : 31790 : gfc_finish_type (typenode);
3087 : 31790 : gfc_set_decl_location (TYPE_STUB_DECL (typenode), &derived->declared_at);
3088 : 31790 : if (derived->module && derived->ns->proc_name
3089 : 18728 : && derived->ns->proc_name->attr.flavor == FL_MODULE)
3090 : : {
3091 : 17655 : if (derived->ns->proc_name->backend_decl
3092 : 17641 : && TREE_CODE (derived->ns->proc_name->backend_decl)
3093 : : == NAMESPACE_DECL)
3094 : : {
3095 : 17641 : TYPE_CONTEXT (typenode) = derived->ns->proc_name->backend_decl;
3096 : 17641 : DECL_CONTEXT (TYPE_STUB_DECL (typenode))
3097 : 35282 : = derived->ns->proc_name->backend_decl;
3098 : : }
3099 : : }
3100 : :
3101 : 31790 : derived->backend_decl = typenode;
3102 : :
3103 : 41313 : copy_derived_types:
3104 : :
3105 : 169397 : for (c = derived->components; c; c = c->next)
3106 : : {
3107 : : /* Do not add a caf_token field for class container components. */
3108 : 128084 : if ((codimen || coarray_flag)
3109 : 666 : && !c->attr.dimension && !c->attr.codimension
3110 : 348 : && (c->attr.allocatable || c->attr.pointer)
3111 : 82 : && !derived->attr.is_class)
3112 : : {
3113 : : /* Provide sufficient space to hold "_caf_symbol". */
3114 : 76 : char caf_name[GFC_MAX_SYMBOL_LEN + 6];
3115 : 76 : gfc_component *token;
3116 : 76 : snprintf (caf_name, sizeof (caf_name), "_caf_%s", c->name);
3117 : 76 : token = gfc_find_component (derived, caf_name, true, true, NULL);
3118 : 76 : gcc_assert (token);
3119 : 76 : c->caf_token = token->backend_decl;
3120 : 76 : suppress_warning (c->caf_token);
3121 : : }
3122 : : }
3123 : :
3124 : 272962 : for (gfc_symbol *dt = gfc_derived_types; dt; dt = dt->dt_next)
3125 : : {
3126 : 272423 : gfc_copy_dt_decls_ifequal (derived, dt, false);
3127 : 272423 : if (dt->dt_next == gfc_derived_types)
3128 : : break;
3129 : : }
3130 : :
3131 : 41313 : return derived->backend_decl;
3132 : : }
3133 : :
3134 : :
3135 : : bool
3136 : 838993 : gfc_return_by_reference (gfc_symbol * sym)
3137 : : {
3138 : 838993 : if (!sym->attr.function)
3139 : : return 0;
3140 : :
3141 : 411371 : if (sym->attr.dimension)
3142 : : return 1;
3143 : :
3144 : 344602 : if (sym->ts.type == BT_CHARACTER
3145 : 21055 : && !sym->attr.is_bind_c
3146 : 20521 : && (!sym->attr.result
3147 : 16 : || !sym->ns->proc_name
3148 : 16 : || !sym->ns->proc_name->attr.is_bind_c))
3149 : : return 1;
3150 : :
3151 : : /* Possibly return complex numbers by reference for g77 compatibility.
3152 : : We don't do this for calls to intrinsics (as the library uses the
3153 : : -fno-f2c calling convention), nor for calls to functions which always
3154 : : require an explicit interface, as no compatibility problems can
3155 : : arise there. */
3156 : 324081 : if (flag_f2c && sym->ts.type == BT_COMPLEX
3157 : : && !sym->attr.pointer
3158 : : && !sym->attr.allocatable
3159 : 1800 : && !sym->attr.intrinsic && !sym->attr.always_explicit)
3160 : 624 : return 1;
3161 : :
3162 : : return 0;
3163 : : }
3164 : :
3165 : : static tree
3166 : 96 : gfc_get_mixed_entry_union (gfc_namespace *ns)
3167 : : {
3168 : 96 : tree type;
3169 : 96 : tree *chain = NULL;
3170 : 96 : char name[GFC_MAX_SYMBOL_LEN + 1];
3171 : 96 : gfc_entry_list *el, *el2;
3172 : :
3173 : 96 : gcc_assert (ns->proc_name->attr.mixed_entry_master);
3174 : 96 : gcc_assert (memcmp (ns->proc_name->name, "master.", 7) == 0);
3175 : :
3176 : 96 : snprintf (name, GFC_MAX_SYMBOL_LEN, "munion.%s", ns->proc_name->name + 7);
3177 : :
3178 : : /* Build the type node. */
3179 : 96 : type = make_node (UNION_TYPE);
3180 : :
3181 : 96 : TYPE_NAME (type) = get_identifier (name);
3182 : :
3183 : 306 : for (el = ns->entries; el; el = el->next)
3184 : : {
3185 : : /* Search for duplicates. */
3186 : 342 : for (el2 = ns->entries; el2 != el; el2 = el2->next)
3187 : 132 : if (el2->sym->result == el->sym->result)
3188 : : break;
3189 : :
3190 : 210 : if (el == el2)
3191 : 210 : gfc_add_field_to_struct_1 (type,
3192 : 210 : get_identifier (el->sym->result->name),
3193 : 210 : gfc_sym_type (el->sym->result), &chain);
3194 : : }
3195 : :
3196 : : /* Finish off the type. */
3197 : 96 : gfc_finish_type (type);
3198 : 96 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) = 1;
3199 : 96 : return type;
3200 : : }
3201 : :
3202 : : /* Create a "fn spec" based on the formal arguments;
3203 : : cf. create_function_arglist. */
3204 : :
3205 : : static tree
3206 : 98759 : create_fn_spec (gfc_symbol *sym, tree fntype)
3207 : : {
3208 : 98759 : char spec[150];
3209 : 98759 : size_t spec_len;
3210 : 98759 : gfc_formal_arglist *f;
3211 : 98759 : tree tmp;
3212 : :
3213 : 98759 : memset (&spec, 0, sizeof (spec));
3214 : 98759 : spec[0] = '.';
3215 : 98759 : spec[1] = ' ';
3216 : 98759 : spec_len = 2;
3217 : :
3218 : 98759 : if (sym->attr.entry_master)
3219 : : {
3220 : 632 : spec[spec_len++] = 'R';
3221 : 632 : spec[spec_len++] = ' ';
3222 : : }
3223 : 98759 : if (gfc_return_by_reference (sym))
3224 : : {
3225 : 9437 : gfc_symbol *result = sym->result ? sym->result : sym;
3226 : :
3227 : 9437 : if (result->attr.pointer || sym->attr.proc_pointer)
3228 : : {
3229 : 311 : spec[spec_len++] = '.';
3230 : 311 : spec[spec_len++] = ' ';
3231 : : }
3232 : : else
3233 : : {
3234 : 9126 : spec[spec_len++] = 'w';
3235 : 9126 : spec[spec_len++] = ' ';
3236 : : }
3237 : 9437 : if (sym->ts.type == BT_CHARACTER)
3238 : : {
3239 : 2750 : if (!sym->ts.u.cl->length
3240 : 493 : && (sym->attr.allocatable || sym->attr.pointer))
3241 : 271 : spec[spec_len++] = 'w';
3242 : : else
3243 : 2479 : spec[spec_len++] = 'R';
3244 : 2750 : spec[spec_len++] = ' ';
3245 : : }
3246 : : }
3247 : :
3248 : 227028 : for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
3249 : 128269 : if (spec_len < sizeof (spec))
3250 : : {
3251 : 128269 : bool is_class = false;
3252 : 128269 : bool is_pointer = false;
3253 : :
3254 : 128269 : if (f->sym)
3255 : : {
3256 : 8660 : is_class = f->sym->ts.type == BT_CLASS && CLASS_DATA (f->sym)
3257 : 136825 : && f->sym->attr.class_ok;
3258 : 128165 : is_pointer = is_class ? CLASS_DATA (f->sym)->attr.class_pointer
3259 : 119505 : : f->sym->attr.pointer;
3260 : : }
3261 : :
3262 : 128269 : if (f->sym == NULL || is_pointer || f->sym->attr.target
3263 : 124384 : || f->sym->attr.external || f->sym->attr.cray_pointer
3264 : 121537 : || (f->sym->ts.type == BT_DERIVED
3265 : 21057 : && (f->sym->ts.u.derived->attr.proc_pointer_comp
3266 : 21057 : || f->sym->ts.u.derived->attr.pointer_comp))
3267 : 118946 : || (is_class
3268 : 7799 : && (CLASS_DATA (f->sym)->ts.u.derived->attr.proc_pointer_comp
3269 : 7799 : || CLASS_DATA (f->sym)->ts.u.derived->attr.pointer_comp))
3270 : 117692 : || (f->sym->ts.type == BT_INTEGER && f->sym->ts.is_c_interop))
3271 : : {
3272 : 17832 : spec[spec_len++] = '.';
3273 : 17832 : spec[spec_len++] = ' ';
3274 : : }
3275 : 110437 : else if (f->sym->attr.intent == INTENT_IN)
3276 : : {
3277 : 49657 : spec[spec_len++] = 'r';
3278 : 49657 : spec[spec_len++] = ' ';
3279 : : }
3280 : 60780 : else if (f->sym)
3281 : : {
3282 : 60780 : spec[spec_len++] = 'w';
3283 : 60780 : spec[spec_len++] = ' ';
3284 : : }
3285 : : }
3286 : :
3287 : 98759 : tmp = build_tree_list (NULL_TREE, build_string (spec_len, spec));
3288 : 98759 : tmp = tree_cons (get_identifier ("fn spec"), tmp, TYPE_ATTRIBUTES (fntype));
3289 : 98759 : return build_type_attribute_variant (fntype, tmp);
3290 : : }
3291 : :
3292 : :
3293 : : /* NOTE: The returned function type must match the argument list created by
3294 : : create_function_arglist. */
3295 : :
3296 : : tree
3297 : 100525 : gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args,
3298 : : const char *fnspec)
3299 : : {
3300 : 100525 : tree type;
3301 : 100525 : vec<tree, va_gc> *typelist = NULL;
3302 : 100525 : vec<tree, va_gc> *hidden_typelist = NULL;
3303 : 100525 : gfc_formal_arglist *f;
3304 : 100525 : gfc_symbol *arg;
3305 : 100525 : int alternate_return = 0;
3306 : 100525 : bool is_varargs = true;
3307 : :
3308 : : /* Make sure this symbol is a function, a subroutine or the main
3309 : : program. */
3310 : 100525 : gcc_assert (sym->attr.flavor == FL_PROCEDURE
3311 : : || sym->attr.flavor == FL_PROGRAM);
3312 : :
3313 : : /* To avoid recursing infinitely on recursive types, we use error_mark_node
3314 : : so that they can be detected here and handled further down. */
3315 : 100525 : if (sym->backend_decl == NULL)
3316 : 100321 : sym->backend_decl = error_mark_node;
3317 : 204 : else if (sym->backend_decl == error_mark_node)
3318 : 27 : goto arg_type_list_done;
3319 : 177 : else if (sym->attr.proc_pointer)
3320 : 0 : return TREE_TYPE (TREE_TYPE (sym->backend_decl));
3321 : : else
3322 : 177 : return TREE_TYPE (sym->backend_decl);
3323 : :
3324 : 100321 : if (sym->attr.entry_master)
3325 : : /* Additional parameter for selecting an entry point. */
3326 : 632 : vec_safe_push (typelist, gfc_array_index_type);
3327 : :
3328 : 100321 : if (sym->result)
3329 : 30122 : arg = sym->result;
3330 : : else
3331 : : arg = sym;
3332 : :
3333 : 100321 : if (arg->ts.type == BT_CHARACTER)
3334 : 3053 : gfc_conv_const_charlen (arg->ts.u.cl);
3335 : :
3336 : : /* Some functions we use an extra parameter for the return value. */
3337 : 100321 : if (gfc_return_by_reference (sym))
3338 : : {
3339 : 10944 : type = gfc_sym_type (arg);
3340 : 10944 : if (arg->ts.type == BT_COMPLEX
3341 : 10623 : || arg->attr.dimension
3342 : 1530 : || arg->ts.type == BT_CHARACTER)
3343 : 10944 : type = build_reference_type (type);
3344 : :
3345 : 10944 : vec_safe_push (typelist, type);
3346 : 10944 : if (arg->ts.type == BT_CHARACTER)
3347 : : {
3348 : 2990 : if (!arg->ts.deferred)
3349 : : /* Transfer by value. */
3350 : 2671 : vec_safe_push (typelist, gfc_charlen_type_node);
3351 : : else
3352 : : /* Deferred character lengths are transferred by reference
3353 : : so that the value can be returned. */
3354 : 319 : vec_safe_push (typelist, build_pointer_type(gfc_charlen_type_node));
3355 : : }
3356 : : }
3357 : 100321 : if (sym->backend_decl == error_mark_node && actual_args != NULL
3358 : 14375 : && sym->formal == NULL && (sym->attr.proc == PROC_EXTERNAL
3359 : 1112 : || sym->attr.proc == PROC_UNKNOWN))
3360 : 791 : gfc_get_formal_from_actual_arglist (sym, actual_args);
3361 : :
3362 : : /* Build the argument types for the function. */
3363 : 233132 : for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
3364 : : {
3365 : 132811 : arg = f->sym;
3366 : 132811 : if (arg)
3367 : : {
3368 : : /* Evaluate constant character lengths here so that they can be
3369 : : included in the type. */
3370 : 132707 : if (arg->ts.type == BT_CHARACTER)
3371 : 11642 : gfc_conv_const_charlen (arg->ts.u.cl);
3372 : :
3373 : 132707 : if (arg->attr.flavor == FL_PROCEDURE)
3374 : : {
3375 : 961 : type = gfc_get_function_type (arg);
3376 : 961 : type = build_pointer_type (type);
3377 : : }
3378 : : else
3379 : 131746 : type = gfc_sym_type (arg, sym->attr.is_bind_c);
3380 : :
3381 : : /* Parameter Passing Convention
3382 : :
3383 : : We currently pass all parameters by reference.
3384 : : Parameters with INTENT(IN) could be passed by value.
3385 : : The problem arises if a function is called via an implicit
3386 : : prototype. In this situation the INTENT is not known.
3387 : : For this reason all parameters to global functions must be
3388 : : passed by reference. Passing by value would potentially
3389 : : generate bad code. Worse there would be no way of telling that
3390 : : this code was bad, except that it would give incorrect results.
3391 : :
3392 : : Contained procedures could pass by value as these are never
3393 : : used without an explicit interface, and cannot be passed as
3394 : : actual parameters for a dummy procedure. */
3395 : :
3396 : 132707 : vec_safe_push (typelist, type);
3397 : : }
3398 : : else
3399 : : {
3400 : 104 : if (sym->attr.subroutine)
3401 : 132811 : alternate_return = 1;
3402 : : }
3403 : : }
3404 : :
3405 : : /* Add hidden arguments. */
3406 : 233132 : for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
3407 : : {
3408 : 132811 : arg = f->sym;
3409 : : /* Add hidden string length parameters. */
3410 : 132811 : if (arg && arg->ts.type == BT_CHARACTER && !sym->attr.is_bind_c)
3411 : : {
3412 : 9573 : if (!arg->ts.deferred)
3413 : : /* Transfer by value. */
3414 : 9094 : type = gfc_charlen_type_node;
3415 : : else
3416 : : /* Deferred character lengths are transferred by reference
3417 : : so that the value can be returned. */
3418 : 479 : type = build_pointer_type (gfc_charlen_type_node);
3419 : :
3420 : 9573 : vec_safe_push (hidden_typelist, type);
3421 : : }
3422 : : /* For scalar intrinsic types, VALUE passes the value,
3423 : : hence, the optional status cannot be transferred via a NULL pointer.
3424 : : Thus, we will use a hidden argument in that case. */
3425 : : if (arg
3426 : : && arg->attr.optional
3427 : : && arg->attr.value
3428 : 132707 : && !arg->attr.dimension
3429 : 456 : && arg->ts.type != BT_CLASS
3430 : : && !gfc_bt_struct (arg->ts.type))
3431 : 456 : vec_safe_push (typelist, boolean_type_node);
3432 : : /* Coarrays which are descriptorless or assumed-shape pass with
3433 : : -fcoarray=lib the token and the offset as hidden arguments. */
3434 : 560 : if (arg
3435 : 132707 : && flag_coarray == GFC_FCOARRAY_LIB
3436 : 402 : && ((arg->ts.type != BT_CLASS
3437 : : && arg->attr.codimension
3438 : 387 : && !arg->attr.allocatable)
3439 : 351 : || (arg->ts.type == BT_CLASS
3440 : 15 : && CLASS_DATA (arg)->attr.codimension
3441 : 15 : && !CLASS_DATA (arg)->attr.allocatable)))
3442 : : {
3443 : 60 : vec_safe_push (hidden_typelist, pvoid_type_node); /* caf_token. */
3444 : 60 : vec_safe_push (hidden_typelist, gfc_array_index_type); /* caf_offset. */
3445 : : }
3446 : : }
3447 : :
3448 : : /* Put hidden character length, caf_token, caf_offset at the end. */
3449 : 107030 : vec_safe_reserve (typelist, vec_safe_length (hidden_typelist));
3450 : 100321 : vec_safe_splice (typelist, hidden_typelist);
3451 : :
3452 : 100321 : if (!vec_safe_is_empty (typelist)
3453 : : || sym->attr.is_main_program
3454 : 40171 : || sym->attr.if_source != IFSRC_UNKNOWN)
3455 : : is_varargs = false;
3456 : :
3457 : 100321 : if (sym->backend_decl == error_mark_node)
3458 : 100321 : sym->backend_decl = NULL_TREE;
3459 : :
3460 : 100348 : arg_type_list_done:
3461 : :
3462 : 100348 : if (alternate_return)
3463 : 74 : type = integer_type_node;
3464 : 100274 : else if (!sym->attr.function || gfc_return_by_reference (sym))
3465 : 80701 : type = void_type_node;
3466 : 19573 : else if (sym->attr.mixed_entry_master)
3467 : 96 : type = gfc_get_mixed_entry_union (sym->ns);
3468 : 19477 : else if (flag_f2c && sym->ts.type == BT_REAL
3469 : 393 : && sym->ts.kind == gfc_default_real_kind
3470 : : && !sym->attr.pointer
3471 : 219 : && !sym->attr.allocatable
3472 : 171 : && !sym->attr.always_explicit)
3473 : : {
3474 : : /* Special case: f2c calling conventions require that (scalar)
3475 : : default REAL functions return the C type double instead. f2c
3476 : : compatibility is only an issue with functions that don't
3477 : : require an explicit interface, as only these could be
3478 : : implemented in Fortran 77. */
3479 : 171 : sym->ts.kind = gfc_default_double_kind;
3480 : 171 : type = gfc_typenode_for_spec (&sym->ts);
3481 : 171 : sym->ts.kind = gfc_default_real_kind;
3482 : : }
3483 : 19306 : else if (sym->result && sym->result->attr.proc_pointer)
3484 : : /* Procedure pointer return values. */
3485 : : {
3486 : 443 : if (sym->result->attr.result && strcmp (sym->name,"ppr@") != 0)
3487 : : {
3488 : : /* Unset proc_pointer as gfc_get_function_type
3489 : : is called recursively. */
3490 : 151 : sym->result->attr.proc_pointer = 0;
3491 : 151 : type = build_pointer_type (gfc_get_function_type (sym->result));
3492 : 151 : sym->result->attr.proc_pointer = 1;
3493 : : }
3494 : : else
3495 : 292 : type = gfc_sym_type (sym->result);
3496 : : }
3497 : : else
3498 : 18863 : type = gfc_sym_type (sym);
3499 : :
3500 : 100348 : if (is_varargs)
3501 : : /* This should be represented as an unprototyped type, not a type
3502 : : with (...) prototype. */
3503 : 1925 : type = build_function_type (type, NULL_TREE);
3504 : : else
3505 : 218723 : type = build_function_type_vec (type, typelist);
3506 : :
3507 : : /* If we were passed an fn spec, add it here, otherwise determine it from
3508 : : the formal arguments. */
3509 : 100348 : if (fnspec)
3510 : : {
3511 : 1589 : tree tmp;
3512 : 1589 : int spec_len = strlen (fnspec);
3513 : 1589 : tmp = build_tree_list (NULL_TREE, build_string (spec_len, fnspec));
3514 : 1589 : tmp = tree_cons (get_identifier ("fn spec"), tmp, TYPE_ATTRIBUTES (type));
3515 : 1589 : type = build_type_attribute_variant (type, tmp);
3516 : : }
3517 : : else
3518 : 98759 : type = create_fn_spec (sym, type);
3519 : :
3520 : 100348 : return type;
3521 : : }
3522 : :
3523 : : /* Language hooks for middle-end access to type nodes. */
3524 : :
3525 : : /* Return an integer type with BITS bits of precision,
3526 : : that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3527 : :
3528 : : tree
3529 : 775701 : gfc_type_for_size (unsigned bits, int unsignedp)
3530 : : {
3531 : 775701 : if (!unsignedp)
3532 : : {
3533 : : int i;
3534 : 354959 : for (i = 0; i <= MAX_INT_KINDS; ++i)
3535 : : {
3536 : 354959 : tree type = gfc_integer_types[i];
3537 : 354959 : if (type && bits == TYPE_PRECISION (type))
3538 : 95279 : return type;
3539 : : }
3540 : :
3541 : : /* Handle TImode as a special case because it is used by some backends
3542 : : (e.g. ARM) even though it is not available for normal use. */
3543 : : #if HOST_BITS_PER_WIDE_INT >= 64
3544 : 0 : if (bits == TYPE_PRECISION (intTI_type_node))
3545 : : return intTI_type_node;
3546 : : #endif
3547 : :
3548 : 0 : if (bits <= TYPE_PRECISION (intQI_type_node))
3549 : : return intQI_type_node;
3550 : 0 : if (bits <= TYPE_PRECISION (intHI_type_node))
3551 : : return intHI_type_node;
3552 : 0 : if (bits <= TYPE_PRECISION (intSI_type_node))
3553 : : return intSI_type_node;
3554 : 0 : if (bits <= TYPE_PRECISION (intDI_type_node))
3555 : : return intDI_type_node;
3556 : 0 : if (bits <= TYPE_PRECISION (intTI_type_node))
3557 : : return intTI_type_node;
3558 : : }
3559 : : else
3560 : : {
3561 : 680422 : if (bits <= TYPE_PRECISION (unsigned_intQI_type_node))
3562 : : return unsigned_intQI_type_node;
3563 : 617975 : if (bits <= TYPE_PRECISION (unsigned_intHI_type_node))
3564 : : return unsigned_intHI_type_node;
3565 : 586020 : if (bits <= TYPE_PRECISION (unsigned_intSI_type_node))
3566 : : return unsigned_intSI_type_node;
3567 : 545017 : if (bits <= TYPE_PRECISION (unsigned_intDI_type_node))
3568 : : return unsigned_intDI_type_node;
3569 : 30343 : if (bits <= TYPE_PRECISION (unsigned_intTI_type_node))
3570 : : return unsigned_intTI_type_node;
3571 : : }
3572 : :
3573 : : return NULL_TREE;
3574 : : }
3575 : :
3576 : : /* Return a data type that has machine mode MODE. If the mode is an
3577 : : integer, then UNSIGNEDP selects between signed and unsigned types. */
3578 : :
3579 : : tree
3580 : 756703 : gfc_type_for_mode (machine_mode mode, int unsignedp)
3581 : : {
3582 : 756703 : int i;
3583 : 756703 : tree *base;
3584 : 756703 : scalar_int_mode int_mode;
3585 : :
3586 : 756703 : if (GET_MODE_CLASS (mode) == MODE_FLOAT)
3587 : : base = gfc_real_types;
3588 : 749621 : else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3589 : : base = gfc_complex_types;
3590 : 567775 : else if (is_a <scalar_int_mode> (mode, &int_mode))
3591 : : {
3592 : 566043 : tree type = gfc_type_for_size (GET_MODE_PRECISION (int_mode), unsignedp);
3593 : 566043 : return type != NULL_TREE && mode == TYPE_MODE (type) ? type : NULL_TREE;
3594 : : }
3595 : 1732 : else if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
3596 : 1732 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
3597 : : {
3598 : 0 : unsigned int elem_bits = vector_element_size (GET_MODE_PRECISION (mode),
3599 : : GET_MODE_NUNITS (mode));
3600 : 0 : tree bool_type = build_nonstandard_boolean_type (elem_bits);
3601 : 0 : return build_vector_type_for_mode (bool_type, mode);
3602 : : }
3603 : 35 : else if (VECTOR_MODE_P (mode)
3604 : 3461 : && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
3605 : : {
3606 : 1729 : machine_mode inner_mode = GET_MODE_INNER (mode);
3607 : 1729 : tree inner_type = gfc_type_for_mode (inner_mode, unsignedp);
3608 : 1729 : if (inner_type != NULL_TREE)
3609 : 1729 : return build_vector_type_for_mode (inner_type, mode);
3610 : : return NULL_TREE;
3611 : : }
3612 : : else
3613 : 3 : return NULL_TREE;
3614 : :
3615 : 738320 : for (i = 0; i <= MAX_REAL_KINDS; ++i)
3616 : : {
3617 : 678024 : tree type = base[i];
3618 : 678024 : if (type && mode == TYPE_MODE (type))
3619 : 128632 : return type;
3620 : : }
3621 : :
3622 : : return NULL_TREE;
3623 : : }
3624 : :
3625 : : /* Return TRUE if TYPE is a type with a hidden descriptor, fill in INFO
3626 : : in that case. */
3627 : :
3628 : : bool
3629 : 365488 : gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
3630 : : {
3631 : 365488 : int rank, dim;
3632 : 365488 : bool indirect = false;
3633 : 365488 : tree etype, ptype, t, base_decl;
3634 : 365488 : tree data_off, span_off, dim_off, dtype_off, dim_size, elem_size;
3635 : 365488 : tree lower_suboff, upper_suboff, stride_suboff;
3636 : 365488 : tree dtype, field, rank_off;
3637 : :
3638 : 365488 : if (! GFC_DESCRIPTOR_TYPE_P (type))
3639 : : {
3640 : 233393 : if (! POINTER_TYPE_P (type))
3641 : : return false;
3642 : 146980 : type = TREE_TYPE (type);
3643 : 146980 : if (! GFC_DESCRIPTOR_TYPE_P (type))
3644 : : return false;
3645 : : indirect = true;
3646 : : }
3647 : :
3648 : 259077 : rank = GFC_TYPE_ARRAY_RANK (type);
3649 : 259077 : if (rank >= (int) (ARRAY_SIZE (info->dimen)))
3650 : : return false;
3651 : :
3652 : 259077 : etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
3653 : 259077 : gcc_assert (POINTER_TYPE_P (etype));
3654 : 259077 : etype = TREE_TYPE (etype);
3655 : :
3656 : : /* If the type is not a scalar coarray. */
3657 : 259077 : if (TREE_CODE (etype) == ARRAY_TYPE)
3658 : 259053 : etype = TREE_TYPE (etype);
3659 : :
3660 : : /* Can't handle variable sized elements yet. */
3661 : 259077 : if (int_size_in_bytes (etype) <= 0)
3662 : : return false;
3663 : : /* Nor non-constant lower bounds in assumed shape arrays. */
3664 : 241814 : if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE
3665 : 241814 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE_CONT)
3666 : : {
3667 : 76208 : for (dim = 0; dim < rank; dim++)
3668 : 46940 : if (GFC_TYPE_ARRAY_LBOUND (type, dim) == NULL_TREE
3669 : 46940 : || TREE_CODE (GFC_TYPE_ARRAY_LBOUND (type, dim)) != INTEGER_CST)
3670 : : return false;
3671 : : }
3672 : :
3673 : 241732 : memset (info, '\0', sizeof (*info));
3674 : 241732 : info->ndimensions = rank;
3675 : 241732 : info->ordering = array_descr_ordering_column_major;
3676 : 241732 : info->element_type = etype;
3677 : 241732 : ptype = build_pointer_type (gfc_array_index_type);
3678 : 241732 : base_decl = GFC_TYPE_ARRAY_BASE_DECL (type, indirect);
3679 : 241732 : if (!base_decl)
3680 : : {
3681 : 352280 : base_decl = build_debug_expr_decl (indirect
3682 : 117420 : ? build_pointer_type (ptype) : ptype);
3683 : 234860 : GFC_TYPE_ARRAY_BASE_DECL (type, indirect) = base_decl;
3684 : : }
3685 : 241732 : info->base_decl = base_decl;
3686 : 241732 : if (indirect)
3687 : 118792 : base_decl = build1 (INDIRECT_REF, ptype, base_decl);
3688 : :
3689 : 241732 : gfc_get_descriptor_offsets_for_info (type, &data_off, &dtype_off, &span_off,
3690 : : &dim_off, &dim_size, &stride_suboff,
3691 : : &lower_suboff, &upper_suboff);
3692 : :
3693 : 241732 : t = fold_build_pointer_plus (base_decl, span_off);
3694 : 241732 : elem_size = build1 (INDIRECT_REF, gfc_array_index_type, t);
3695 : :
3696 : 241732 : t = base_decl;
3697 : 241732 : if (!integer_zerop (data_off))
3698 : 0 : t = fold_build_pointer_plus (t, data_off);
3699 : 241732 : t = build1 (NOP_EXPR, build_pointer_type (ptr_type_node), t);
3700 : 241732 : info->data_location = build1 (INDIRECT_REF, ptr_type_node, t);
3701 : 241732 : if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ALLOCATABLE)
3702 : 23936 : info->allocated = build2 (NE_EXPR, logical_type_node,
3703 : : info->data_location, null_pointer_node);
3704 : 217796 : else if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER
3705 : 217796 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_POINTER_CONT)
3706 : 14498 : info->associated = build2 (NE_EXPR, logical_type_node,
3707 : : info->data_location, null_pointer_node);
3708 : 241732 : if ((GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK
3709 : 233873 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_RANK_CONT)
3710 : 246296 : && dwarf_version >= 5)
3711 : : {
3712 : 12423 : rank = 1;
3713 : 12423 : info->ndimensions = 1;
3714 : 12423 : t = fold_build_pointer_plus (base_decl, dtype_off);
3715 : 12423 : dtype = TYPE_MAIN_VARIANT (get_dtype_type_node ());
3716 : 12423 : field = gfc_advance_chain (TYPE_FIELDS (dtype), GFC_DTYPE_RANK);
3717 : 12423 : rank_off = byte_position (field);
3718 : 12423 : t = fold_build_pointer_plus (t, rank_off);
3719 : :
3720 : 12423 : t = build1 (NOP_EXPR, build_pointer_type (TREE_TYPE (field)), t);
3721 : 12423 : t = build1 (INDIRECT_REF, TREE_TYPE (field), t);
3722 : 12423 : info->rank = t;
3723 : 12423 : t = build0 (PLACEHOLDER_EXPR, TREE_TYPE (dim_off));
3724 : 12423 : t = size_binop (MULT_EXPR, t, dim_size);
3725 : 12423 : dim_off = build2 (PLUS_EXPR, TREE_TYPE (dim_off), t, dim_off);
3726 : : }
3727 : :
3728 : 591231 : for (dim = 0; dim < rank; dim++)
3729 : : {
3730 : 349499 : t = fold_build_pointer_plus (base_decl,
3731 : : size_binop (PLUS_EXPR,
3732 : : dim_off, lower_suboff));
3733 : 349499 : t = build1 (INDIRECT_REF, gfc_array_index_type, t);
3734 : 349499 : info->dimen[dim].lower_bound = t;
3735 : 349499 : t = fold_build_pointer_plus (base_decl,
3736 : : size_binop (PLUS_EXPR,
3737 : : dim_off, upper_suboff));
3738 : 349499 : t = build1 (INDIRECT_REF, gfc_array_index_type, t);
3739 : 349499 : info->dimen[dim].upper_bound = t;
3740 : 349499 : if (GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE
3741 : 349499 : || GFC_TYPE_ARRAY_AKIND (type) == GFC_ARRAY_ASSUMED_SHAPE_CONT)
3742 : : {
3743 : : /* Assumed shape arrays have known lower bounds. */
3744 : 46858 : info->dimen[dim].upper_bound
3745 : 46858 : = build2 (MINUS_EXPR, gfc_array_index_type,
3746 : : info->dimen[dim].upper_bound,
3747 : : info->dimen[dim].lower_bound);
3748 : 46858 : info->dimen[dim].lower_bound
3749 : 46858 : = fold_convert (gfc_array_index_type,
3750 : : GFC_TYPE_ARRAY_LBOUND (type, dim));
3751 : 46858 : info->dimen[dim].upper_bound
3752 : 46858 : = build2 (PLUS_EXPR, gfc_array_index_type,
3753 : : info->dimen[dim].lower_bound,
3754 : : info->dimen[dim].upper_bound);
3755 : : }
3756 : 349499 : t = fold_build_pointer_plus (base_decl,
3757 : : size_binop (PLUS_EXPR,
3758 : : dim_off, stride_suboff));
3759 : 349499 : t = build1 (INDIRECT_REF, gfc_array_index_type, t);
3760 : 349499 : t = build2 (MULT_EXPR, gfc_array_index_type, t, elem_size);
3761 : 349499 : info->dimen[dim].stride = t;
3762 : 349499 : if (dim + 1 < rank)
3763 : 107791 : dim_off = size_binop (PLUS_EXPR, dim_off, dim_size);
3764 : : }
3765 : :
3766 : : return true;
3767 : : }
3768 : :
3769 : :
3770 : : /* Create a type to handle vector subscripts for coarray library calls. It
3771 : : has the form:
3772 : : struct caf_vector_t {
3773 : : size_t nvec; // size of the vector
3774 : : union {
3775 : : struct {
3776 : : void *vector;
3777 : : int kind;
3778 : : } v;
3779 : : struct {
3780 : : ptrdiff_t lower_bound;
3781 : : ptrdiff_t upper_bound;
3782 : : ptrdiff_t stride;
3783 : : } triplet;
3784 : : } u;
3785 : : }
3786 : : where nvec == 0 for DIMEN_ELEMENT or DIMEN_RANGE and nvec being the vector
3787 : : size in case of DIMEN_VECTOR, where kind is the integer type of the vector. */
3788 : :
3789 : : tree
3790 : 0 : gfc_get_caf_vector_type (int dim)
3791 : : {
3792 : 0 : static tree vector_types[GFC_MAX_DIMENSIONS];
3793 : 0 : static tree vec_type = NULL_TREE;
3794 : 0 : tree triplet_struct_type, vect_struct_type, union_type, tmp, *chain;
3795 : :
3796 : 0 : if (vector_types[dim-1] != NULL_TREE)
3797 : : return vector_types[dim-1];
3798 : :
3799 : 0 : if (vec_type == NULL_TREE)
3800 : : {
3801 : 0 : chain = 0;
3802 : 0 : vect_struct_type = make_node (RECORD_TYPE);
3803 : 0 : tmp = gfc_add_field_to_struct_1 (vect_struct_type,
3804 : : get_identifier ("vector"),
3805 : : pvoid_type_node, &chain);
3806 : 0 : suppress_warning (tmp);
3807 : 0 : tmp = gfc_add_field_to_struct_1 (vect_struct_type,
3808 : : get_identifier ("kind"),
3809 : : integer_type_node, &chain);
3810 : 0 : suppress_warning (tmp);
3811 : 0 : gfc_finish_type (vect_struct_type);
3812 : :
3813 : 0 : chain = 0;
3814 : 0 : triplet_struct_type = make_node (RECORD_TYPE);
3815 : 0 : tmp = gfc_add_field_to_struct_1 (triplet_struct_type,
3816 : : get_identifier ("lower_bound"),
3817 : : gfc_array_index_type, &chain);
3818 : 0 : suppress_warning (tmp);
3819 : 0 : tmp = gfc_add_field_to_struct_1 (triplet_struct_type,
3820 : : get_identifier ("upper_bound"),
3821 : : gfc_array_index_type, &chain);
3822 : 0 : suppress_warning (tmp);
3823 : 0 : tmp = gfc_add_field_to_struct_1 (triplet_struct_type, get_identifier ("stride"),
3824 : : gfc_array_index_type, &chain);
3825 : 0 : suppress_warning (tmp);
3826 : 0 : gfc_finish_type (triplet_struct_type);
3827 : :
3828 : 0 : chain = 0;
3829 : 0 : union_type = make_node (UNION_TYPE);
3830 : 0 : tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("v"),
3831 : : vect_struct_type, &chain);
3832 : 0 : suppress_warning (tmp);
3833 : 0 : tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("triplet"),
3834 : : triplet_struct_type, &chain);
3835 : 0 : suppress_warning (tmp);
3836 : 0 : gfc_finish_type (union_type);
3837 : :
3838 : 0 : chain = 0;
3839 : 0 : vec_type = make_node (RECORD_TYPE);
3840 : 0 : tmp = gfc_add_field_to_struct_1 (vec_type, get_identifier ("nvec"),
3841 : : size_type_node, &chain);
3842 : 0 : suppress_warning (tmp);
3843 : 0 : tmp = gfc_add_field_to_struct_1 (vec_type, get_identifier ("u"),
3844 : : union_type, &chain);
3845 : 0 : suppress_warning (tmp);
3846 : 0 : gfc_finish_type (vec_type);
3847 : 0 : TYPE_NAME (vec_type) = get_identifier ("caf_vector_t");
3848 : : }
3849 : :
3850 : 0 : tmp = build_range_type (gfc_array_index_type, gfc_index_zero_node,
3851 : : gfc_rank_cst[dim-1]);
3852 : 0 : vector_types[dim-1] = build_array_type (vec_type, tmp);
3853 : 0 : return vector_types[dim-1];
3854 : : }
3855 : :
3856 : :
3857 : : tree
3858 : 1867 : gfc_get_caf_reference_type ()
3859 : : {
3860 : 1867 : static tree reference_type = NULL_TREE;
3861 : 1867 : tree c_struct_type, s_struct_type, v_struct_type, union_type, dim_union_type,
3862 : : a_struct_type, u_union_type, tmp, *chain;
3863 : :
3864 : 1867 : if (reference_type != NULL_TREE)
3865 : : return reference_type;
3866 : :
3867 : 90 : chain = 0;
3868 : 90 : c_struct_type = make_node (RECORD_TYPE);
3869 : 90 : tmp = gfc_add_field_to_struct_1 (c_struct_type,
3870 : : get_identifier ("offset"),
3871 : : gfc_array_index_type, &chain);
3872 : 90 : suppress_warning (tmp);
3873 : 90 : tmp = gfc_add_field_to_struct_1 (c_struct_type,
3874 : : get_identifier ("caf_token_offset"),
3875 : : gfc_array_index_type, &chain);
3876 : 90 : suppress_warning (tmp);
3877 : 90 : gfc_finish_type (c_struct_type);
3878 : :
3879 : 90 : chain = 0;
3880 : 90 : s_struct_type = make_node (RECORD_TYPE);
3881 : 90 : tmp = gfc_add_field_to_struct_1 (s_struct_type,
3882 : : get_identifier ("start"),
3883 : : gfc_array_index_type, &chain);
3884 : 90 : suppress_warning (tmp);
3885 : 90 : tmp = gfc_add_field_to_struct_1 (s_struct_type,
3886 : : get_identifier ("end"),
3887 : : gfc_array_index_type, &chain);
3888 : 90 : suppress_warning (tmp);
3889 : 90 : tmp = gfc_add_field_to_struct_1 (s_struct_type,
3890 : : get_identifier ("stride"),
3891 : : gfc_array_index_type, &chain);
3892 : 90 : suppress_warning (tmp);
3893 : 90 : gfc_finish_type (s_struct_type);
3894 : :
3895 : 90 : chain = 0;
3896 : 90 : v_struct_type = make_node (RECORD_TYPE);
3897 : 90 : tmp = gfc_add_field_to_struct_1 (v_struct_type,
3898 : : get_identifier ("vector"),
3899 : : pvoid_type_node, &chain);
3900 : 90 : suppress_warning (tmp);
3901 : 90 : tmp = gfc_add_field_to_struct_1 (v_struct_type,
3902 : : get_identifier ("nvec"),
3903 : : size_type_node, &chain);
3904 : 90 : suppress_warning (tmp);
3905 : 90 : tmp = gfc_add_field_to_struct_1 (v_struct_type,
3906 : : get_identifier ("kind"),
3907 : : integer_type_node, &chain);
3908 : 90 : suppress_warning (tmp);
3909 : 90 : gfc_finish_type (v_struct_type);
3910 : :
3911 : 90 : chain = 0;
3912 : 90 : union_type = make_node (UNION_TYPE);
3913 : 90 : tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("s"),
3914 : : s_struct_type, &chain);
3915 : 90 : suppress_warning (tmp);
3916 : 90 : tmp = gfc_add_field_to_struct_1 (union_type, get_identifier ("v"),
3917 : : v_struct_type, &chain);
3918 : 90 : suppress_warning (tmp);
3919 : 90 : gfc_finish_type (union_type);
3920 : :
3921 : 90 : tmp = build_range_type (gfc_array_index_type, gfc_index_zero_node,
3922 : : gfc_rank_cst[GFC_MAX_DIMENSIONS - 1]);
3923 : 90 : dim_union_type = build_array_type (union_type, tmp);
3924 : :
3925 : 90 : chain = 0;
3926 : 90 : a_struct_type = make_node (RECORD_TYPE);
3927 : 90 : tmp = gfc_add_field_to_struct_1 (a_struct_type, get_identifier ("mode"),
3928 : : build_array_type (unsigned_char_type_node,
3929 : : build_range_type (gfc_array_index_type,
3930 : : gfc_index_zero_node,
3931 : : gfc_rank_cst[GFC_MAX_DIMENSIONS - 1])),
3932 : : &chain);
3933 : 90 : suppress_warning (tmp);
3934 : 90 : tmp = gfc_add_field_to_struct_1 (a_struct_type,
3935 : : get_identifier ("static_array_type"),
3936 : : integer_type_node, &chain);
3937 : 90 : suppress_warning (tmp);
3938 : 90 : tmp = gfc_add_field_to_struct_1 (a_struct_type, get_identifier ("dim"),
3939 : : dim_union_type, &chain);
3940 : 90 : suppress_warning (tmp);
3941 : 90 : gfc_finish_type (a_struct_type);
3942 : :
3943 : 90 : chain = 0;
3944 : 90 : u_union_type = make_node (UNION_TYPE);
3945 : 90 : tmp = gfc_add_field_to_struct_1 (u_union_type, get_identifier ("c"),
3946 : : c_struct_type, &chain);
3947 : 90 : suppress_warning (tmp);
3948 : 90 : tmp = gfc_add_field_to_struct_1 (u_union_type, get_identifier ("a"),
3949 : : a_struct_type, &chain);
3950 : 90 : suppress_warning (tmp);
3951 : 90 : gfc_finish_type (u_union_type);
3952 : :
3953 : 90 : chain = 0;
3954 : 90 : reference_type = make_node (RECORD_TYPE);
3955 : 90 : tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("next"),
3956 : : build_pointer_type (reference_type), &chain);
3957 : 90 : suppress_warning (tmp);
3958 : 90 : tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("type"),
3959 : : integer_type_node, &chain);
3960 : 90 : suppress_warning (tmp);
3961 : 90 : tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("item_size"),
3962 : : size_type_node, &chain);
3963 : 90 : suppress_warning (tmp);
3964 : 90 : tmp = gfc_add_field_to_struct_1 (reference_type, get_identifier ("u"),
3965 : : u_union_type, &chain);
3966 : 90 : suppress_warning (tmp);
3967 : 90 : gfc_finish_type (reference_type);
3968 : 90 : TYPE_NAME (reference_type) = get_identifier ("caf_reference_t");
3969 : :
3970 : 90 : return reference_type;
3971 : : }
3972 : :
3973 : : static tree
3974 : 1328 : gfc_get_cfi_dim_type ()
3975 : : {
3976 : 1328 : static tree CFI_dim_t = NULL;
3977 : :
3978 : 1328 : if (CFI_dim_t)
3979 : : return CFI_dim_t;
3980 : :
3981 : 630 : CFI_dim_t = make_node (RECORD_TYPE);
3982 : 630 : TYPE_NAME (CFI_dim_t) = get_identifier ("CFI_dim_t");
3983 : 630 : TYPE_NAMELESS (CFI_dim_t) = 1;
3984 : 630 : tree field;
3985 : 630 : tree *chain = NULL;
3986 : 630 : field = gfc_add_field_to_struct_1 (CFI_dim_t, get_identifier ("lower_bound"),
3987 : : gfc_array_index_type, &chain);
3988 : 630 : suppress_warning (field);
3989 : 630 : field = gfc_add_field_to_struct_1 (CFI_dim_t, get_identifier ("extent"),
3990 : : gfc_array_index_type, &chain);
3991 : 630 : suppress_warning (field);
3992 : 630 : field = gfc_add_field_to_struct_1 (CFI_dim_t, get_identifier ("sm"),
3993 : : gfc_array_index_type, &chain);
3994 : 630 : suppress_warning (field);
3995 : 630 : gfc_finish_type (CFI_dim_t);
3996 : 630 : TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (CFI_dim_t)) = 1;
3997 : 630 : return CFI_dim_t;
3998 : : }
3999 : :
4000 : :
4001 : : /* Return the CFI type; use dimen == -1 for dim[] (only for pointers);
4002 : : otherwise dim[dimen] is used. */
4003 : :
4004 : : tree
4005 : 12484 : gfc_get_cfi_type (int dimen, bool restricted)
4006 : : {
4007 : 12484 : gcc_assert (dimen >= -1 && dimen <= CFI_MAX_RANK);
4008 : :
4009 : 12484 : int idx = 2*(dimen + 1) + restricted;
4010 : :
4011 : 12484 : if (gfc_cfi_descriptor_base[idx])
4012 : : return gfc_cfi_descriptor_base[idx];
4013 : :
4014 : : /* Build the type node. */
4015 : 1506 : tree CFI_cdesc_t = make_node (RECORD_TYPE);
4016 : 1506 : char name[GFC_MAX_SYMBOL_LEN + 1];
4017 : 1506 : if (dimen != -1)
4018 : 957 : sprintf (name, "CFI_cdesc_t" GFC_RANK_PRINTF_FORMAT, dimen);
4019 : 1506 : TYPE_NAME (CFI_cdesc_t) = get_identifier (dimen < 0 ? "CFI_cdesc_t" : name);
4020 : 1506 : TYPE_NAMELESS (CFI_cdesc_t) = 1;
4021 : :
4022 : 1506 : tree field;
4023 : 1506 : tree *chain = NULL;
4024 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("base_addr"),
4025 : : (restricted ? prvoid_type_node
4026 : : : ptr_type_node), &chain);
4027 : 1506 : suppress_warning (field);
4028 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("elem_len"),
4029 : : size_type_node, &chain);
4030 : 1506 : suppress_warning (field);
4031 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("version"),
4032 : : integer_type_node, &chain);
4033 : 1506 : suppress_warning (field);
4034 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("rank"),
4035 : : signed_char_type_node, &chain);
4036 : 1506 : suppress_warning (field);
4037 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("attribute"),
4038 : : signed_char_type_node, &chain);
4039 : 1506 : suppress_warning (field);
4040 : 1506 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("type"),
4041 : : get_typenode_from_name (INT16_TYPE),
4042 : : &chain);
4043 : 1506 : suppress_warning (field);
4044 : :
4045 : 1506 : if (dimen != 0)
4046 : : {
4047 : 1328 : tree range = NULL_TREE;
4048 : 1328 : if (dimen > 0)
4049 : 779 : range = gfc_rank_cst[dimen - 1];
4050 : 1328 : range = build_range_type (gfc_array_index_type, gfc_index_zero_node,
4051 : : range);
4052 : 1328 : tree CFI_dim_t = build_array_type (gfc_get_cfi_dim_type (), range);
4053 : 1328 : field = gfc_add_field_to_struct_1 (CFI_cdesc_t, get_identifier ("dim"),
4054 : : CFI_dim_t, &chain);
4055 : 1328 : suppress_warning (field);
4056 : : }
4057 : :
4058 : 1506 : TYPE_TYPELESS_STORAGE (CFI_cdesc_t) = 1;
4059 : 1506 : gfc_finish_type (CFI_cdesc_t);
4060 : 1506 : gfc_cfi_descriptor_base[idx] = CFI_cdesc_t;
4061 : 1506 : return CFI_cdesc_t;
4062 : : }
4063 : :
4064 : : #include "gt-fortran-trans-types.h"
|