1 /* Backend support for Fortran 95 basic types and derived types.
2 Copyright (C) 2002-2025 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
4 and Steven Bosscher <s.bosscher@student.tudelft.nl>
6 This file is part of GCC.
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
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
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/>. */
22 /* trans-types.cc -- gfortran backend types */
26 #include "coretypes.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. */
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"
51 #error If you really need >99 dimensions, continue the sequence above...
54 /* array of structs so we don't have to worry about xmalloc or free */
55 CInteropKind_t c_interop_kinds_table
[ISOCBINDING_NUMBER
];
57 tree gfc_array_index_type
;
58 tree gfc_array_range_type
;
59 tree gfc_character1_type_node
;
61 tree prvoid_type_node
;
62 tree ppvoid_type_node
;
64 static tree pfunc_type_node
;
66 tree logical_type_node
;
67 tree logical_true_node
;
68 tree logical_false_node
;
69 tree gfc_charlen_type_node
;
71 tree gfc_float128_type_node
= NULL_TREE
;
72 tree gfc_complex_float128_type_node
= NULL_TREE
;
74 bool gfc_real16_is_float128
= false;
75 bool gfc_real16_use_iec_60559
= false;
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)];
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. */
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];
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];
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];
104 static tree
gfc_add_field_to_struct_1 (tree
, tree
, tree
, tree
**);
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. */
109 int gfc_index_integer_kind
;
111 /* The default kinds of the various types. */
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
;
123 int gfc_c_intptr_kind
;
124 int gfc_atomic_int_kind
;
125 int gfc_atomic_logical_kind
;
127 /* The kind size used for record offsets. If the target system supports
128 kind=8, this will be set to 8, otherwise it is set to 4. */
131 /* The integer kind used to store character lengths. */
132 int gfc_charlen_int_kind
;
134 /* Kind of internal integer for storing object sizes. */
137 /* The size of the numeric storage unit and character storage unit. */
138 int gfc_numeric_storage_size
;
139 int gfc_character_storage_size
;
141 static tree dtype_type_node
= NULL_TREE
;
144 /* Build the dtype_type_node if necessary. */
145 tree
get_dtype_type_node (void)
149 tree
*dtype_chain
= NULL
;
151 if (dtype_type_node
== NULL_TREE
)
153 dtype_node
= make_node (RECORD_TYPE
);
154 TYPE_NAME (dtype_node
) = get_identifier ("dtype_type");
155 TYPE_NAMELESS (dtype_node
) = 1;
156 field
= gfc_add_field_to_struct_1 (dtype_node
,
157 get_identifier ("elem_len"),
158 size_type_node
, &dtype_chain
);
159 suppress_warning (field
);
160 field
= gfc_add_field_to_struct_1 (dtype_node
,
161 get_identifier ("version"),
162 integer_type_node
, &dtype_chain
);
163 suppress_warning (field
);
164 field
= gfc_add_field_to_struct_1 (dtype_node
,
165 get_identifier ("rank"),
166 signed_char_type_node
, &dtype_chain
);
167 suppress_warning (field
);
168 field
= gfc_add_field_to_struct_1 (dtype_node
,
169 get_identifier ("type"),
170 signed_char_type_node
, &dtype_chain
);
171 suppress_warning (field
);
172 field
= gfc_add_field_to_struct_1 (dtype_node
,
173 get_identifier ("attribute"),
174 short_integer_type_node
, &dtype_chain
);
175 suppress_warning (field
);
176 gfc_finish_type (dtype_node
);
177 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (dtype_node
)) = 1;
178 dtype_type_node
= dtype_node
;
180 return dtype_type_node
;
184 get_real_kind_from_node (tree type
)
188 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
189 if (gfc_real_kinds
[i
].mode_precision
== TYPE_PRECISION (type
))
191 /* On Power, we have three 128-bit scalar floating-point modes
192 and all of their types have 128 bit type precision, so we
193 should check underlying real format details further. */
194 #if defined(HAVE_TFmode) && defined(HAVE_IFmode) && defined(HAVE_KFmode)
195 if (gfc_real_kinds
[i
].kind
== 16)
197 machine_mode mode
= TYPE_MODE (type
);
198 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
199 if (fmt
->p
!= gfc_real_kinds
[i
].digits
)
203 return gfc_real_kinds
[i
].kind
;
210 get_int_kind_from_node (tree type
)
217 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
218 if (gfc_integer_kinds
[i
].bit_size
== TYPE_PRECISION (type
))
219 return gfc_integer_kinds
[i
].kind
;
225 get_int_kind_from_name (const char *name
)
227 return get_int_kind_from_node (get_typenode_from_name (name
));
231 get_unsigned_kind_from_node (tree type
)
238 for (i
= 0; gfc_unsigned_kinds
[i
].kind
!= 0; i
++)
239 if (gfc_unsigned_kinds
[i
].bit_size
== TYPE_PRECISION (type
))
240 return gfc_unsigned_kinds
[i
].kind
;
246 get_uint_kind_from_name (const char *name
)
248 return get_unsigned_kind_from_node (get_typenode_from_name (name
));
251 /* Get the kind number corresponding to an integer of given size,
252 following the required return values for ISO_FORTRAN_ENV INT* constants:
253 -2 is returned if we support a kind of larger size, -1 otherwise. */
255 gfc_get_int_kind_from_width_isofortranenv (int size
)
259 /* Look for a kind with matching storage size. */
260 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
261 if (gfc_integer_kinds
[i
].bit_size
== size
)
262 return gfc_integer_kinds
[i
].kind
;
264 /* Look for a kind with larger storage size. */
265 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
266 if (gfc_integer_kinds
[i
].bit_size
> size
)
272 /* Same, but for unsigned. */
275 gfc_get_uint_kind_from_width_isofortranenv (int size
)
279 /* Look for a kind with matching storage size. */
280 for (i
= 0; gfc_unsigned_kinds
[i
].kind
!= 0; i
++)
281 if (gfc_unsigned_kinds
[i
].bit_size
== size
)
282 return gfc_unsigned_kinds
[i
].kind
;
284 /* Look for a kind with larger storage size. */
285 for (i
= 0; gfc_unsigned_kinds
[i
].kind
!= 0; i
++)
286 if (gfc_unsigned_kinds
[i
].bit_size
> size
)
293 /* Get the kind number corresponding to a real of a given storage size.
294 If two real's have the same storage size, then choose the real with
295 the largest precision. If a kind type is unavailable and a real
296 exists with wider storage, then return -2; otherwise, return -1. */
299 gfc_get_real_kind_from_width_isofortranenv (int size
)
308 /* Look for a kind with matching storage size. */
309 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
310 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) == size
)
312 if (gfc_real_kinds
[i
].digits
> digits
)
314 digits
= gfc_real_kinds
[i
].digits
;
315 kind
= gfc_real_kinds
[i
].kind
;
322 /* Look for a kind with larger storage size. */
323 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
324 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) > size
)
333 get_int_kind_from_width (int size
)
337 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
338 if (gfc_integer_kinds
[i
].bit_size
== size
)
339 return gfc_integer_kinds
[i
].kind
;
345 get_int_kind_from_minimal_width (int size
)
349 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
350 if (gfc_integer_kinds
[i
].bit_size
>= size
)
351 return gfc_integer_kinds
[i
].kind
;
357 get_uint_kind_from_width (int size
)
361 for (i
= 0; gfc_unsigned_kinds
[i
].kind
!= 0; i
++)
362 if (gfc_integer_kinds
[i
].bit_size
== size
)
363 return gfc_integer_kinds
[i
].kind
;
369 /* Generate the CInteropKind_t objects for the C interoperable
373 gfc_init_c_interop_kinds (void)
377 /* init all pointers in the list to NULL */
378 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
380 /* Initialize the name and value fields. */
381 c_interop_kinds_table
[i
].name
[0] = '\0';
382 c_interop_kinds_table
[i
].value
= -100;
383 c_interop_kinds_table
[i
].f90_type
= BT_UNKNOWN
;
386 #define NAMED_INTCST(a,b,c,d) \
387 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
388 c_interop_kinds_table[a].f90_type = BT_INTEGER; \
389 c_interop_kinds_table[a].value = c;
390 #define NAMED_UINTCST(a,b,c,d) \
391 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
392 c_interop_kinds_table[a].f90_type = BT_UNSIGNED; \
393 c_interop_kinds_table[a].value = c;
394 #define NAMED_REALCST(a,b,c,d) \
395 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
396 c_interop_kinds_table[a].f90_type = BT_REAL; \
397 c_interop_kinds_table[a].value = c;
398 #define NAMED_CMPXCST(a,b,c,d) \
399 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
400 c_interop_kinds_table[a].f90_type = BT_COMPLEX; \
401 c_interop_kinds_table[a].value = c;
402 #define NAMED_LOGCST(a,b,c) \
403 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
404 c_interop_kinds_table[a].f90_type = BT_LOGICAL; \
405 c_interop_kinds_table[a].value = c;
406 #define NAMED_CHARKNDCST(a,b,c) \
407 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
408 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
409 c_interop_kinds_table[a].value = c;
410 #define NAMED_CHARCST(a,b,c) \
411 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
412 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
413 c_interop_kinds_table[a].value = c;
414 #define DERIVED_TYPE(a,b,c) \
415 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
416 c_interop_kinds_table[a].f90_type = BT_DERIVED; \
417 c_interop_kinds_table[a].value = c;
418 #define NAMED_FUNCTION(a,b,c,d) \
419 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
420 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
421 c_interop_kinds_table[a].value = c;
422 #define NAMED_SUBROUTINE(a,b,c,d) \
423 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
424 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
425 c_interop_kinds_table[a].value = c;
426 #include "iso-c-binding.def"
430 /* Query the target to determine which machine modes are available for
431 computation. Choose KIND numbers for them. */
434 gfc_init_kinds (void)
436 opt_scalar_int_mode int_mode_iter
;
437 opt_scalar_float_mode float_mode_iter
;
438 int i_index
, r_index
, kind
;
439 bool saw_i4
= false, saw_i8
= false;
440 bool saw_r4
= false, saw_r8
= false, saw_r10
= false, saw_r16
= false;
441 scalar_mode r16_mode
= QImode
;
442 scalar_mode composite_mode
= QImode
;
445 FOR_EACH_MODE_IN_CLASS (int_mode_iter
, MODE_INT
)
447 scalar_int_mode mode
= int_mode_iter
.require ();
450 if (!targetm
.scalar_mode_supported_p (mode
))
453 /* The middle end doesn't support constants larger than 2*HWI.
454 Perhaps the target hook shouldn't have accepted these either,
455 but just to be safe... */
456 bitsize
= GET_MODE_BITSIZE (mode
);
457 if (bitsize
> 2*HOST_BITS_PER_WIDE_INT
)
460 gcc_assert (i_index
!= MAX_INT_KINDS
);
462 /* Let the kind equal the bit size divided by 8. This insulates the
463 programmer from the underlying byte size. */
471 gfc_integer_kinds
[i_index
].kind
= kind
;
472 gfc_integer_kinds
[i_index
].radix
= 2;
473 gfc_integer_kinds
[i_index
].digits
= bitsize
- 1;
474 gfc_integer_kinds
[i_index
].bit_size
= bitsize
;
478 gfc_unsigned_kinds
[i_index
].kind
= kind
;
479 gfc_unsigned_kinds
[i_index
].radix
= 2;
480 gfc_unsigned_kinds
[i_index
].digits
= bitsize
;
481 gfc_unsigned_kinds
[i_index
].bit_size
= bitsize
;
484 gfc_logical_kinds
[i_index
].kind
= kind
;
485 gfc_logical_kinds
[i_index
].bit_size
= bitsize
;
490 /* Set the kind used to match GFC_INT_IO in libgfortran. This is
491 used for large file access. */
498 /* If we do not at least have kind = 4, everything is pointless. */
501 /* Set the maximum integer kind. Used with at least BOZ constants. */
502 gfc_max_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
505 FOR_EACH_MODE_IN_CLASS (float_mode_iter
, MODE_FLOAT
)
507 scalar_float_mode mode
= float_mode_iter
.require ();
508 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
513 if (!targetm
.scalar_mode_supported_p (mode
))
516 if (MODE_COMPOSITE_P (mode
)
517 && (GET_MODE_PRECISION (mode
) + 7) / 8 == 16)
518 composite_mode
= mode
;
520 /* Only let float, double, long double and TFmode go through.
521 Runtime support for others is not provided, so they would be
523 if (!targetm
.libgcc_floating_mode_supported_p (mode
))
525 if (mode
!= TYPE_MODE (float_type_node
)
526 && (mode
!= TYPE_MODE (double_type_node
))
527 && (mode
!= TYPE_MODE (long_double_type_node
))
528 #if defined(HAVE_TFmode) && defined(ENABLE_LIBQUADMATH_SUPPORT)
534 /* Let the kind equal the precision divided by 8, rounding up. Again,
535 this insulates the programmer from the underlying byte size.
537 Also, it effectively deals with IEEE extended formats. There, the
538 total size of the type may equal 16, but it's got 6 bytes of padding
539 and the increased size can get in the way of a real IEEE quad format
540 which may also be supported by the target.
542 We round up so as to handle IA-64 __floatreg (RFmode), which is an
543 82 bit type. Not to be confused with __float80 (XFmode), which is
544 an 80 bit type also supported by IA-64. So XFmode should come out
545 to be kind=10, and RFmode should come out to be kind=11. Egads.
547 TODO: The kind calculation has to be modified to support all
548 three 128-bit floating-point modes on PowerPC as IFmode, KFmode,
549 and TFmode since the following line would all map to kind=16.
550 However, currently only float, double, long double, and TFmode
554 kind
= (GET_MODE_PRECISION (mode
) + 7) / 8;
568 /* Careful we don't stumble a weird internal mode. */
569 gcc_assert (r_index
<= 0 || gfc_real_kinds
[r_index
-1].kind
!= kind
);
570 /* Or have too many modes for the allocated space. */
571 gcc_assert (r_index
!= MAX_REAL_KINDS
);
573 gfc_real_kinds
[r_index
].kind
= kind
;
574 gfc_real_kinds
[r_index
].abi_kind
= kind
;
575 gfc_real_kinds
[r_index
].radix
= fmt
->b
;
576 gfc_real_kinds
[r_index
].digits
= fmt
->p
;
577 gfc_real_kinds
[r_index
].min_exponent
= fmt
->emin
;
578 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
;
579 if (fmt
->pnan
< fmt
->p
)
580 /* This is an IBM extended double format (or the MIPS variant)
581 made up of two IEEE doubles. The value of the long double is
582 the sum of the values of the two parts. The most significant
583 part is required to be the value of the long double rounded
584 to the nearest double. If we use emax of 1024 then we can't
585 represent huge(x) = (1 - b**(-p)) * b**(emax-1) * b, because
586 rounding will make the most significant part overflow. */
587 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
- 1;
588 gfc_real_kinds
[r_index
].mode_precision
= GET_MODE_PRECISION (mode
);
592 /* Detect the powerpc64le-linux case with -mabi=ieeelongdouble, where
593 the long double type is non-MODE_COMPOSITE_P TFmode but one can use
594 -mabi=ibmlongdouble too and get MODE_COMPOSITE_P TFmode with the same
595 precision. For libgfortran calls pretend the IEEE 754 quad TFmode has
596 kind 17 rather than 16 and use kind 16 for the IBM extended format
598 if (composite_mode
!= QImode
&& saw_r16
&& !MODE_COMPOSITE_P (r16_mode
))
600 for (int i
= 0; i
< r_index
; ++i
)
601 if (gfc_real_kinds
[i
].kind
== 16)
603 gfc_real_kinds
[i
].abi_kind
= 17;
604 if (flag_building_libgfortran
605 && (TARGET_GLIBC_MAJOR
< 2
606 || (TARGET_GLIBC_MAJOR
== 2 && TARGET_GLIBC_MINOR
< 32)))
608 if (TARGET_GLIBC_MAJOR
== 2 && TARGET_GLIBC_MINOR
>= 26)
610 gfc_real16_use_iec_60559
= true;
611 gfc_real_kinds
[i
].use_iec_60559
= 1;
613 gfc_real16_is_float128
= true;
614 gfc_real_kinds
[i
].c_float128
= 1;
618 else if ((flag_convert
& (GFC_CONVERT_R16_IEEE
| GFC_CONVERT_R16_IBM
)) != 0)
619 gfc_fatal_error ("%<-fconvert=r16_ieee%> or %<-fconvert=r16_ibm%> not "
620 "supported on this architecture");
622 /* Choose the default integer kind. We choose 4 unless the user directs us
623 otherwise. Even if the user specified that the default integer kind is 8,
624 the numeric storage size is not 64 bits. In this case, a warning will be
625 issued when NUMERIC_STORAGE_SIZE is used. Set NUMERIC_STORAGE_SIZE to 32. */
627 gfc_numeric_storage_size
= 4 * 8;
629 if (flag_default_integer
)
632 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
633 "%<-fdefault-integer-8%> option");
635 gfc_default_integer_kind
= 8;
638 else if (flag_integer4_kind
== 8)
641 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
642 "%<-finteger-4-integer-8%> option");
644 gfc_default_integer_kind
= 8;
648 gfc_default_integer_kind
= 4;
652 gfc_default_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
653 gfc_numeric_storage_size
= gfc_integer_kinds
[i_index
- 1].bit_size
;
656 gfc_default_unsigned_kind
= gfc_default_integer_kind
;
658 /* Choose the default real kind. Again, we choose 4 when possible. */
659 if (flag_default_real_8
)
662 gfc_fatal_error ("REAL(KIND=8) is not available for "
663 "%<-fdefault-real-8%> option");
665 gfc_default_real_kind
= 8;
667 else if (flag_default_real_10
)
670 gfc_fatal_error ("REAL(KIND=10) is not available for "
671 "%<-fdefault-real-10%> option");
673 gfc_default_real_kind
= 10;
675 else if (flag_default_real_16
)
678 gfc_fatal_error ("REAL(KIND=16) is not available for "
679 "%<-fdefault-real-16%> option");
681 gfc_default_real_kind
= 16;
683 else if (flag_real4_kind
== 8)
686 gfc_fatal_error ("REAL(KIND=8) is not available for %<-freal-4-real-8%> "
689 gfc_default_real_kind
= 8;
691 else if (flag_real4_kind
== 10)
694 gfc_fatal_error ("REAL(KIND=10) is not available for "
695 "%<-freal-4-real-10%> option");
697 gfc_default_real_kind
= 10;
699 else if (flag_real4_kind
== 16)
702 gfc_fatal_error ("REAL(KIND=16) is not available for "
703 "%<-freal-4-real-16%> option");
705 gfc_default_real_kind
= 16;
708 gfc_default_real_kind
= 4;
710 gfc_default_real_kind
= gfc_real_kinds
[0].kind
;
712 /* Choose the default double kind. If -fdefault-real and -fdefault-double
713 are specified, we use kind=8, if it's available. If -fdefault-real is
714 specified without -fdefault-double, we use kind=16, if it's available.
715 Otherwise we do not change anything. */
716 if (flag_default_double
&& saw_r8
)
717 gfc_default_double_kind
= 8;
718 else if (flag_default_real_8
|| flag_default_real_10
|| flag_default_real_16
)
720 /* Use largest available kind. */
722 gfc_default_double_kind
= 16;
724 gfc_default_double_kind
= 10;
726 gfc_default_double_kind
= 8;
728 gfc_default_double_kind
= gfc_default_real_kind
;
730 else if (flag_real8_kind
== 4)
733 gfc_fatal_error ("REAL(KIND=4) is not available for "
734 "%<-freal-8-real-4%> option");
736 gfc_default_double_kind
= 4;
738 else if (flag_real8_kind
== 10 )
741 gfc_fatal_error ("REAL(KIND=10) is not available for "
742 "%<-freal-8-real-10%> option");
744 gfc_default_double_kind
= 10;
746 else if (flag_real8_kind
== 16 )
749 gfc_fatal_error ("REAL(KIND=10) is not available for "
750 "%<-freal-8-real-16%> option");
752 gfc_default_double_kind
= 16;
754 else if (saw_r4
&& saw_r8
)
755 gfc_default_double_kind
= 8;
758 /* F95 14.6.3.1: A nonpointer scalar object of type double precision
759 real ... occupies two contiguous numeric storage units.
761 Therefore we must be supplied a kind twice as large as we chose
762 for single precision. There are loopholes, in that double
763 precision must *occupy* two storage units, though it doesn't have
764 to *use* two storage units. Which means that you can make this
765 kind artificially wide by padding it. But at present there are
766 no GCC targets for which a two-word type does not exist, so we
767 just let gfc_validate_kind abort and tell us if something breaks. */
769 gfc_default_double_kind
770 = gfc_validate_kind (BT_REAL
, gfc_default_real_kind
* 2, false);
773 /* The default logical kind is constrained to be the same as the
774 default integer kind. Similarly with complex and real. */
775 gfc_default_logical_kind
= gfc_default_integer_kind
;
776 gfc_default_complex_kind
= gfc_default_real_kind
;
778 /* We only have two character kinds: ASCII and UCS-4.
779 ASCII corresponds to a 8-bit integer type, if one is available.
780 UCS-4 corresponds to a 32-bit integer type, if one is available. */
782 if ((kind
= get_int_kind_from_width (8)) > 0)
784 gfc_character_kinds
[i_index
].kind
= kind
;
785 gfc_character_kinds
[i_index
].bit_size
= 8;
786 gfc_character_kinds
[i_index
].name
= "ascii";
789 if ((kind
= get_int_kind_from_width (32)) > 0)
791 gfc_character_kinds
[i_index
].kind
= kind
;
792 gfc_character_kinds
[i_index
].bit_size
= 32;
793 gfc_character_kinds
[i_index
].name
= "iso_10646";
797 /* Choose the smallest integer kind for our default character. */
798 gfc_default_character_kind
= gfc_character_kinds
[0].kind
;
799 gfc_character_storage_size
= gfc_default_character_kind
* 8;
801 gfc_index_integer_kind
= get_int_kind_from_name (PTRDIFF_TYPE
);
803 /* Pick a kind the same size as the C "int" type. */
804 gfc_c_int_kind
= INT_TYPE_SIZE
/ 8;
806 /* UNSIGNED has the same as INT. */
807 gfc_c_uint_kind
= gfc_c_int_kind
;
809 /* Choose atomic kinds to match C's int. */
810 gfc_atomic_int_kind
= gfc_c_int_kind
;
811 gfc_atomic_logical_kind
= gfc_c_int_kind
;
813 gfc_c_intptr_kind
= POINTER_SIZE
/ 8;
817 /* Make sure that a valid kind is present. Returns an index into the
818 associated kinds array, -1 if the kind is not present. */
821 validate_integer (int kind
)
825 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
826 if (gfc_integer_kinds
[i
].kind
== kind
)
833 validate_unsigned (int kind
)
837 for (i
= 0; gfc_unsigned_kinds
[i
].kind
!= 0; i
++)
838 if (gfc_unsigned_kinds
[i
].kind
== kind
)
845 validate_real (int kind
)
849 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
850 if (gfc_real_kinds
[i
].kind
== kind
)
857 validate_logical (int kind
)
861 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
862 if (gfc_logical_kinds
[i
].kind
== kind
)
869 validate_character (int kind
)
873 for (i
= 0; gfc_character_kinds
[i
].kind
; i
++)
874 if (gfc_character_kinds
[i
].kind
== kind
)
880 /* Validate a kind given a basic type. The return value is the same
881 for the child functions, with -1 indicating nonexistence of the
882 type. If MAY_FAIL is false, then -1 is never returned, and we ICE. */
885 gfc_validate_kind (bt type
, int kind
, bool may_fail
)
891 case BT_REAL
: /* Fall through */
893 rc
= validate_real (kind
);
896 rc
= validate_integer (kind
);
899 rc
= validate_unsigned (kind
);
902 rc
= validate_logical (kind
);
905 rc
= validate_character (kind
);
909 gfc_internal_error ("gfc_validate_kind(): Got bad type");
912 if (rc
< 0 && !may_fail
)
913 gfc_internal_error ("gfc_validate_kind(): Got bad kind");
919 /* Four subroutines of gfc_init_types. Create type nodes for the given kind.
920 Reuse common type nodes where possible. Recognize if the kind matches up
921 with a C type. This will be used later in determining which routines may
922 be scarfed from libm. */
925 gfc_build_int_type (gfc_integer_info
*info
)
927 int mode_precision
= info
->bit_size
;
929 if (mode_precision
== CHAR_TYPE_SIZE
)
931 if (mode_precision
== SHORT_TYPE_SIZE
)
933 if (mode_precision
== INT_TYPE_SIZE
)
935 if (mode_precision
== LONG_TYPE_SIZE
)
937 if (mode_precision
== LONG_LONG_TYPE_SIZE
)
938 info
->c_long_long
= 1;
940 if (TYPE_PRECISION (intQI_type_node
) == mode_precision
)
941 return intQI_type_node
;
942 if (TYPE_PRECISION (intHI_type_node
) == mode_precision
)
943 return intHI_type_node
;
944 if (TYPE_PRECISION (intSI_type_node
) == mode_precision
)
945 return intSI_type_node
;
946 if (TYPE_PRECISION (intDI_type_node
) == mode_precision
)
947 return intDI_type_node
;
948 if (TYPE_PRECISION (intTI_type_node
) == mode_precision
)
949 return intTI_type_node
;
951 return make_signed_type (mode_precision
);
955 gfc_build_uint_type (int size
)
957 if (size
== CHAR_TYPE_SIZE
)
958 return unsigned_char_type_node
;
959 if (size
== SHORT_TYPE_SIZE
)
960 return short_unsigned_type_node
;
961 if (size
== INT_TYPE_SIZE
)
962 return unsigned_type_node
;
963 if (size
== LONG_TYPE_SIZE
)
964 return long_unsigned_type_node
;
965 if (size
== LONG_LONG_TYPE_SIZE
)
966 return long_long_unsigned_type_node
;
968 return make_unsigned_type (size
);
972 gfc_build_unsigned_type (gfc_unsigned_info
*info
)
974 int mode_precision
= info
->bit_size
;
976 if (mode_precision
== CHAR_TYPE_SIZE
)
977 info
->c_unsigned_char
= 1;
978 if (mode_precision
== SHORT_TYPE_SIZE
)
979 info
->c_unsigned_short
= 1;
980 if (mode_precision
== INT_TYPE_SIZE
)
981 info
->c_unsigned_int
= 1;
982 if (mode_precision
== LONG_TYPE_SIZE
)
983 info
->c_unsigned_long
= 1;
984 if (mode_precision
== LONG_LONG_TYPE_SIZE
)
985 info
->c_unsigned_long_long
= 1;
987 return gfc_build_uint_type (mode_precision
);
991 gfc_build_real_type (gfc_real_info
*info
)
993 int mode_precision
= info
->mode_precision
;
996 if (mode_precision
== TYPE_PRECISION (float_type_node
))
998 if (mode_precision
== TYPE_PRECISION (double_type_node
))
1000 if (mode_precision
== TYPE_PRECISION (long_double_type_node
)
1001 && !info
->c_float128
)
1002 info
->c_long_double
= 1;
1003 if (mode_precision
!= TYPE_PRECISION (long_double_type_node
)
1004 && mode_precision
== 128)
1006 /* TODO: see PR101835. */
1007 info
->c_float128
= 1;
1008 gfc_real16_is_float128
= true;
1009 if (TARGET_GLIBC_MAJOR
> 2
1010 || (TARGET_GLIBC_MAJOR
== 2 && TARGET_GLIBC_MINOR
>= 26))
1012 info
->use_iec_60559
= 1;
1013 gfc_real16_use_iec_60559
= true;
1017 if (TYPE_PRECISION (float_type_node
) == mode_precision
)
1018 return float_type_node
;
1019 if (TYPE_PRECISION (double_type_node
) == mode_precision
)
1020 return double_type_node
;
1021 if (TYPE_PRECISION (long_double_type_node
) == mode_precision
)
1022 return long_double_type_node
;
1024 new_type
= make_node (REAL_TYPE
);
1025 TYPE_PRECISION (new_type
) = mode_precision
;
1026 layout_type (new_type
);
1031 gfc_build_complex_type (tree scalar_type
)
1035 if (scalar_type
== NULL
)
1037 if (scalar_type
== float_type_node
)
1038 return complex_float_type_node
;
1039 if (scalar_type
== double_type_node
)
1040 return complex_double_type_node
;
1041 if (scalar_type
== long_double_type_node
)
1042 return complex_long_double_type_node
;
1044 new_type
= make_node (COMPLEX_TYPE
);
1045 TREE_TYPE (new_type
) = scalar_type
;
1046 layout_type (new_type
);
1051 gfc_build_logical_type (gfc_logical_info
*info
)
1053 int bit_size
= info
->bit_size
;
1056 if (bit_size
== BOOL_TYPE_SIZE
)
1059 return boolean_type_node
;
1062 new_type
= make_unsigned_type (bit_size
);
1063 TREE_SET_CODE (new_type
, BOOLEAN_TYPE
);
1064 TYPE_MAX_VALUE (new_type
) = build_int_cst (new_type
, 1);
1065 TYPE_PRECISION (new_type
) = 1;
1071 /* Create the backend type nodes. We map them to their
1072 equivalent C type, at least for now. We also give
1073 names to the types here, and we push them in the
1074 global binding level context.*/
1077 gfc_init_types (void)
1084 /* Create and name the types. */
1085 #define PUSH_TYPE(name, node) \
1086 pushdecl (build_decl (input_location, \
1087 TYPE_DECL, get_identifier (name), node))
1089 for (index
= 0; gfc_integer_kinds
[index
].kind
!= 0; ++index
)
1091 type
= gfc_build_int_type (&gfc_integer_kinds
[index
]);
1092 /* Ensure integer(kind=1) doesn't have TYPE_STRING_FLAG set. */
1093 if (TYPE_STRING_FLAG (type
))
1094 type
= make_signed_type (gfc_integer_kinds
[index
].bit_size
);
1095 gfc_integer_types
[index
] = type
;
1096 snprintf (name_buf
, sizeof(name_buf
), "integer(kind=%d)",
1097 gfc_integer_kinds
[index
].kind
);
1098 PUSH_TYPE (name_buf
, type
);
1101 for (index
= 0; gfc_logical_kinds
[index
].kind
!= 0; ++index
)
1103 type
= gfc_build_logical_type (&gfc_logical_kinds
[index
]);
1104 gfc_logical_types
[index
] = type
;
1105 snprintf (name_buf
, sizeof(name_buf
), "logical(kind=%d)",
1106 gfc_logical_kinds
[index
].kind
);
1107 PUSH_TYPE (name_buf
, type
);
1110 for (index
= 0; gfc_real_kinds
[index
].kind
!= 0; index
++)
1112 type
= gfc_build_real_type (&gfc_real_kinds
[index
]);
1113 gfc_real_types
[index
] = type
;
1114 snprintf (name_buf
, sizeof(name_buf
), "real(kind=%d)",
1115 gfc_real_kinds
[index
].kind
);
1116 PUSH_TYPE (name_buf
, type
);
1118 if (gfc_real_kinds
[index
].c_float128
)
1119 gfc_float128_type_node
= type
;
1121 type
= gfc_build_complex_type (type
);
1122 gfc_complex_types
[index
] = type
;
1123 snprintf (name_buf
, sizeof(name_buf
), "complex(kind=%d)",
1124 gfc_real_kinds
[index
].kind
);
1125 PUSH_TYPE (name_buf
, type
);
1127 if (gfc_real_kinds
[index
].c_float128
)
1128 gfc_complex_float128_type_node
= type
;
1131 for (index
= 0; gfc_character_kinds
[index
].kind
!= 0; ++index
)
1133 type
= gfc_build_uint_type (gfc_character_kinds
[index
].bit_size
);
1134 type
= build_qualified_type (type
, TYPE_UNQUALIFIED
);
1135 snprintf (name_buf
, sizeof(name_buf
), "character(kind=%d)",
1136 gfc_character_kinds
[index
].kind
);
1137 PUSH_TYPE (name_buf
, type
);
1138 gfc_character_types
[index
] = type
;
1139 gfc_pcharacter_types
[index
] = build_pointer_type (type
);
1141 gfc_character1_type_node
= gfc_character_types
[0];
1145 for (index
= 0; gfc_unsigned_kinds
[index
].kind
!= 0;++index
)
1147 int index_char
= -1;
1148 for (int i
=0; gfc_character_kinds
[i
].kind
!= 0; i
++)
1150 if (gfc_character_kinds
[i
].bit_size
1151 == gfc_unsigned_kinds
[index
].bit_size
)
1157 if (index_char
> -1)
1159 type
= gfc_character_types
[index_char
];
1160 if (TYPE_STRING_FLAG (type
))
1162 type
= build_distinct_type_copy (type
);
1163 TYPE_CANONICAL (type
)
1164 = TYPE_CANONICAL (gfc_character_types
[index_char
]);
1167 type
= build_variant_type_copy (type
);
1168 TYPE_NAME (type
) = NULL_TREE
;
1169 TYPE_STRING_FLAG (type
) = 0;
1172 type
= gfc_build_unsigned_type (&gfc_unsigned_kinds
[index
]);
1173 gfc_unsigned_types
[index
] = type
;
1174 snprintf (name_buf
, sizeof(name_buf
), "unsigned(kind=%d)",
1175 gfc_integer_kinds
[index
].kind
);
1176 PUSH_TYPE (name_buf
, type
);
1180 PUSH_TYPE ("byte", unsigned_char_type_node
);
1181 PUSH_TYPE ("void", void_type_node
);
1183 /* DBX debugging output gets upset if these aren't set. */
1184 if (!TYPE_NAME (integer_type_node
))
1185 PUSH_TYPE ("c_integer", integer_type_node
);
1186 if (!TYPE_NAME (char_type_node
))
1187 PUSH_TYPE ("c_char", char_type_node
);
1191 pvoid_type_node
= build_pointer_type (void_type_node
);
1192 prvoid_type_node
= build_qualified_type (pvoid_type_node
, TYPE_QUAL_RESTRICT
);
1193 ppvoid_type_node
= build_pointer_type (pvoid_type_node
);
1194 pchar_type_node
= build_pointer_type (gfc_character1_type_node
);
1196 = build_pointer_type (build_function_type_list (void_type_node
, NULL_TREE
));
1198 gfc_array_index_type
= gfc_get_int_type (gfc_index_integer_kind
);
1199 /* We cannot use gfc_index_zero_node in definition of gfc_array_range_type,
1200 since this function is called before gfc_init_constants. */
1201 gfc_array_range_type
1202 = build_range_type (gfc_array_index_type
,
1203 build_int_cst (gfc_array_index_type
, 0),
1206 /* The maximum array element size that can be handled is determined
1207 by the number of bits available to store this field in the array
1210 n
= TYPE_PRECISION (size_type_node
);
1211 gfc_max_array_element_size
1212 = wide_int_to_tree (size_type_node
,
1213 wi::mask (n
, UNSIGNED
,
1214 TYPE_PRECISION (size_type_node
)));
1216 logical_type_node
= gfc_get_logical_type (gfc_default_logical_kind
);
1217 logical_true_node
= build_int_cst (logical_type_node
, 1);
1218 logical_false_node
= build_int_cst (logical_type_node
, 0);
1220 /* Character lengths are of type size_t, except signed. */
1221 gfc_charlen_int_kind
= get_int_kind_from_node (size_type_node
);
1222 gfc_charlen_type_node
= gfc_get_int_type (gfc_charlen_int_kind
);
1224 /* Fortran kind number of size_type_node (size_t). This is used for
1225 the _size member in vtables. */
1226 gfc_size_kind
= get_int_kind_from_node (size_type_node
);
1229 /* Get the type node for the given type and kind. */
1232 gfc_get_int_type (int kind
)
1234 int index
= gfc_validate_kind (BT_INTEGER
, kind
, true);
1235 return index
< 0 ? 0 : gfc_integer_types
[index
];
1239 gfc_get_unsigned_type (int kind
)
1241 int index
= gfc_validate_kind (BT_UNSIGNED
, kind
, true);
1242 return index
< 0 ? 0 : gfc_unsigned_types
[index
];
1246 gfc_get_real_type (int kind
)
1248 int index
= gfc_validate_kind (BT_REAL
, kind
, true);
1249 return index
< 0 ? 0 : gfc_real_types
[index
];
1253 gfc_get_complex_type (int kind
)
1255 int index
= gfc_validate_kind (BT_COMPLEX
, kind
, true);
1256 return index
< 0 ? 0 : gfc_complex_types
[index
];
1260 gfc_get_logical_type (int kind
)
1262 int index
= gfc_validate_kind (BT_LOGICAL
, kind
, true);
1263 return index
< 0 ? 0 : gfc_logical_types
[index
];
1267 gfc_get_char_type (int kind
)
1269 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1270 return index
< 0 ? 0 : gfc_character_types
[index
];
1274 gfc_get_pchar_type (int kind
)
1276 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1277 return index
< 0 ? 0 : gfc_pcharacter_types
[index
];
1281 /* Create a character type with the given kind and length. */
1284 gfc_get_character_type_len_for_eltype (tree eltype
, tree len
)
1288 bounds
= build_range_type (gfc_charlen_type_node
, gfc_index_one_node
, len
);
1289 type
= build_array_type (eltype
, bounds
);
1290 TYPE_STRING_FLAG (type
) = 1;
1296 gfc_get_character_type_len (int kind
, tree len
)
1298 gfc_validate_kind (BT_CHARACTER
, kind
, false);
1299 return gfc_get_character_type_len_for_eltype (gfc_get_char_type (kind
), len
);
1303 /* Get a type node for a character kind. */
1306 gfc_get_character_type (int kind
, gfc_charlen
* cl
)
1310 len
= (cl
== NULL
) ? NULL_TREE
: cl
->backend_decl
;
1311 if (len
&& POINTER_TYPE_P (TREE_TYPE (len
)))
1312 len
= build_fold_indirect_ref (len
);
1314 return gfc_get_character_type_len (kind
, len
);
1317 /* Convert a basic type. This will be an array for character types. */
1320 gfc_typenode_for_spec (gfc_typespec
* spec
, int codim
)
1330 /* We use INTEGER(c_intptr_t) for C_PTR and C_FUNPTR once the symbol
1331 has been resolved. This is done so we can convert C_PTR and
1332 C_FUNPTR to simple variables that get translated to (void *). */
1333 if (spec
->f90_type
== BT_VOID
)
1336 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1337 basetype
= ptr_type_node
;
1339 basetype
= pfunc_type_node
;
1342 basetype
= gfc_get_int_type (spec
->kind
);
1346 basetype
= gfc_get_unsigned_type (spec
->kind
);
1350 basetype
= gfc_get_real_type (spec
->kind
);
1354 basetype
= gfc_get_complex_type (spec
->kind
);
1358 basetype
= gfc_get_logical_type (spec
->kind
);
1362 basetype
= gfc_get_character_type (spec
->kind
, spec
->u
.cl
);
1366 /* Since this cannot be used, return a length one character. */
1367 basetype
= gfc_get_character_type_len (gfc_default_character_kind
,
1368 gfc_index_one_node
);
1372 basetype
= gfc_get_union_type (spec
->u
.derived
);
1377 basetype
= gfc_get_derived_type (spec
->u
.derived
, codim
);
1379 if (spec
->type
== BT_CLASS
)
1380 GFC_CLASS_TYPE_P (basetype
) = 1;
1382 /* If we're dealing with either C_PTR or C_FUNPTR, we modified the
1383 type and kind to fit a (void *) and the basetype returned was a
1384 ptr_type_node. We need to pass up this new information to the
1385 symbol that was declared of type C_PTR or C_FUNPTR. */
1386 if (spec
->u
.derived
->ts
.f90_type
== BT_VOID
)
1388 spec
->type
= BT_INTEGER
;
1389 spec
->kind
= gfc_index_integer_kind
;
1390 spec
->f90_type
= BT_VOID
;
1391 spec
->is_c_interop
= 1; /* Mark as escaping later. */
1396 /* This is for the second arg to c_f_pointer and c_f_procpointer
1397 of the iso_c_binding module, to accept any ptr type. */
1398 basetype
= ptr_type_node
;
1399 if (spec
->f90_type
== BT_VOID
)
1402 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1403 basetype
= ptr_type_node
;
1405 basetype
= pfunc_type_node
;
1409 basetype
= pfunc_type_node
;
1417 /* Build an INT_CST for constant expressions, otherwise return NULL_TREE. */
1420 gfc_conv_array_bound (gfc_expr
* expr
)
1422 /* If expr is an integer constant, return that. */
1423 if (expr
!= NULL
&& expr
->expr_type
== EXPR_CONSTANT
)
1424 return gfc_conv_mpz_to_tree (expr
->value
.integer
, gfc_index_integer_kind
);
1426 /* Otherwise return NULL. */
1430 /* Return the type of an element of the array. Note that scalar coarrays
1431 are special. In particular, for GFC_ARRAY_TYPE_P, the original argument
1432 (with POINTER_TYPE stripped) is returned. */
1435 gfc_get_element_type (tree type
)
1439 if (GFC_ARRAY_TYPE_P (type
))
1441 if (TREE_CODE (type
) == POINTER_TYPE
)
1442 type
= TREE_TYPE (type
);
1443 if (GFC_TYPE_ARRAY_RANK (type
) == 0)
1445 gcc_assert (GFC_TYPE_ARRAY_CORANK (type
) > 0);
1450 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
1451 element
= TREE_TYPE (type
);
1456 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
));
1457 element
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
1459 gcc_assert (TREE_CODE (element
) == POINTER_TYPE
);
1460 element
= TREE_TYPE (element
);
1462 /* For arrays, which are not scalar coarrays. */
1463 if (TREE_CODE (element
) == ARRAY_TYPE
&& !TYPE_STRING_FLAG (element
))
1464 element
= TREE_TYPE (element
);
1470 /* Build an array. This function is called from gfc_sym_type().
1471 Actually returns array descriptor type.
1473 Format of array descriptors is as follows:
1475 struct gfc_array_descriptor
1479 struct dtype_type dtype;
1480 struct descriptor_dimension dimension[N_DIM];
1489 signed short attribute;
1492 struct descriptor_dimension
1499 Translation code should use gfc_conv_descriptor_* rather than
1500 accessing the descriptor directly. Any changes to the array
1501 descriptor type will require changes in gfc_conv_descriptor_* and
1502 gfc_build_array_initializer.
1504 This is represented internally as a RECORD_TYPE. The index nodes
1505 are gfc_array_index_type and the data node is a pointer to the
1506 data. See below for the handling of character types.
1508 I originally used nested ARRAY_TYPE nodes to represent arrays, but
1509 this generated poor code for assumed/deferred size arrays. These
1510 require use of PLACEHOLDER_EXPR/WITH_RECORD_EXPR, which isn't part
1511 of the GENERIC grammar. Also, there is no way to explicitly set
1512 the array stride, so all data must be packed(1). I've tried to
1513 mark all the functions which would require modification with a GCC
1516 The data component points to the first element in the array. The
1517 offset field is the position of the origin of the array (i.e. element
1518 (0, 0 ...)). This may be outside the bounds of the array.
1520 An element is accessed by
1521 data[offset + index0*stride0 + index1*stride1 + index2*stride2]
1522 This gives good performance as the computation does not involve the
1523 bounds of the array. For packed arrays, this is optimized further
1524 by substituting the known strides.
1526 This system has one problem: all array bounds must be within 2^31
1527 elements of the origin (2^63 on 64-bit machines). For example
1528 integer, dimension (80000:90000, 80000:90000, 2) :: array
1529 may not work properly on 32-bit machines because 80000*80000 >
1530 2^31, so the calculation for stride2 would overflow. This may
1531 still work, but I haven't checked, and it relies on the overflow
1532 doing the right thing.
1534 The way to fix this problem is to access elements as follows:
1535 data[(index0-lbound0)*stride0 + (index1-lbound1)*stride1]
1536 Obviously this is much slower. I will make this a compile time
1537 option, something like -fsmall-array-offsets. Mixing code compiled
1538 with and without this switch will work.
1540 (1) This can be worked around by modifying the upper bound of the
1541 previous dimension. This requires extra fields in the descriptor
1542 (both real_ubound and fake_ubound). */
1545 /* Returns true if the array sym does not require a descriptor. */
1548 gfc_is_nodesc_array (gfc_symbol
* sym
)
1550 symbol_attribute
*array_attr
;
1552 bool is_classarray
= IS_CLASS_COARRAY_OR_ARRAY (sym
);
1554 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
1555 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
1557 gcc_assert (array_attr
->dimension
|| array_attr
->codimension
);
1559 /* We only want local arrays. */
1560 if ((sym
->ts
.type
!= BT_CLASS
&& sym
->attr
.pointer
)
1561 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->attr
.class_pointer
)
1562 || array_attr
->allocatable
)
1565 /* We want a descriptor for associate-name arrays that do not have an
1566 explicitly known shape already. */
1567 if (sym
->assoc
&& as
->type
!= AS_EXPLICIT
)
1570 /* The dummy is stored in sym and not in the component. */
1571 if (sym
->attr
.dummy
)
1572 return as
->type
!= AS_ASSUMED_SHAPE
1573 && as
->type
!= AS_ASSUMED_RANK
;
1575 if (sym
->attr
.result
|| sym
->attr
.function
)
1578 gcc_assert (as
->type
== AS_EXPLICIT
|| as
->cp_was_assumed
);
1584 /* Create an array descriptor type. */
1587 gfc_build_array_type (tree type
, gfc_array_spec
* as
,
1588 enum gfc_array_kind akind
, bool restricted
,
1589 bool contiguous
, int codim
)
1591 tree lbound
[GFC_MAX_DIMENSIONS
];
1592 tree ubound
[GFC_MAX_DIMENSIONS
];
1595 /* Assumed-shape arrays do not have codimension information stored in the
1597 corank
= MAX (as
->corank
, codim
);
1598 if (as
->type
== AS_ASSUMED_SHAPE
||
1599 (as
->type
== AS_ASSUMED_RANK
&& akind
== GFC_ARRAY_ALLOCATABLE
))
1602 if (as
->type
== AS_ASSUMED_RANK
)
1603 for (n
= 0; n
< GFC_MAX_DIMENSIONS
; n
++)
1605 lbound
[n
] = NULL_TREE
;
1606 ubound
[n
] = NULL_TREE
;
1609 for (n
= 0; n
< as
->rank
; n
++)
1611 /* Create expressions for the known bounds of the array. */
1612 if (as
->type
== AS_ASSUMED_SHAPE
&& as
->lower
[n
] == NULL
)
1613 lbound
[n
] = gfc_index_one_node
;
1615 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1616 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1619 for (n
= as
->rank
; n
< as
->rank
+ corank
; n
++)
1621 if (as
->type
!= AS_DEFERRED
&& as
->lower
[n
] == NULL
)
1622 lbound
[n
] = gfc_index_one_node
;
1624 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1626 if (n
< as
->rank
+ corank
- 1)
1627 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1630 if (as
->type
== AS_ASSUMED_SHAPE
)
1631 akind
= contiguous
? GFC_ARRAY_ASSUMED_SHAPE_CONT
1632 : GFC_ARRAY_ASSUMED_SHAPE
;
1633 else if (as
->type
== AS_ASSUMED_RANK
)
1635 if (akind
== GFC_ARRAY_ALLOCATABLE
)
1636 akind
= GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
;
1637 else if (akind
== GFC_ARRAY_POINTER
|| akind
== GFC_ARRAY_POINTER_CONT
)
1638 akind
= contiguous
? GFC_ARRAY_ASSUMED_RANK_POINTER_CONT
1639 : GFC_ARRAY_ASSUMED_RANK_POINTER
;
1641 akind
= contiguous
? GFC_ARRAY_ASSUMED_RANK_CONT
1642 : GFC_ARRAY_ASSUMED_RANK
;
1644 return gfc_get_array_type_bounds (type
, as
->rank
== -1
1645 ? GFC_MAX_DIMENSIONS
: as
->rank
,
1646 corank
, lbound
, ubound
, 0, akind
,
1650 /* Returns the struct descriptor_dimension type. */
1653 gfc_get_desc_dim_type (void)
1656 tree decl
, *chain
= NULL
;
1658 if (gfc_desc_dim_type
)
1659 return gfc_desc_dim_type
;
1661 /* Build the type node. */
1662 type
= make_node (RECORD_TYPE
);
1664 TYPE_NAME (type
) = get_identifier ("descriptor_dimension");
1665 TYPE_PACKED (type
) = 1;
1667 /* Consists of the stride, lbound and ubound members. */
1668 decl
= gfc_add_field_to_struct_1 (type
,
1669 get_identifier ("stride"),
1670 gfc_array_index_type
, &chain
);
1671 suppress_warning (decl
);
1673 decl
= gfc_add_field_to_struct_1 (type
,
1674 get_identifier ("lbound"),
1675 gfc_array_index_type
, &chain
);
1676 suppress_warning (decl
);
1678 decl
= gfc_add_field_to_struct_1 (type
,
1679 get_identifier ("ubound"),
1680 gfc_array_index_type
, &chain
);
1681 suppress_warning (decl
);
1683 /* Finish off the type. */
1684 gfc_finish_type (type
);
1685 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
1687 gfc_desc_dim_type
= type
;
1692 /* Return the DTYPE for an array. This describes the type and type parameters
1694 /* TODO: Only call this when the value is actually used, and make all the
1695 unknown cases abort. */
1698 gfc_get_dtype_rank_type (int rank
, tree etype
)
1706 vec
<constructor_elt
, va_gc
> *v
= NULL
;
1709 while (TREE_CODE (etype
) == POINTER_TYPE
1710 || TREE_CODE (etype
) == ARRAY_TYPE
)
1713 etype
= TREE_TYPE (etype
);
1718 switch (TREE_CODE (etype
))
1721 if (TREE_CODE (ptype
) == ARRAY_TYPE
1722 && TYPE_STRING_FLAG (ptype
))
1726 if (TYPE_UNSIGNED (etype
))
1746 if (GFC_CLASS_TYPE_P (etype
))
1758 /* TODO: Don't do dtype for temporary descriptorless arrays. */
1759 /* We can encounter strange array types for temporary arrays. */
1766 gcc_assert (TREE_CODE (ptype
) == ARRAY_TYPE
);
1767 size
= gfc_get_character_len_in_bytes (ptype
);
1770 gcc_assert (TREE_CODE (ptype
) == POINTER_TYPE
);
1771 size
= size_in_bytes (ptype
);
1774 size
= size_in_bytes (etype
);
1781 size
= fold_convert (size_type_node
, size
);
1782 tmp
= get_dtype_type_node ();
1783 field
= gfc_advance_chain (TYPE_FIELDS (tmp
),
1784 GFC_DTYPE_ELEM_LEN
);
1785 CONSTRUCTOR_APPEND_ELT (v
, field
,
1786 fold_convert (TREE_TYPE (field
), size
));
1787 field
= gfc_advance_chain (TYPE_FIELDS (dtype_type_node
),
1789 CONSTRUCTOR_APPEND_ELT (v
, field
,
1790 build_zero_cst (TREE_TYPE (field
)));
1792 field
= gfc_advance_chain (TYPE_FIELDS (dtype_type_node
),
1795 CONSTRUCTOR_APPEND_ELT (v
, field
,
1796 build_int_cst (TREE_TYPE (field
), rank
));
1798 field
= gfc_advance_chain (TYPE_FIELDS (dtype_type_node
),
1800 CONSTRUCTOR_APPEND_ELT (v
, field
,
1801 build_int_cst (TREE_TYPE (field
), n
));
1803 dtype
= build_constructor (tmp
, v
);
1810 gfc_get_dtype (tree type
, int * rank
)
1816 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
) || GFC_ARRAY_TYPE_P (type
));
1818 irnk
= (rank
) ? (*rank
) : (GFC_TYPE_ARRAY_RANK (type
));
1819 etype
= gfc_get_element_type (type
);
1820 dtype
= gfc_get_dtype_rank_type (irnk
, etype
);
1822 GFC_TYPE_ARRAY_DTYPE (type
) = dtype
;
1827 /* Build an array type for use without a descriptor, packed according
1828 to the value of PACKED. */
1831 gfc_get_nodesc_array_type (tree etype
, gfc_array_spec
* as
, gfc_packed packed
,
1845 mpz_init_set_ui (offset
, 0);
1846 mpz_init_set_ui (stride
, 1);
1849 /* We don't use build_array_type because this does not include
1850 lang-specific information (i.e. the bounds of the array) when checking
1853 type
= make_node (ARRAY_TYPE
);
1855 type
= build_variant_type_copy (etype
);
1857 GFC_ARRAY_TYPE_P (type
) = 1;
1858 TYPE_LANG_SPECIFIC (type
) = ggc_cleared_alloc
<struct lang_type
> ();
1860 known_stride
= (packed
!= PACKED_NO
);
1862 for (n
= 0; n
< as
->rank
; n
++)
1864 /* Fill in the stride and bound components of the type. */
1866 tmp
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1869 GFC_TYPE_ARRAY_STRIDE (type
, n
) = tmp
;
1871 expr
= as
->lower
[n
];
1872 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1874 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1875 gfc_index_integer_kind
);
1882 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1886 /* Calculate the offset. */
1887 mpz_mul (delta
, stride
, as
->lower
[n
]->value
.integer
);
1888 mpz_sub (offset
, offset
, delta
);
1893 expr
= as
->upper
[n
];
1894 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1896 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1897 gfc_index_integer_kind
);
1904 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1908 /* Calculate the stride. */
1909 mpz_sub (delta
, as
->upper
[n
]->value
.integer
,
1910 as
->lower
[n
]->value
.integer
);
1911 mpz_add_ui (delta
, delta
, 1);
1912 mpz_mul (stride
, stride
, delta
);
1915 /* Only the first stride is known for partial packed arrays. */
1916 if (packed
== PACKED_NO
|| packed
== PACKED_PARTIAL
)
1919 for (n
= as
->rank
; n
< as
->rank
+ as
->corank
; n
++)
1921 expr
= as
->lower
[n
];
1922 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1923 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1924 gfc_index_integer_kind
);
1927 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1929 expr
= as
->upper
[n
];
1930 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1931 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1932 gfc_index_integer_kind
);
1935 if (n
< as
->rank
+ as
->corank
- 1)
1936 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1941 GFC_TYPE_ARRAY_OFFSET (type
) =
1942 gfc_conv_mpz_to_tree (offset
, gfc_index_integer_kind
);
1945 GFC_TYPE_ARRAY_OFFSET (type
) = NULL_TREE
;
1949 GFC_TYPE_ARRAY_SIZE (type
) =
1950 gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1953 GFC_TYPE_ARRAY_SIZE (type
) = NULL_TREE
;
1955 GFC_TYPE_ARRAY_RANK (type
) = as
->rank
;
1956 GFC_TYPE_ARRAY_CORANK (type
) = as
->corank
;
1957 GFC_TYPE_ARRAY_DTYPE (type
) = NULL_TREE
;
1958 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
1960 /* TODO: use main type if it is unbounded. */
1961 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1962 build_pointer_type (build_array_type (etype
, range
));
1964 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1965 build_qualified_type (GFC_TYPE_ARRAY_DATAPTR_TYPE (type
),
1966 TYPE_QUAL_RESTRICT
);
1970 if (packed
!= PACKED_STATIC
|| flag_coarray
== GFC_FCOARRAY_LIB
)
1972 type
= build_pointer_type (type
);
1975 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
1977 GFC_ARRAY_TYPE_P (type
) = 1;
1978 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
1981 goto array_type_done
;
1986 mpz_sub_ui (stride
, stride
, 1);
1987 range
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1992 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
, range
);
1993 TYPE_DOMAIN (type
) = range
;
1995 build_pointer_type (etype
);
1996 TREE_TYPE (type
) = etype
;
2000 /* Represent packed arrays as multi-dimensional if they have rank >
2001 1 and with proper bounds, instead of flat arrays. This makes for
2002 better debug info. */
2005 tree gtype
= etype
, rtype
, type_decl
;
2007 for (n
= as
->rank
- 1; n
>= 0; n
--)
2009 rtype
= build_range_type (gfc_array_index_type
,
2010 GFC_TYPE_ARRAY_LBOUND (type
, n
),
2011 GFC_TYPE_ARRAY_UBOUND (type
, n
));
2012 gtype
= build_array_type (gtype
, rtype
);
2014 TYPE_NAME (type
) = type_decl
= build_decl (input_location
,
2015 TYPE_DECL
, NULL
, gtype
);
2016 DECL_ORIGINAL_TYPE (type_decl
) = gtype
;
2019 if (packed
!= PACKED_STATIC
|| !known_stride
2020 || (as
->corank
&& flag_coarray
== GFC_FCOARRAY_LIB
))
2022 /* For dummy arrays and automatic (heap allocated) arrays we
2023 want a pointer to the array. */
2024 type
= build_pointer_type (type
);
2026 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
2027 GFC_ARRAY_TYPE_P (type
) = 1;
2028 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
2040 /* Return or create the base type for an array descriptor. */
2043 gfc_get_array_descriptor_base (int dimen
, int codimen
, bool restricted
)
2045 tree fat_type
, decl
, arraytype
, *chain
= NULL
;
2046 char name
[16 + 2*GFC_RANK_DIGITS
+ 1 + 1];
2049 /* Assumed-rank array. */
2051 dimen
= GFC_MAX_DIMENSIONS
;
2053 idx
= 2 * (codimen
+ dimen
) + restricted
;
2055 gcc_assert (codimen
+ dimen
>= 0 && codimen
+ dimen
<= GFC_MAX_DIMENSIONS
);
2057 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
2059 if (gfc_array_descriptor_base_caf
[idx
])
2060 return gfc_array_descriptor_base_caf
[idx
];
2062 else if (gfc_array_descriptor_base
[idx
])
2063 return gfc_array_descriptor_base
[idx
];
2065 /* Build the type node. */
2066 fat_type
= make_node (RECORD_TYPE
);
2068 sprintf (name
, "array_descriptor" GFC_RANK_PRINTF_FORMAT
, dimen
+ codimen
);
2069 TYPE_NAME (fat_type
) = get_identifier (name
);
2070 TYPE_NAMELESS (fat_type
) = 1;
2072 /* Add the data member as the first element of the descriptor. */
2073 gfc_add_field_to_struct_1 (fat_type
,
2074 get_identifier ("data"),
2077 : ptr_type_node
), &chain
);
2079 /* Add the base component. */
2080 decl
= gfc_add_field_to_struct_1 (fat_type
,
2081 get_identifier ("offset"),
2082 gfc_array_index_type
, &chain
);
2083 suppress_warning (decl
);
2085 /* Add the dtype component. */
2086 decl
= gfc_add_field_to_struct_1 (fat_type
,
2087 get_identifier ("dtype"),
2088 get_dtype_type_node (), &chain
);
2089 suppress_warning (decl
);
2091 /* Add the span component. */
2092 decl
= gfc_add_field_to_struct_1 (fat_type
,
2093 get_identifier ("span"),
2094 gfc_array_index_type
, &chain
);
2095 suppress_warning (decl
);
2097 /* Build the array type for the stride and bound components. */
2098 if (dimen
+ codimen
> 0)
2101 build_array_type (gfc_get_desc_dim_type (),
2102 build_range_type (gfc_array_index_type
,
2103 gfc_index_zero_node
,
2104 gfc_rank_cst
[codimen
+ dimen
- 1]));
2106 decl
= gfc_add_field_to_struct_1 (fat_type
, get_identifier ("dim"),
2108 suppress_warning (decl
);
2111 if (flag_coarray
== GFC_FCOARRAY_LIB
)
2113 decl
= gfc_add_field_to_struct_1 (fat_type
,
2114 get_identifier ("token"),
2115 prvoid_type_node
, &chain
);
2116 suppress_warning (decl
);
2119 /* Finish off the type. */
2120 gfc_finish_type (fat_type
);
2121 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (fat_type
)) = 1;
2123 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
2124 gfc_array_descriptor_base_caf
[idx
] = fat_type
;
2126 gfc_array_descriptor_base
[idx
] = fat_type
;
2132 /* Build an array (descriptor) type with given bounds. */
2135 gfc_get_array_type_bounds (tree etype
, int dimen
, int codimen
, tree
* lbound
,
2136 tree
* ubound
, int packed
,
2137 enum gfc_array_kind akind
, bool restricted
)
2139 char name
[8 + 2*GFC_RANK_DIGITS
+ 1 + GFC_MAX_SYMBOL_LEN
];
2140 tree fat_type
, base_type
, arraytype
, lower
, upper
, stride
, tmp
, rtype
;
2141 const char *type_name
;
2144 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, restricted
);
2145 fat_type
= build_distinct_type_copy (base_type
);
2146 /* Unshare TYPE_FIELDs. */
2147 for (tree
*tp
= &TYPE_FIELDS (fat_type
); *tp
; tp
= &DECL_CHAIN (*tp
))
2149 tree next
= DECL_CHAIN (*tp
);
2150 *tp
= copy_node (*tp
);
2151 DECL_CONTEXT (*tp
) = fat_type
;
2152 DECL_CHAIN (*tp
) = next
;
2154 /* Make sure that nontarget and target array type have the same canonical
2155 type (and same stub decl for debug info). */
2156 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, false);
2157 TYPE_CANONICAL (fat_type
) = base_type
;
2158 TYPE_STUB_DECL (fat_type
) = TYPE_STUB_DECL (base_type
);
2159 /* Arrays of unknown type must alias with all array descriptors. */
2160 TYPE_TYPELESS_STORAGE (base_type
) = 1;
2161 TYPE_TYPELESS_STORAGE (fat_type
) = 1;
2162 gcc_checking_assert (!get_alias_set (base_type
) && !get_alias_set (fat_type
));
2165 if (TREE_CODE (tmp
) == ARRAY_TYPE
2166 && TYPE_STRING_FLAG (tmp
))
2167 tmp
= TREE_TYPE (etype
);
2168 tmp
= TYPE_NAME (tmp
);
2169 if (tmp
&& TREE_CODE (tmp
) == TYPE_DECL
)
2170 tmp
= DECL_NAME (tmp
);
2172 type_name
= IDENTIFIER_POINTER (tmp
);
2174 type_name
= "unknown";
2175 sprintf (name
, "array" GFC_RANK_PRINTF_FORMAT
"_%.*s", dimen
+ codimen
,
2176 GFC_MAX_SYMBOL_LEN
, type_name
);
2177 TYPE_NAME (fat_type
) = get_identifier (name
);
2178 TYPE_NAMELESS (fat_type
) = 1;
2180 GFC_DESCRIPTOR_TYPE_P (fat_type
) = 1;
2181 TYPE_LANG_SPECIFIC (fat_type
) = ggc_cleared_alloc
<struct lang_type
> ();
2183 GFC_TYPE_ARRAY_RANK (fat_type
) = dimen
;
2184 GFC_TYPE_ARRAY_CORANK (fat_type
) = codimen
;
2185 GFC_TYPE_ARRAY_DTYPE (fat_type
) = NULL_TREE
;
2186 GFC_TYPE_ARRAY_AKIND (fat_type
) = akind
;
2188 /* Build an array descriptor record type. */
2190 stride
= gfc_index_one_node
;
2193 for (n
= 0; n
< dimen
+ codimen
; n
++)
2196 GFC_TYPE_ARRAY_STRIDE (fat_type
, n
) = stride
;
2203 if (lower
!= NULL_TREE
)
2205 if (INTEGER_CST_P (lower
))
2206 GFC_TYPE_ARRAY_LBOUND (fat_type
, n
) = lower
;
2211 if (codimen
&& n
== dimen
+ codimen
- 1)
2215 if (upper
!= NULL_TREE
)
2217 if (INTEGER_CST_P (upper
))
2218 GFC_TYPE_ARRAY_UBOUND (fat_type
, n
) = upper
;
2226 if (upper
!= NULL_TREE
&& lower
!= NULL_TREE
&& stride
!= NULL_TREE
)
2228 tmp
= fold_build2_loc (input_location
, MINUS_EXPR
,
2229 gfc_array_index_type
, upper
, lower
);
2230 tmp
= fold_build2_loc (input_location
, PLUS_EXPR
,
2231 gfc_array_index_type
, tmp
,
2232 gfc_index_one_node
);
2233 stride
= fold_build2_loc (input_location
, MULT_EXPR
,
2234 gfc_array_index_type
, tmp
, stride
);
2235 /* Check the folding worked. */
2236 gcc_assert (INTEGER_CST_P (stride
));
2241 GFC_TYPE_ARRAY_SIZE (fat_type
) = stride
;
2243 /* TODO: known offsets for descriptors. */
2244 GFC_TYPE_ARRAY_OFFSET (fat_type
) = NULL_TREE
;
2248 arraytype
= build_pointer_type (etype
);
2250 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
2252 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
2256 /* We define data as an array with the correct size if possible.
2257 Much better than doing pointer arithmetic. */
2259 rtype
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
2260 int_const_binop (MINUS_EXPR
, stride
,
2261 build_int_cst (TREE_TYPE (stride
), 1)));
2263 rtype
= gfc_array_range_type
;
2264 arraytype
= build_array_type (etype
, rtype
);
2265 arraytype
= build_pointer_type (arraytype
);
2267 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
2268 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
2270 /* This will generate the base declarations we need to emit debug
2271 information for this type. FIXME: there must be a better way to
2272 avoid divergence between compilations with and without debug
2275 struct array_descr_info info
;
2276 gfc_get_array_descr_info (fat_type
, &info
);
2277 gfc_get_array_descr_info (build_pointer_type (fat_type
), &info
);
2283 /* Build a pointer type. This function is called from gfc_sym_type(). */
2286 gfc_build_pointer_type (gfc_symbol
* sym
, tree type
)
2288 /* Array pointer types aren't actually pointers. */
2289 if (sym
->attr
.dimension
)
2292 return build_pointer_type (type
);
2295 static tree
gfc_nonrestricted_type (tree t
);
2296 /* Given two record or union type nodes TO and FROM, ensure
2297 that all fields in FROM have a corresponding field in TO,
2298 their type being nonrestrict variants. This accepts a TO
2299 node that already has a prefix of the fields in FROM. */
2301 mirror_fields (tree to
, tree from
)
2306 /* Forward to the end of TOs fields. */
2307 fto
= TYPE_FIELDS (to
);
2308 ffrom
= TYPE_FIELDS (from
);
2309 chain
= &TYPE_FIELDS (to
);
2312 gcc_assert (ffrom
&& DECL_NAME (fto
) == DECL_NAME (ffrom
));
2313 chain
= &DECL_CHAIN (fto
);
2314 fto
= DECL_CHAIN (fto
);
2315 ffrom
= DECL_CHAIN (ffrom
);
2318 /* Now add all fields remaining in FROM (starting with ffrom). */
2319 for (; ffrom
; ffrom
= DECL_CHAIN (ffrom
))
2321 tree newfield
= copy_node (ffrom
);
2322 DECL_CONTEXT (newfield
) = to
;
2323 /* The store to DECL_CHAIN might seem redundant with the
2324 stores to *chain, but not clearing it here would mean
2325 leaving a chain into the old fields. If ever
2326 our called functions would look at them confusion
2328 DECL_CHAIN (newfield
) = NULL_TREE
;
2330 chain
= &DECL_CHAIN (newfield
);
2332 if (TREE_CODE (ffrom
) == FIELD_DECL
)
2334 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (ffrom
));
2335 TREE_TYPE (newfield
) = elemtype
;
2341 /* Given a type T, returns a different type of the same structure,
2342 except that all types it refers to (recursively) are always
2343 non-restrict qualified types. */
2345 gfc_nonrestricted_type (tree t
)
2349 /* If the type isn't laid out yet, don't copy it. If something
2350 needs it for real it should wait until the type got finished. */
2354 if (!TYPE_LANG_SPECIFIC (t
))
2355 TYPE_LANG_SPECIFIC (t
) = ggc_cleared_alloc
<struct lang_type
> ();
2356 /* If we're dealing with this very node already further up
2357 the call chain (recursion via pointers and struct members)
2358 we haven't yet determined if we really need a new type node.
2359 Assume we don't, return T itself. */
2360 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
== error_mark_node
)
2363 /* If we have calculated this all already, just return it. */
2364 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
)
2365 return TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
;
2367 /* Mark this type. */
2368 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= error_mark_node
;
2370 switch (TREE_CODE (t
))
2376 case REFERENCE_TYPE
:
2378 tree totype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2379 if (totype
== TREE_TYPE (t
))
2381 else if (TREE_CODE (t
) == POINTER_TYPE
)
2382 ret
= build_pointer_type (totype
);
2384 ret
= build_reference_type (totype
);
2385 ret
= build_qualified_type (ret
,
2386 TYPE_QUALS (t
) & ~TYPE_QUAL_RESTRICT
);
2392 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2393 if (elemtype
== TREE_TYPE (t
))
2397 ret
= build_variant_type_copy (t
);
2398 TREE_TYPE (ret
) = elemtype
;
2399 if (TYPE_LANG_SPECIFIC (t
)
2400 && GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2402 tree dataptr_type
= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
);
2403 dataptr_type
= gfc_nonrestricted_type (dataptr_type
);
2404 if (dataptr_type
!= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2406 TYPE_LANG_SPECIFIC (ret
)
2407 = ggc_cleared_alloc
<struct lang_type
> ();
2408 *TYPE_LANG_SPECIFIC (ret
) = *TYPE_LANG_SPECIFIC (t
);
2409 GFC_TYPE_ARRAY_DATAPTR_TYPE (ret
) = dataptr_type
;
2418 case QUAL_UNION_TYPE
:
2421 /* First determine if we need a new type at all.
2422 Careful, the two calls to gfc_nonrestricted_type per field
2423 might return different values. That happens exactly when
2424 one of the fields reaches back to this very record type
2425 (via pointers). The first calls will assume that we don't
2426 need to copy T (see the error_mark_node marking). If there
2427 are any reasons for copying T apart from having to copy T,
2428 we'll indeed copy it, and the second calls to
2429 gfc_nonrestricted_type will use that new node if they
2431 for (field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
2432 if (TREE_CODE (field
) == FIELD_DECL
)
2434 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (field
));
2435 if (elemtype
!= TREE_TYPE (field
))
2440 ret
= build_variant_type_copy (t
);
2441 TYPE_FIELDS (ret
) = NULL_TREE
;
2443 /* Here we make sure that as soon as we know we have to copy
2444 T, that also fields reaching back to us will use the new
2445 copy. It's okay if that copy still contains the old fields,
2446 we won't look at them. */
2447 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2448 mirror_fields (ret
, t
);
2453 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2458 /* Return the type for a symbol. Special handling is required for character
2459 types to get the correct level of indirection.
2460 For functions return the return type.
2461 For subroutines return void_type_node.
2462 Calling this multiple times for the same symbol should be avoided,
2463 especially for character and array types. */
2466 gfc_sym_type (gfc_symbol
* sym
, bool is_bind_c
)
2472 /* Procedure Pointers inside COMMON blocks. */
2473 if (sym
->attr
.proc_pointer
&& sym
->attr
.in_common
)
2475 /* Unset proc_pointer as gfc_get_function_type calls gfc_sym_type. */
2476 sym
->attr
.proc_pointer
= 0;
2477 type
= build_pointer_type (gfc_get_function_type (sym
));
2478 sym
->attr
.proc_pointer
= 1;
2482 if (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
2483 return void_type_node
;
2485 /* In the case of a function the fake result variable may have a
2486 type different from the function type, so don't return early in
2488 if (sym
->backend_decl
&& !sym
->attr
.function
)
2489 return TREE_TYPE (sym
->backend_decl
);
2491 if (sym
->attr
.result
2492 && sym
->ts
.type
== BT_CHARACTER
2493 && sym
->ts
.u
.cl
->backend_decl
== NULL_TREE
2494 && sym
->ns
->proc_name
2495 && sym
->ns
->proc_name
->ts
.u
.cl
2496 && sym
->ns
->proc_name
->ts
.u
.cl
->backend_decl
!= NULL_TREE
)
2497 sym
->ts
.u
.cl
->backend_decl
= sym
->ns
->proc_name
->ts
.u
.cl
->backend_decl
;
2499 if (sym
->ts
.type
== BT_CHARACTER
2500 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
)
2501 || ((sym
->attr
.result
|| sym
->attr
.value
)
2502 && sym
->ns
->proc_name
2503 && sym
->ns
->proc_name
->attr
.is_bind_c
)
2504 || (sym
->ts
.deferred
2506 || !sym
->ts
.u
.cl
->backend_decl
2510 && gfc_length_one_character_type_p (&sym
->ts
))))
2511 type
= gfc_get_char_type (sym
->ts
.kind
);
2513 type
= gfc_typenode_for_spec (&sym
->ts
, sym
->attr
.codimension
);
2515 if (sym
->attr
.dummy
&& !sym
->attr
.function
&& !sym
->attr
.value
2516 && !sym
->pass_as_value
)
2521 restricted
= (!sym
->attr
.target
&& !IS_POINTER (sym
)
2522 && !IS_PROC_POINTER (sym
) && !sym
->attr
.cray_pointee
);
2524 type
= gfc_nonrestricted_type (type
);
2526 /* Dummy argument to a bind(C) procedure. */
2527 if (is_bind_c
&& is_CFI_desc (sym
, NULL
))
2528 type
= gfc_get_cfi_type (sym
->attr
.dimension
? sym
->as
->rank
: 0,
2529 /* restricted = */ false);
2530 else if (sym
->attr
.dimension
|| sym
->attr
.codimension
)
2532 if (gfc_is_nodesc_array (sym
))
2534 /* If this is a character argument of unknown length, just use the
2536 if (sym
->ts
.type
!= BT_CHARACTER
2537 || !(sym
->attr
.dummy
|| sym
->attr
.function
)
2538 || sym
->ts
.u
.cl
->backend_decl
)
2540 type
= gfc_get_nodesc_array_type (type
, sym
->as
,
2549 enum gfc_array_kind akind
= GFC_ARRAY_UNKNOWN
;
2550 if (sym
->attr
.pointer
)
2551 akind
= sym
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2552 : GFC_ARRAY_POINTER
;
2553 else if (sym
->attr
.allocatable
)
2554 akind
= GFC_ARRAY_ALLOCATABLE
;
2555 type
= gfc_build_array_type (type
, sym
->as
, akind
, restricted
,
2556 sym
->attr
.contiguous
, sym
->as
->corank
);
2561 if (sym
->attr
.allocatable
|| sym
->attr
.pointer
2562 || gfc_is_associate_pointer (sym
))
2563 type
= gfc_build_pointer_type (sym
, type
);
2566 /* We currently pass all parameters by reference.
2567 See f95_get_function_decl. For dummy function parameters return the
2571 /* We must use pointer types for potentially absent variables. The
2572 optimizers assume a reference type argument is never NULL. */
2573 if ((sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->attr
.optional
)
2574 || sym
->attr
.optional
2575 || (sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.entry_master
))
2576 type
= build_pointer_type (type
);
2578 type
= build_reference_type (type
);
2581 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
2587 /* Layout and output debug info for a record type. */
2590 gfc_finish_type (tree type
)
2594 decl
= build_decl (input_location
,
2595 TYPE_DECL
, NULL_TREE
, type
);
2596 TYPE_STUB_DECL (type
) = decl
;
2598 rest_of_type_compilation (type
, 1);
2599 rest_of_decl_compilation (decl
, 1, 0);
2602 /* Add a field of given NAME and TYPE to the context of a UNION_TYPE
2603 or RECORD_TYPE pointed to by CONTEXT. The new field is chained
2604 to the end of the field list pointed to by *CHAIN.
2606 Returns a pointer to the new field. */
2609 gfc_add_field_to_struct_1 (tree context
, tree name
, tree type
, tree
**chain
)
2611 tree decl
= build_decl (input_location
, FIELD_DECL
, name
, type
);
2613 DECL_CONTEXT (decl
) = context
;
2614 DECL_CHAIN (decl
) = NULL_TREE
;
2615 if (TYPE_FIELDS (context
) == NULL_TREE
)
2616 TYPE_FIELDS (context
) = decl
;
2621 *chain
= &DECL_CHAIN (decl
);
2627 /* Like `gfc_add_field_to_struct_1', but adds alignment
2631 gfc_add_field_to_struct (tree context
, tree name
, tree type
, tree
**chain
)
2633 tree decl
= gfc_add_field_to_struct_1 (context
, name
, type
, chain
);
2635 DECL_INITIAL (decl
) = 0;
2636 SET_DECL_ALIGN (decl
, 0);
2637 DECL_USER_ALIGN (decl
) = 0;
2643 /* Copy the backend_decl and component backend_decls if
2644 the two derived type symbols are "equal", as described
2645 in 4.4.2 and resolved by gfc_compare_derived_types. */
2648 gfc_copy_dt_decls_ifequal (gfc_symbol
*from
, gfc_symbol
*to
,
2651 gfc_component
*to_cm
;
2652 gfc_component
*from_cm
;
2657 if (from
->backend_decl
== NULL
2658 || !gfc_compare_derived_types (from
, to
))
2661 to
->backend_decl
= from
->backend_decl
;
2663 to_cm
= to
->components
;
2664 from_cm
= from
->components
;
2666 /* Copy the component declarations. If a component is itself
2667 a derived type, we need a copy of its component declarations.
2668 This is done by recursing into gfc_get_derived_type and
2669 ensures that the component's component declarations have
2670 been built. If it is a character, we need the character
2672 for (; to_cm
; to_cm
= to_cm
->next
, from_cm
= from_cm
->next
)
2674 to_cm
->backend_decl
= from_cm
->backend_decl
;
2675 to_cm
->caf_token
= from_cm
->caf_token
;
2676 if (from_cm
->ts
.type
== BT_UNION
)
2677 gfc_get_union_type (to_cm
->ts
.u
.derived
);
2678 else if (from_cm
->ts
.type
== BT_DERIVED
2679 && (!from_cm
->attr
.pointer
|| from_gsym
))
2680 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2681 else if (from_cm
->ts
.type
== BT_CLASS
2682 && (!CLASS_DATA (from_cm
)->attr
.class_pointer
|| from_gsym
))
2683 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2684 else if (from_cm
->ts
.type
== BT_CHARACTER
)
2685 to_cm
->ts
.u
.cl
->backend_decl
= from_cm
->ts
.u
.cl
->backend_decl
;
2692 /* Build a tree node for a procedure pointer component. */
2695 gfc_get_ppc_type (gfc_component
* c
)
2699 /* Explicit interface. */
2700 if (c
->attr
.if_source
!= IFSRC_UNKNOWN
&& c
->ts
.interface
)
2701 return build_pointer_type (gfc_get_function_type (c
->ts
.interface
));
2703 /* Implicit interface (only return value may be known). */
2704 if (c
->attr
.function
&& !c
->attr
.dimension
&& c
->ts
.type
!= BT_CHARACTER
)
2705 t
= gfc_typenode_for_spec (&c
->ts
);
2709 /* FIXME: it would be better to provide explicit interfaces in all
2710 cases, since they should be known by the compiler. */
2711 return build_pointer_type (build_function_type (t
, NULL_TREE
));
2715 /* Build a tree node for a union type. Requires building each map
2716 structure which is an element of the union. */
2719 gfc_get_union_type (gfc_symbol
*un
)
2721 gfc_component
*map
= NULL
;
2722 tree typenode
= NULL
, map_type
= NULL
, map_field
= NULL
;
2725 if (un
->backend_decl
)
2727 if (TYPE_FIELDS (un
->backend_decl
) || un
->attr
.proc_pointer_comp
)
2728 return un
->backend_decl
;
2730 typenode
= un
->backend_decl
;
2734 typenode
= make_node (UNION_TYPE
);
2735 TYPE_NAME (typenode
) = get_identifier (un
->name
);
2738 /* Add each contained MAP as a field. */
2739 for (map
= un
->components
; map
; map
= map
->next
)
2741 gcc_assert (map
->ts
.type
== BT_DERIVED
);
2743 /* The map's type node, which is defined within this union's context. */
2744 map_type
= gfc_get_derived_type (map
->ts
.u
.derived
);
2745 TYPE_CONTEXT (map_type
) = typenode
;
2747 /* The map field's declaration. */
2748 map_field
= gfc_add_field_to_struct(typenode
, get_identifier(map
->name
),
2750 if (GFC_LOCUS_IS_SET (map
->loc
))
2751 gfc_set_decl_location (map_field
, &map
->loc
);
2752 else if (GFC_LOCUS_IS_SET (un
->declared_at
))
2753 gfc_set_decl_location (map_field
, &un
->declared_at
);
2755 DECL_PACKED (map_field
) |= TYPE_PACKED (typenode
);
2756 DECL_NAMELESS(map_field
) = true;
2758 /* We should never clobber another backend declaration for this map,
2759 because each map component is unique. */
2760 if (!map
->backend_decl
)
2761 map
->backend_decl
= map_field
;
2764 un
->backend_decl
= typenode
;
2765 gfc_finish_type (typenode
);
2771 cobounds_match_decl (const gfc_symbol
*derived
)
2776 if (!derived
->backend_decl
)
2778 /* Care only about coarray declarations. Everything else is ok with us. */
2779 if (!derived
->components
|| strcmp (derived
->components
->name
, "_data") != 0)
2781 if (!derived
->components
->attr
.codimension
)
2784 arrtype
= TREE_TYPE (TYPE_FIELDS (derived
->backend_decl
));
2785 as
= derived
->components
->as
;
2786 if (GFC_TYPE_ARRAY_CORANK (arrtype
) != as
->corank
)
2789 for (int dim
= as
->rank
; dim
< as
->rank
+ as
->corank
; ++dim
)
2791 /* Check lower bound. */
2792 tmp
= TYPE_LANG_SPECIFIC (arrtype
)->lbound
[dim
];
2793 if (!tmp
|| !INTEGER_CST_P (tmp
))
2795 if (as
->lower
[dim
]->expr_type
!= EXPR_CONSTANT
2796 || as
->lower
[dim
]->ts
.type
!= BT_INTEGER
)
2798 if (*tmp
->int_cst
.val
!= mpz_get_si (as
->lower
[dim
]->value
.integer
))
2801 /* Check upper bound. */
2802 tmp
= TYPE_LANG_SPECIFIC (arrtype
)->ubound
[dim
];
2803 if (!tmp
&& !as
->upper
[dim
])
2806 if (!tmp
|| !INTEGER_CST_P (tmp
))
2808 if (as
->upper
[dim
]->expr_type
!= EXPR_CONSTANT
2809 || as
->upper
[dim
]->ts
.type
!= BT_INTEGER
)
2811 if (*tmp
->int_cst
.val
!= mpz_get_si (as
->upper
[dim
]->value
.integer
))
2818 /* Build a tree node for a derived type. If there are equal
2819 derived types, with different local names, these are built
2820 at the same time. If an equal derived type has been built
2821 in a parent namespace, this is used. */
2824 gfc_get_derived_type (gfc_symbol
* derived
, int codimen
)
2826 tree typenode
= NULL
, field
= NULL
, field_type
= NULL
;
2827 tree canonical
= NULL_TREE
;
2829 bool got_canonical
= false;
2830 bool unlimited_entity
= false;
2834 bool coarray_flag
, class_coarray_flag
;
2836 coarray_flag
= flag_coarray
== GFC_FCOARRAY_LIB
2837 && derived
->module
&& !derived
->attr
.vtype
;
2838 class_coarray_flag
= derived
->components
2839 && derived
->components
->ts
.type
== BT_DERIVED
2840 && strcmp (derived
->components
->name
, "_data") == 0
2841 && derived
->components
->attr
.codimension
2842 && derived
->components
->as
->cotype
== AS_EXPLICIT
;
2844 gcc_assert (!derived
->attr
.pdt_template
);
2846 if (derived
->attr
.unlimited_polymorphic
2847 || (flag_coarray
== GFC_FCOARRAY_LIB
2848 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2849 && (derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
2850 || derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
2851 || derived
->intmod_sym_id
== ISOFORTRAN_TEAM_TYPE
)))
2852 return ptr_type_node
;
2854 if (flag_coarray
!= GFC_FCOARRAY_LIB
2855 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2856 && (derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
2857 || derived
->intmod_sym_id
== ISOFORTRAN_TEAM_TYPE
))
2858 return gfc_get_int_type (gfc_default_integer_kind
);
2860 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
2861 && derived
->attr
.generic
)
2862 derived
= gfc_find_dt_in_generic (derived
);
2864 /* See if it's one of the iso_c_binding derived types. */
2865 if (derived
->attr
.is_iso_c
== 1 || derived
->ts
.f90_type
== BT_VOID
)
2867 if (derived
->backend_decl
)
2868 return derived
->backend_decl
;
2870 if (derived
->intmod_sym_id
== ISOCBINDING_PTR
)
2871 derived
->backend_decl
= ptr_type_node
;
2873 derived
->backend_decl
= pfunc_type_node
;
2875 derived
->ts
.kind
= gfc_index_integer_kind
;
2876 derived
->ts
.type
= BT_INTEGER
;
2877 /* Set the f90_type to BT_VOID as a way to recognize something of type
2878 BT_INTEGER that needs to fit a void * for the purpose of the
2879 iso_c_binding derived types. */
2880 derived
->ts
.f90_type
= BT_VOID
;
2882 return derived
->backend_decl
;
2885 /* If use associated, use the module type for this one. */
2886 if (derived
->backend_decl
== NULL
2887 && (derived
->attr
.use_assoc
|| derived
->attr
.used_in_submodule
)
2889 && gfc_get_module_backend_decl (derived
))
2890 goto copy_derived_types
;
2892 /* The derived types from an earlier namespace can be used as the
2894 if (derived
->backend_decl
== NULL
2895 && !derived
->attr
.use_assoc
2896 && !derived
->attr
.used_in_submodule
2897 && gfc_global_ns_list
)
2899 for (ns
= gfc_global_ns_list
;
2900 ns
->translated
&& !got_canonical
;
2903 if (ns
->derived_types
)
2905 for (gfc_symbol
*dt
= ns
->derived_types
; dt
&& !got_canonical
;
2908 gfc_copy_dt_decls_ifequal (dt
, derived
, true);
2909 if (derived
->backend_decl
)
2910 got_canonical
= true;
2911 if (dt
->dt_next
== ns
->derived_types
)
2918 /* Store up the canonical type to be added to this one. */
2921 if (TYPE_CANONICAL (derived
->backend_decl
))
2922 canonical
= TYPE_CANONICAL (derived
->backend_decl
);
2924 canonical
= derived
->backend_decl
;
2926 derived
->backend_decl
= NULL_TREE
;
2929 /* derived->backend_decl != 0 means we saw it before, but its
2930 components' backend_decl may have not been built. */
2931 if (derived
->backend_decl
2932 && (!class_coarray_flag
|| cobounds_match_decl (derived
)))
2934 /* Its components' backend_decl have been built or we are
2935 seeing recursion through the formal arglist of a procedure
2936 pointer component. */
2937 if (TYPE_FIELDS (derived
->backend_decl
))
2938 return derived
->backend_decl
;
2939 else if (derived
->attr
.abstract
2940 && derived
->attr
.proc_pointer_comp
)
2942 /* If an abstract derived type with procedure pointer
2943 components has no other type of component, return the
2944 backend_decl. Otherwise build the components if any of the
2945 non-procedure pointer components have no backend_decl. */
2946 for (c
= derived
->components
; c
; c
= c
->next
)
2948 bool same_alloc_type
= c
->attr
.allocatable
2949 && derived
== c
->ts
.u
.derived
;
2950 if (!c
->attr
.proc_pointer
2952 && c
->backend_decl
== NULL
)
2954 else if (c
->next
== NULL
)
2955 return derived
->backend_decl
;
2957 typenode
= derived
->backend_decl
;
2960 typenode
= derived
->backend_decl
;
2964 /* We see this derived type first time, so build the type node. */
2965 typenode
= make_node (RECORD_TYPE
);
2966 TYPE_NAME (typenode
) = get_identifier (derived
->name
);
2967 TYPE_PACKED (typenode
) = flag_pack_derived
;
2968 derived
->backend_decl
= typenode
;
2971 if (derived
->components
2972 && derived
->components
->ts
.type
== BT_DERIVED
2973 && startswith (derived
->name
, "__class")
2974 && strcmp (derived
->components
->name
, "_data") == 0
2975 && derived
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
2976 unlimited_entity
= true;
2978 /* Go through the derived type components, building them as
2979 necessary. The reason for doing this now is that it is
2980 possible to recurse back to this derived type through a
2981 pointer component (PR24092). If this happens, the fields
2982 will be built and so we can return the type. */
2983 for (c
= derived
->components
; c
; c
= c
->next
)
2985 if (c
->ts
.type
== BT_UNION
&& c
->ts
.u
.derived
->backend_decl
== NULL
)
2986 c
->ts
.u
.derived
->backend_decl
= gfc_get_union_type (c
->ts
.u
.derived
);
2988 if (c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
2991 const bool incomplete_type
2992 = c
->ts
.u
.derived
->backend_decl
2993 && TREE_CODE (c
->ts
.u
.derived
->backend_decl
) == RECORD_TYPE
2994 && !(TYPE_LANG_SPECIFIC (c
->ts
.u
.derived
->backend_decl
)
2995 && TYPE_LANG_SPECIFIC (c
->ts
.u
.derived
->backend_decl
)->size
);
2996 const bool pointer_component
2997 = c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.proc_pointer
;
2999 /* Prevent endless recursion on recursive types (i.e. types that reference
3000 themself in a component. Break the recursion by not building pointers
3001 to incomplete types again, aka types that are already in the build. */
3002 if (c
->ts
.u
.derived
->backend_decl
== NULL
3003 || (c
->attr
.codimension
&& c
->as
->corank
!= codimen
)
3004 || !(incomplete_type
&& pointer_component
))
3006 int local_codim
= c
->attr
.codimension
? c
->as
->corank
: codimen
;
3007 c
->ts
.u
.derived
->backend_decl
= gfc_get_derived_type (c
->ts
.u
.derived
,
3011 if (c
->ts
.u
.derived
->attr
.is_iso_c
)
3013 /* Need to copy the modified ts from the derived type. The
3014 typespec was modified because C_PTR/C_FUNPTR are translated
3015 into (void *) from derived types. */
3016 c
->ts
.type
= c
->ts
.u
.derived
->ts
.type
;
3017 c
->ts
.kind
= c
->ts
.u
.derived
->ts
.kind
;
3018 c
->ts
.f90_type
= c
->ts
.u
.derived
->ts
.f90_type
;
3021 c
->initializer
->ts
.type
= c
->ts
.type
;
3022 c
->initializer
->ts
.kind
= c
->ts
.kind
;
3023 c
->initializer
->ts
.f90_type
= c
->ts
.f90_type
;
3024 c
->initializer
->expr_type
= EXPR_NULL
;
3029 if (!class_coarray_flag
&& TYPE_FIELDS (derived
->backend_decl
))
3030 return derived
->backend_decl
;
3032 /* Build the type member list. Install the newly created RECORD_TYPE
3033 node as DECL_CONTEXT of each FIELD_DECL. In this case we must go
3034 through only the top-level linked list of components so we correctly
3035 build UNION_TYPE nodes for BT_UNION components. MAPs and other nested
3036 types are built as part of gfc_get_union_type. */
3037 for (c
= derived
->components
; c
; c
= c
->next
)
3039 bool same_alloc_type
= c
->attr
.allocatable
3040 && derived
== c
->ts
.u
.derived
;
3041 /* Prevent infinite recursion, when the procedure pointer type is
3042 the same as derived, by forcing the procedure pointer component to
3043 be built as if the explicit interface does not exist. */
3044 if (c
->attr
.proc_pointer
3045 && (c
->ts
.type
!= BT_DERIVED
|| (c
->ts
.u
.derived
3046 && !gfc_compare_derived_types (derived
, c
->ts
.u
.derived
)))
3047 && (c
->ts
.type
!= BT_CLASS
|| (CLASS_DATA (c
)->ts
.u
.derived
3048 && !gfc_compare_derived_types (derived
, CLASS_DATA (c
)->ts
.u
.derived
))))
3049 field_type
= gfc_get_ppc_type (c
);
3050 else if (c
->attr
.proc_pointer
&& derived
->backend_decl
)
3052 tmp
= build_function_type (derived
->backend_decl
, NULL_TREE
);
3053 field_type
= build_pointer_type (tmp
);
3055 else if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
3056 field_type
= c
->ts
.u
.derived
->backend_decl
;
3057 else if (c
->attr
.caf_token
)
3058 field_type
= pvoid_type_node
;
3061 if (c
->ts
.type
== BT_CHARACTER
3062 && !c
->ts
.deferred
&& !c
->attr
.pdt_string
)
3064 /* Evaluate the string length. */
3065 gfc_conv_const_charlen (c
->ts
.u
.cl
);
3066 gcc_assert (c
->ts
.u
.cl
->backend_decl
);
3068 else if (c
->ts
.type
== BT_CHARACTER
)
3069 c
->ts
.u
.cl
->backend_decl
3070 = build_int_cst (gfc_charlen_type_node
, 0);
3072 field_type
= gfc_typenode_for_spec (&c
->ts
, codimen
);
3075 /* This returns an array descriptor type. Initialization may be
3077 if ((c
->attr
.dimension
|| c
->attr
.codimension
) && !c
->attr
.proc_pointer
)
3079 if (c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_array
)
3081 enum gfc_array_kind akind
;
3082 bool is_ptr
= ((c
== derived
->components
3083 && derived
->components
->ts
.type
== BT_DERIVED
3084 && startswith (derived
->name
, "__class")
3085 && (strcmp (derived
->components
->name
, "_data")
3087 ? c
->attr
.class_pointer
: c
->attr
.pointer
);
3089 akind
= c
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
3090 : GFC_ARRAY_POINTER
;
3091 else if (c
->attr
.allocatable
)
3092 akind
= GFC_ARRAY_ALLOCATABLE
;
3093 else if (c
->as
->type
== AS_ASSUMED_RANK
)
3094 akind
= GFC_ARRAY_ASSUMED_RANK
;
3096 /* FIXME – see PR fortran/104651. Additionally, the following
3097 gfc_build_array_type should use !is_ptr instead of
3098 c->attr.pointer and codim unconditionally without '? :'. */
3099 akind
= GFC_ARRAY_ASSUMED_SHAPE
;
3100 /* Pointers to arrays aren't actually pointer types. The
3101 descriptors are separate, but the data is common. Every
3102 array pointer in a coarray derived type needs to provide space
3103 for the coarray management, too. Therefore treat coarrays
3104 and pointers to coarrays in derived types the same. */
3105 field_type
= gfc_build_array_type
3107 field_type
, c
->as
, akind
, !c
->attr
.target
&& !c
->attr
.pointer
,
3109 c
->attr
.codimension
|| c
->attr
.pointer
? codimen
: 0
3113 field_type
= gfc_get_nodesc_array_type (field_type
, c
->as
,
3117 else if ((c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_string
)
3118 && !c
->attr
.proc_pointer
3119 && !(unlimited_entity
&& c
== derived
->components
))
3120 field_type
= build_pointer_type (field_type
);
3122 if (c
->attr
.pointer
|| same_alloc_type
)
3123 field_type
= gfc_nonrestricted_type (field_type
);
3125 /* vtype fields can point to different types to the base type. */
3126 if (c
->ts
.type
== BT_DERIVED
3127 && c
->ts
.u
.derived
&& c
->ts
.u
.derived
->attr
.vtype
)
3128 field_type
= build_pointer_type_for_mode (TREE_TYPE (field_type
),
3131 /* Ensure that the CLASS language specific flag is set. */
3132 if (c
->ts
.type
== BT_CLASS
)
3134 if (POINTER_TYPE_P (field_type
))
3135 GFC_CLASS_TYPE_P (TREE_TYPE (field_type
)) = 1;
3137 GFC_CLASS_TYPE_P (field_type
) = 1;
3140 field
= gfc_add_field_to_struct (typenode
,
3141 get_identifier (c
->name
),
3142 field_type
, &chain
);
3143 if (GFC_LOCUS_IS_SET (c
->loc
))
3144 gfc_set_decl_location (field
, &c
->loc
);
3145 else if (GFC_LOCUS_IS_SET (derived
->declared_at
))
3146 gfc_set_decl_location (field
, &derived
->declared_at
);
3148 gfc_finish_decl_attrs (field
, &c
->attr
);
3150 DECL_PACKED (field
) |= TYPE_PACKED (typenode
);
3153 /* Overwrite for class array to supply different bounds for different
3155 if (class_coarray_flag
|| !c
->backend_decl
|| c
->attr
.caf_token
)
3156 c
->backend_decl
= field
;
3158 if (c
->attr
.pointer
&& (c
->attr
.dimension
|| c
->attr
.codimension
)
3159 && !(c
->ts
.type
== BT_DERIVED
&& strcmp (c
->name
, "_data") == 0))
3160 GFC_DECL_PTR_ARRAY_P (c
->backend_decl
) = 1;
3163 /* Now lay out the derived type, including the fields. */
3165 TYPE_CANONICAL (typenode
) = canonical
;
3167 gfc_finish_type (typenode
);
3168 gfc_set_decl_location (TYPE_STUB_DECL (typenode
), &derived
->declared_at
);
3169 if (derived
->module
&& derived
->ns
->proc_name
3170 && derived
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
3172 if (derived
->ns
->proc_name
->backend_decl
3173 && TREE_CODE (derived
->ns
->proc_name
->backend_decl
)
3176 TYPE_CONTEXT (typenode
) = derived
->ns
->proc_name
->backend_decl
;
3177 DECL_CONTEXT (TYPE_STUB_DECL (typenode
))
3178 = derived
->ns
->proc_name
->backend_decl
;
3182 derived
->backend_decl
= typenode
;
3186 if (!derived
->attr
.vtype
)
3187 for (c
= derived
->components
; c
; c
= c
->next
)
3189 /* Do not add a caf_token field for class container components. */
3190 if (codimen
&& coarray_flag
&& !c
->attr
.dimension
3191 && !c
->attr
.codimension
&& (c
->attr
.allocatable
|| c
->attr
.pointer
)
3192 && !derived
->attr
.is_class
)
3194 /* Provide sufficient space to hold "_caf_symbol". */
3195 char caf_name
[GFC_MAX_SYMBOL_LEN
+ 6];
3196 gfc_component
*token
;
3197 snprintf (caf_name
, sizeof (caf_name
), "_caf_%s", c
->name
);
3198 token
= gfc_find_component (derived
, caf_name
, true, true, NULL
);
3200 gfc_comp_caf_token (c
) = token
->backend_decl
;
3201 suppress_warning (gfc_comp_caf_token (c
));
3205 for (gfc_symbol
*dt
= gfc_derived_types
; dt
; dt
= dt
->dt_next
)
3207 gfc_copy_dt_decls_ifequal (derived
, dt
, false);
3208 if (dt
->dt_next
== gfc_derived_types
)
3212 return derived
->backend_decl
;
3217 gfc_return_by_reference (gfc_symbol
* sym
)
3219 if (!sym
->attr
.function
)
3222 if (sym
->attr
.dimension
)
3225 if (sym
->ts
.type
== BT_CHARACTER
3226 && !sym
->attr
.is_bind_c
3227 && (!sym
->attr
.result
3228 || !sym
->ns
->proc_name
3229 || !sym
->ns
->proc_name
->attr
.is_bind_c
))
3232 /* Possibly return complex numbers by reference for g77 compatibility.
3233 We don't do this for calls to intrinsics (as the library uses the
3234 -fno-f2c calling convention) except for calls to specific wrappers
3235 (_gfortran_f2c_specific_*), nor for calls to functions which always
3236 require an explicit interface, as no compatibility problems can
3238 if (flag_f2c
&& sym
->ts
.type
== BT_COMPLEX
3239 && !sym
->attr
.pointer
3240 && !sym
->attr
.allocatable
3241 && !sym
->attr
.always_explicit
)
3248 gfc_get_mixed_entry_union (gfc_namespace
*ns
)
3252 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
3253 gfc_entry_list
*el
, *el2
;
3255 gcc_assert (ns
->proc_name
->attr
.mixed_entry_master
);
3256 gcc_assert (memcmp (ns
->proc_name
->name
, "master.", 7) == 0);
3258 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "munion.%s", ns
->proc_name
->name
+ 7);
3260 /* Build the type node. */
3261 type
= make_node (UNION_TYPE
);
3263 TYPE_NAME (type
) = get_identifier (name
);
3265 for (el
= ns
->entries
; el
; el
= el
->next
)
3267 /* Search for duplicates. */
3268 for (el2
= ns
->entries
; el2
!= el
; el2
= el2
->next
)
3269 if (el2
->sym
->result
== el
->sym
->result
)
3273 gfc_add_field_to_struct_1 (type
,
3274 get_identifier (el
->sym
->result
->name
),
3275 gfc_sym_type (el
->sym
->result
), &chain
);
3278 /* Finish off the type. */
3279 gfc_finish_type (type
);
3280 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
3284 /* Create a "fn spec" based on the formal arguments;
3285 cf. create_function_arglist. */
3288 create_fn_spec (gfc_symbol
*sym
, tree fntype
)
3292 gfc_formal_arglist
*f
;
3295 memset (&spec
, 0, sizeof (spec
));
3300 if (sym
->attr
.entry_master
)
3302 spec
[spec_len
++] = 'R';
3303 spec
[spec_len
++] = ' ';
3305 if (gfc_return_by_reference (sym
))
3307 gfc_symbol
*result
= sym
->result
? sym
->result
: sym
;
3309 if (result
->attr
.pointer
|| sym
->attr
.proc_pointer
)
3311 spec
[spec_len
++] = '.';
3312 spec
[spec_len
++] = ' ';
3316 spec
[spec_len
++] = 'w';
3317 spec
[spec_len
++] = ' ';
3319 if (sym
->ts
.type
== BT_CHARACTER
)
3321 if (!sym
->ts
.u
.cl
->length
3322 && (sym
->attr
.allocatable
|| sym
->attr
.pointer
))
3323 spec
[spec_len
++] = 'w';
3325 spec
[spec_len
++] = 'R';
3326 spec
[spec_len
++] = ' ';
3330 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3331 if (spec_len
< sizeof (spec
))
3333 bool is_class
= false;
3334 bool is_pointer
= false;
3338 is_class
= f
->sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (f
->sym
)
3339 && f
->sym
->attr
.class_ok
;
3340 is_pointer
= is_class
? CLASS_DATA (f
->sym
)->attr
.class_pointer
3341 : f
->sym
->attr
.pointer
;
3344 if (f
->sym
== NULL
|| is_pointer
|| f
->sym
->attr
.target
3345 || f
->sym
->attr
.external
|| f
->sym
->attr
.cray_pointer
3346 || (f
->sym
->ts
.type
== BT_DERIVED
3347 && (f
->sym
->ts
.u
.derived
->attr
.proc_pointer_comp
3348 || f
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
3350 && (CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.proc_pointer_comp
3351 || CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.pointer_comp
))
3352 || (f
->sym
->ts
.type
== BT_INTEGER
&& f
->sym
->ts
.is_c_interop
))
3354 spec
[spec_len
++] = '.';
3355 spec
[spec_len
++] = ' ';
3357 else if (f
->sym
->attr
.intent
== INTENT_IN
)
3359 spec
[spec_len
++] = 'r';
3360 spec
[spec_len
++] = ' ';
3364 spec
[spec_len
++] = 'w';
3365 spec
[spec_len
++] = ' ';
3369 tmp
= build_tree_list (NULL_TREE
, build_string (spec_len
, spec
));
3370 tmp
= tree_cons (get_identifier ("fn spec"), tmp
, TYPE_ATTRIBUTES (fntype
));
3371 return build_type_attribute_variant (fntype
, tmp
);
3375 /* NOTE: The returned function type must match the argument list created by
3376 create_function_arglist. */
3379 gfc_get_function_type (gfc_symbol
* sym
, gfc_actual_arglist
*actual_args
,
3383 vec
<tree
, va_gc
> *typelist
= NULL
;
3384 vec
<tree
, va_gc
> *hidden_typelist
= NULL
;
3385 gfc_formal_arglist
*f
;
3387 int alternate_return
= 0;
3388 bool is_varargs
= true;
3390 /* Make sure this symbol is a function, a subroutine or the main
3392 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
3393 || sym
->attr
.flavor
== FL_PROGRAM
);
3395 /* To avoid recursing infinitely on recursive types, we use error_mark_node
3396 so that they can be detected here and handled further down. */
3397 if (sym
->backend_decl
== NULL
)
3398 sym
->backend_decl
= error_mark_node
;
3399 else if (sym
->backend_decl
== error_mark_node
)
3400 goto arg_type_list_done
;
3401 else if (sym
->attr
.proc_pointer
)
3402 return TREE_TYPE (TREE_TYPE (sym
->backend_decl
));
3404 return TREE_TYPE (sym
->backend_decl
);
3406 if (sym
->attr
.entry_master
)
3407 /* Additional parameter for selecting an entry point. */
3408 vec_safe_push (typelist
, gfc_array_index_type
);
3415 if (arg
->ts
.type
== BT_CHARACTER
)
3416 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
3418 /* Some functions we use an extra parameter for the return value. */
3419 if (gfc_return_by_reference (sym
))
3421 type
= gfc_sym_type (arg
);
3422 if (arg
->ts
.type
== BT_COMPLEX
3423 || arg
->attr
.dimension
3424 || arg
->ts
.type
== BT_CHARACTER
)
3425 type
= build_reference_type (type
);
3427 vec_safe_push (typelist
, type
);
3428 if (arg
->ts
.type
== BT_CHARACTER
)
3430 if (!arg
->ts
.deferred
)
3431 /* Transfer by value. */
3432 vec_safe_push (typelist
, gfc_charlen_type_node
);
3434 /* Deferred character lengths are transferred by reference
3435 so that the value can be returned. */
3436 vec_safe_push (typelist
, build_pointer_type(gfc_charlen_type_node
));
3439 if (sym
->backend_decl
== error_mark_node
&& actual_args
!= NULL
3440 && sym
->formal
== NULL
&& (sym
->attr
.proc
== PROC_EXTERNAL
3441 || sym
->attr
.proc
== PROC_UNKNOWN
))
3442 gfc_get_formal_from_actual_arglist (sym
, actual_args
);
3444 /* Build the argument types for the function. */
3445 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3450 /* Evaluate constant character lengths here so that they can be
3451 included in the type. */
3452 if (arg
->ts
.type
== BT_CHARACTER
)
3453 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
3455 if (arg
->attr
.flavor
== FL_PROCEDURE
)
3457 type
= gfc_get_function_type (arg
);
3458 type
= build_pointer_type (type
);
3461 type
= gfc_sym_type (arg
, sym
->attr
.is_bind_c
);
3463 /* Parameter Passing Convention
3465 We currently pass all parameters by reference.
3466 Parameters with INTENT(IN) could be passed by value.
3467 The problem arises if a function is called via an implicit
3468 prototype. In this situation the INTENT is not known.
3469 For this reason all parameters to global functions must be
3470 passed by reference. Passing by value would potentially
3471 generate bad code. Worse there would be no way of telling that
3472 this code was bad, except that it would give incorrect results.
3474 Contained procedures could pass by value as these are never
3475 used without an explicit interface, and cannot be passed as
3476 actual parameters for a dummy procedure. */
3478 vec_safe_push (typelist
, type
);
3482 if (sym
->attr
.subroutine
)
3483 alternate_return
= 1;
3487 /* Add hidden arguments. */
3488 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3491 /* Add hidden string length parameters. */
3492 if (arg
&& arg
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.is_bind_c
)
3494 if (!arg
->ts
.deferred
)
3495 /* Transfer by value. */
3496 type
= gfc_charlen_type_node
;
3498 /* Deferred character lengths are transferred by reference
3499 so that the value can be returned. */
3500 type
= build_pointer_type (gfc_charlen_type_node
);
3502 vec_safe_push (hidden_typelist
, type
);
3504 /* For scalar intrinsic types or derived types, VALUE passes the value,
3505 hence, the optional status cannot be transferred via a NULL pointer.
3506 Thus, we will use a hidden argument in that case. */
3508 && arg
->attr
.optional
3510 && !arg
->attr
.dimension
3511 && arg
->ts
.type
!= BT_CLASS
)
3512 vec_safe_push (typelist
, boolean_type_node
);
3513 /* Coarrays which are descriptorless or assumed-shape pass with
3514 -fcoarray=lib the token and the offset as hidden arguments. */
3516 && flag_coarray
== GFC_FCOARRAY_LIB
3517 && ((arg
->ts
.type
!= BT_CLASS
3518 && arg
->attr
.codimension
3519 && !arg
->attr
.allocatable
)
3520 || (arg
->ts
.type
== BT_CLASS
3521 && CLASS_DATA (arg
)->attr
.codimension
3522 && !CLASS_DATA (arg
)->attr
.allocatable
)))
3524 vec_safe_push (hidden_typelist
, pvoid_type_node
); /* caf_token. */
3525 vec_safe_push (hidden_typelist
, gfc_array_index_type
); /* caf_offset. */
3529 /* Put hidden character length, caf_token, caf_offset at the end. */
3530 vec_safe_reserve (typelist
, vec_safe_length (hidden_typelist
));
3531 vec_safe_splice (typelist
, hidden_typelist
);
3533 if (!vec_safe_is_empty (typelist
)
3534 || sym
->attr
.is_main_program
3535 || sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
3538 if (sym
->backend_decl
== error_mark_node
)
3539 sym
->backend_decl
= NULL_TREE
;
3543 if (alternate_return
)
3544 type
= integer_type_node
;
3545 else if (!sym
->attr
.function
|| gfc_return_by_reference (sym
))
3546 type
= void_type_node
;
3547 else if (sym
->attr
.mixed_entry_master
)
3548 type
= gfc_get_mixed_entry_union (sym
->ns
);
3549 else if (flag_f2c
&& sym
->ts
.type
== BT_REAL
3550 && sym
->ts
.kind
== gfc_default_real_kind
3551 && !sym
->attr
.pointer
3552 && !sym
->attr
.allocatable
3553 && !sym
->attr
.always_explicit
)
3555 /* Special case: f2c calling conventions require that (scalar)
3556 default REAL functions return the C type double instead. f2c
3557 compatibility is only an issue with functions that don't
3558 require an explicit interface, as only these could be
3559 implemented in Fortran 77. */
3560 sym
->ts
.kind
= gfc_default_double_kind
;
3561 type
= gfc_typenode_for_spec (&sym
->ts
);
3562 sym
->ts
.kind
= gfc_default_real_kind
;
3564 else if (sym
->result
&& sym
->result
->attr
.proc_pointer
)
3565 /* Procedure pointer return values. */
3567 if (sym
->result
->attr
.result
&& strcmp (sym
->name
,"ppr@") != 0)
3569 /* Unset proc_pointer as gfc_get_function_type
3570 is called recursively. */
3571 sym
->result
->attr
.proc_pointer
= 0;
3572 type
= build_pointer_type (gfc_get_function_type (sym
->result
));
3573 sym
->result
->attr
.proc_pointer
= 1;
3576 type
= gfc_sym_type (sym
->result
);
3579 type
= gfc_sym_type (sym
);
3582 /* This should be represented as an unprototyped type, not a type
3583 with (...) prototype. */
3584 type
= build_function_type (type
, NULL_TREE
);
3586 type
= build_function_type_vec (type
, typelist
);
3588 /* If we were passed an fn spec, add it here, otherwise determine it from
3589 the formal arguments. */
3593 int spec_len
= strlen (fnspec
);
3594 tmp
= build_tree_list (NULL_TREE
, build_string (spec_len
, fnspec
));
3595 tmp
= tree_cons (get_identifier ("fn spec"), tmp
, TYPE_ATTRIBUTES (type
));
3596 type
= build_type_attribute_variant (type
, tmp
);
3599 type
= create_fn_spec (sym
, type
);
3604 /* Language hooks for middle-end access to type nodes. */
3606 /* Return an integer type with BITS bits of precision,
3607 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3610 gfc_type_for_size (unsigned bits
, int unsignedp
)
3615 for (i
= 0; i
<= MAX_INT_KINDS
; ++i
)
3617 tree type
= gfc_integer_types
[i
];
3618 if (type
&& bits
== TYPE_PRECISION (type
))
3622 /* Handle TImode as a special case because it is used by some backends
3623 (e.g. ARM) even though it is not available for normal use. */
3624 #if HOST_BITS_PER_WIDE_INT >= 64
3625 if (bits
== TYPE_PRECISION (intTI_type_node
))
3626 return intTI_type_node
;
3629 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3630 return intQI_type_node
;
3631 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3632 return intHI_type_node
;
3633 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3634 return intSI_type_node
;
3635 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3636 return intDI_type_node
;
3637 if (bits
<= TYPE_PRECISION (intTI_type_node
))
3638 return intTI_type_node
;
3642 if (bits
<= TYPE_PRECISION (unsigned_intQI_type_node
))
3643 return unsigned_intQI_type_node
;
3644 if (bits
<= TYPE_PRECISION (unsigned_intHI_type_node
))
3645 return unsigned_intHI_type_node
;
3646 if (bits
<= TYPE_PRECISION (unsigned_intSI_type_node
))
3647 return unsigned_intSI_type_node
;
3648 if (bits
<= TYPE_PRECISION (unsigned_intDI_type_node
))
3649 return unsigned_intDI_type_node
;
3650 if (bits
<= TYPE_PRECISION (unsigned_intTI_type_node
))
3651 return unsigned_intTI_type_node
;
3657 /* Return a data type that has machine mode MODE. If the mode is an
3658 integer, then UNSIGNEDP selects between signed and unsigned types. */
3661 gfc_type_for_mode (machine_mode mode
, int unsignedp
)
3665 scalar_int_mode int_mode
;
3667 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3668 base
= gfc_real_types
;
3669 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
3670 base
= gfc_complex_types
;
3671 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
3673 tree type
= gfc_type_for_size (GET_MODE_PRECISION (int_mode
), unsignedp
);
3674 return type
!= NULL_TREE
&& mode
== TYPE_MODE (type
) ? type
: NULL_TREE
;
3676 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_BOOL
3677 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
3679 unsigned int elem_bits
= vector_element_size (GET_MODE_PRECISION (mode
),
3680 GET_MODE_NUNITS (mode
));
3681 tree bool_type
= build_nonstandard_boolean_type (elem_bits
);
3682 return build_vector_type_for_mode (bool_type
, mode
);
3684 else if (VECTOR_MODE_P (mode
)
3685 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
3687 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3688 tree inner_type
= gfc_type_for_mode (inner_mode
, unsignedp
);
3689 if (inner_type
!= NULL_TREE
)
3690 return build_vector_type_for_mode (inner_type
, mode
);
3696 for (i
= 0; i
<= MAX_REAL_KINDS
; ++i
)
3698 tree type
= base
[i
];
3699 if (type
&& mode
== TYPE_MODE (type
))
3706 /* Return TRUE if TYPE is a type with a hidden descriptor, fill in INFO
3710 gfc_get_array_descr_info (const_tree type
, struct array_descr_info
*info
)
3713 bool indirect
= false;
3714 tree etype
, ptype
, t
, base_decl
;
3715 tree data_off
, span_off
, dim_off
, dtype_off
, dim_size
, elem_size
;
3716 tree lower_suboff
, upper_suboff
, stride_suboff
;
3717 tree dtype
, field
, rank_off
;
3719 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3721 if (! POINTER_TYPE_P (type
))
3723 type
= TREE_TYPE (type
);
3724 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3729 rank
= GFC_TYPE_ARRAY_RANK (type
);
3730 if (rank
>= (int) (ARRAY_SIZE (info
->dimen
)))
3733 etype
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
3734 gcc_assert (POINTER_TYPE_P (etype
));
3735 etype
= TREE_TYPE (etype
);
3737 /* If the type is not a scalar coarray. */
3738 if (TREE_CODE (etype
) == ARRAY_TYPE
)
3739 etype
= TREE_TYPE (etype
);
3741 /* Can't handle variable sized elements yet. */
3742 if (int_size_in_bytes (etype
) <= 0)
3744 /* Nor non-constant lower bounds in assumed shape arrays. */
3745 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3746 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3748 for (dim
= 0; dim
< rank
; dim
++)
3749 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
3750 || TREE_CODE (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) != INTEGER_CST
)
3754 memset (info
, '\0', sizeof (*info
));
3755 info
->ndimensions
= rank
;
3756 info
->ordering
= array_descr_ordering_column_major
;
3757 info
->element_type
= etype
;
3758 ptype
= build_pointer_type (gfc_array_index_type
);
3759 base_decl
= GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
);
3762 base_decl
= build_debug_expr_decl (indirect
3763 ? build_pointer_type (ptype
) : ptype
);
3764 GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
) = base_decl
;
3766 info
->base_decl
= base_decl
;
3768 base_decl
= build1 (INDIRECT_REF
, ptype
, base_decl
);
3770 gfc_get_descriptor_offsets_for_info (type
, &data_off
, &dtype_off
, &span_off
,
3771 &dim_off
, &dim_size
, &stride_suboff
,
3772 &lower_suboff
, &upper_suboff
);
3774 t
= fold_build_pointer_plus (base_decl
, span_off
);
3775 elem_size
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3778 if (!integer_zerop (data_off
))
3779 t
= fold_build_pointer_plus (t
, data_off
);
3780 t
= build1 (NOP_EXPR
, build_pointer_type (ptr_type_node
), t
);
3781 info
->data_location
= build1 (INDIRECT_REF
, ptr_type_node
, t
);
3782 enum gfc_array_kind akind
= GFC_TYPE_ARRAY_AKIND (type
);
3783 if (akind
== GFC_ARRAY_ALLOCATABLE
3784 || akind
== GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
)
3785 info
->allocated
= build2 (NE_EXPR
, logical_type_node
,
3786 info
->data_location
, null_pointer_node
);
3787 else if (akind
== GFC_ARRAY_POINTER
3788 || akind
== GFC_ARRAY_POINTER_CONT
3789 || akind
== GFC_ARRAY_ASSUMED_RANK_POINTER
3790 || akind
== GFC_ARRAY_ASSUMED_RANK_POINTER_CONT
)
3791 info
->associated
= build2 (NE_EXPR
, logical_type_node
,
3792 info
->data_location
, null_pointer_node
);
3793 if ((akind
== GFC_ARRAY_ASSUMED_RANK
3794 || akind
== GFC_ARRAY_ASSUMED_RANK_CONT
3795 || akind
== GFC_ARRAY_ASSUMED_RANK_ALLOCATABLE
3796 || akind
== GFC_ARRAY_ASSUMED_RANK_POINTER
3797 || akind
== GFC_ARRAY_ASSUMED_RANK_POINTER_CONT
)
3798 && dwarf_version
>= 5)
3801 info
->ndimensions
= 1;
3802 t
= fold_build_pointer_plus (base_decl
, dtype_off
);
3803 dtype
= TYPE_MAIN_VARIANT (get_dtype_type_node ());
3804 field
= gfc_advance_chain (TYPE_FIELDS (dtype
), GFC_DTYPE_RANK
);
3805 rank_off
= byte_position (field
);
3806 t
= fold_build_pointer_plus (t
, rank_off
);
3808 t
= build1 (NOP_EXPR
, build_pointer_type (TREE_TYPE (field
)), t
);
3809 t
= build1 (INDIRECT_REF
, TREE_TYPE (field
), t
);
3811 t
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (dim_off
));
3812 t
= size_binop (MULT_EXPR
, t
, dim_size
);
3813 dim_off
= build2 (PLUS_EXPR
, TREE_TYPE (dim_off
), t
, dim_off
);
3816 for (dim
= 0; dim
< rank
; dim
++)
3818 t
= fold_build_pointer_plus (base_decl
,
3819 size_binop (PLUS_EXPR
,
3820 dim_off
, lower_suboff
));
3821 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3822 info
->dimen
[dim
].lower_bound
= t
;
3823 t
= fold_build_pointer_plus (base_decl
,
3824 size_binop (PLUS_EXPR
,
3825 dim_off
, upper_suboff
));
3826 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3827 info
->dimen
[dim
].upper_bound
= t
;
3828 if (akind
== GFC_ARRAY_ASSUMED_SHAPE
3829 || akind
== GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3831 /* Assumed shape arrays have known lower bounds. */
3832 info
->dimen
[dim
].upper_bound
3833 = build2 (MINUS_EXPR
, gfc_array_index_type
,
3834 info
->dimen
[dim
].upper_bound
,
3835 info
->dimen
[dim
].lower_bound
);
3836 info
->dimen
[dim
].lower_bound
3837 = fold_convert (gfc_array_index_type
,
3838 GFC_TYPE_ARRAY_LBOUND (type
, dim
));
3839 info
->dimen
[dim
].upper_bound
3840 = build2 (PLUS_EXPR
, gfc_array_index_type
,
3841 info
->dimen
[dim
].lower_bound
,
3842 info
->dimen
[dim
].upper_bound
);
3844 t
= fold_build_pointer_plus (base_decl
,
3845 size_binop (PLUS_EXPR
,
3846 dim_off
, stride_suboff
));
3847 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3848 t
= build2 (MULT_EXPR
, gfc_array_index_type
, t
, elem_size
);
3849 info
->dimen
[dim
].stride
= t
;
3851 dim_off
= size_binop (PLUS_EXPR
, dim_off
, dim_size
);
3858 /* Create a type to handle vector subscripts for coarray library calls. It
3860 struct caf_vector_t {
3861 size_t nvec; // size of the vector
3868 ptrdiff_t lower_bound;
3869 ptrdiff_t upper_bound;
3874 where nvec == 0 for DIMEN_ELEMENT or DIMEN_RANGE and nvec being the vector
3875 size in case of DIMEN_VECTOR, where kind is the integer type of the vector. */
3878 gfc_get_caf_vector_type (int dim
)
3880 static tree vector_types
[GFC_MAX_DIMENSIONS
];
3881 static tree vec_type
= NULL_TREE
;
3882 tree triplet_struct_type
, vect_struct_type
, union_type
, tmp
, *chain
;
3884 if (vector_types
[dim
-1] != NULL_TREE
)
3885 return vector_types
[dim
-1];
3887 if (vec_type
== NULL_TREE
)
3890 vect_struct_type
= make_node (RECORD_TYPE
);
3891 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3892 get_identifier ("vector"),
3893 pvoid_type_node
, &chain
);
3894 suppress_warning (tmp
);
3895 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3896 get_identifier ("kind"),
3897 integer_type_node
, &chain
);
3898 suppress_warning (tmp
);
3899 gfc_finish_type (vect_struct_type
);
3902 triplet_struct_type
= make_node (RECORD_TYPE
);
3903 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3904 get_identifier ("lower_bound"),
3905 gfc_array_index_type
, &chain
);
3906 suppress_warning (tmp
);
3907 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3908 get_identifier ("upper_bound"),
3909 gfc_array_index_type
, &chain
);
3910 suppress_warning (tmp
);
3911 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
, get_identifier ("stride"),
3912 gfc_array_index_type
, &chain
);
3913 suppress_warning (tmp
);
3914 gfc_finish_type (triplet_struct_type
);
3917 union_type
= make_node (UNION_TYPE
);
3918 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3919 vect_struct_type
, &chain
);
3920 suppress_warning (tmp
);
3921 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("triplet"),
3922 triplet_struct_type
, &chain
);
3923 suppress_warning (tmp
);
3924 gfc_finish_type (union_type
);
3927 vec_type
= make_node (RECORD_TYPE
);
3928 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("nvec"),
3929 size_type_node
, &chain
);
3930 suppress_warning (tmp
);
3931 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("u"),
3932 union_type
, &chain
);
3933 suppress_warning (tmp
);
3934 gfc_finish_type (vec_type
);
3935 TYPE_NAME (vec_type
) = get_identifier ("caf_vector_t");
3938 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3939 gfc_rank_cst
[dim
-1]);
3940 vector_types
[dim
-1] = build_array_type (vec_type
, tmp
);
3941 return vector_types
[dim
-1];
3946 gfc_get_caf_reference_type ()
3948 static tree reference_type
= NULL_TREE
;
3949 tree c_struct_type
, s_struct_type
, v_struct_type
, union_type
, dim_union_type
,
3950 a_struct_type
, u_union_type
, tmp
, *chain
;
3952 if (reference_type
!= NULL_TREE
)
3953 return reference_type
;
3956 c_struct_type
= make_node (RECORD_TYPE
);
3957 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3958 get_identifier ("offset"),
3959 gfc_array_index_type
, &chain
);
3960 suppress_warning (tmp
);
3961 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3962 get_identifier ("caf_token_offset"),
3963 gfc_array_index_type
, &chain
);
3964 suppress_warning (tmp
);
3965 gfc_finish_type (c_struct_type
);
3968 s_struct_type
= make_node (RECORD_TYPE
);
3969 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3970 get_identifier ("start"),
3971 gfc_array_index_type
, &chain
);
3972 suppress_warning (tmp
);
3973 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3974 get_identifier ("end"),
3975 gfc_array_index_type
, &chain
);
3976 suppress_warning (tmp
);
3977 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3978 get_identifier ("stride"),
3979 gfc_array_index_type
, &chain
);
3980 suppress_warning (tmp
);
3981 gfc_finish_type (s_struct_type
);
3984 v_struct_type
= make_node (RECORD_TYPE
);
3985 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3986 get_identifier ("vector"),
3987 pvoid_type_node
, &chain
);
3988 suppress_warning (tmp
);
3989 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3990 get_identifier ("nvec"),
3991 size_type_node
, &chain
);
3992 suppress_warning (tmp
);
3993 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3994 get_identifier ("kind"),
3995 integer_type_node
, &chain
);
3996 suppress_warning (tmp
);
3997 gfc_finish_type (v_struct_type
);
4000 union_type
= make_node (UNION_TYPE
);
4001 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("s"),
4002 s_struct_type
, &chain
);
4003 suppress_warning (tmp
);
4004 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
4005 v_struct_type
, &chain
);
4006 suppress_warning (tmp
);
4007 gfc_finish_type (union_type
);
4009 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
4010 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1]);
4011 dim_union_type
= build_array_type (union_type
, tmp
);
4014 a_struct_type
= make_node (RECORD_TYPE
);
4015 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("mode"),
4016 build_array_type (unsigned_char_type_node
,
4017 build_range_type (gfc_array_index_type
,
4018 gfc_index_zero_node
,
4019 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1])),
4021 suppress_warning (tmp
);
4022 tmp
= gfc_add_field_to_struct_1 (a_struct_type
,
4023 get_identifier ("static_array_type"),
4024 integer_type_node
, &chain
);
4025 suppress_warning (tmp
);
4026 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("dim"),
4027 dim_union_type
, &chain
);
4028 suppress_warning (tmp
);
4029 gfc_finish_type (a_struct_type
);
4032 u_union_type
= make_node (UNION_TYPE
);
4033 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("c"),
4034 c_struct_type
, &chain
);
4035 suppress_warning (tmp
);
4036 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("a"),
4037 a_struct_type
, &chain
);
4038 suppress_warning (tmp
);
4039 gfc_finish_type (u_union_type
);
4042 reference_type
= make_node (RECORD_TYPE
);
4043 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("next"),
4044 build_pointer_type (reference_type
), &chain
);
4045 suppress_warning (tmp
);
4046 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("type"),
4047 integer_type_node
, &chain
);
4048 suppress_warning (tmp
);
4049 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("item_size"),
4050 size_type_node
, &chain
);
4051 suppress_warning (tmp
);
4052 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("u"),
4053 u_union_type
, &chain
);
4054 suppress_warning (tmp
);
4055 gfc_finish_type (reference_type
);
4056 TYPE_NAME (reference_type
) = get_identifier ("caf_reference_t");
4058 return reference_type
;
4062 gfc_get_cfi_dim_type ()
4064 static tree CFI_dim_t
= NULL
;
4069 CFI_dim_t
= make_node (RECORD_TYPE
);
4070 TYPE_NAME (CFI_dim_t
) = get_identifier ("CFI_dim_t");
4071 TYPE_NAMELESS (CFI_dim_t
) = 1;
4074 field
= gfc_add_field_to_struct_1 (CFI_dim_t
, get_identifier ("lower_bound"),
4075 gfc_array_index_type
, &chain
);
4076 suppress_warning (field
);
4077 field
= gfc_add_field_to_struct_1 (CFI_dim_t
, get_identifier ("extent"),
4078 gfc_array_index_type
, &chain
);
4079 suppress_warning (field
);
4080 field
= gfc_add_field_to_struct_1 (CFI_dim_t
, get_identifier ("sm"),
4081 gfc_array_index_type
, &chain
);
4082 suppress_warning (field
);
4083 gfc_finish_type (CFI_dim_t
);
4084 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (CFI_dim_t
)) = 1;
4089 /* Return the CFI type; use dimen == -1 for dim[] (only for pointers);
4090 otherwise dim[dimen] is used. */
4093 gfc_get_cfi_type (int dimen
, bool restricted
)
4095 gcc_assert (dimen
>= -1 && dimen
<= CFI_MAX_RANK
);
4097 int idx
= 2*(dimen
+ 1) + restricted
;
4099 if (gfc_cfi_descriptor_base
[idx
])
4100 return gfc_cfi_descriptor_base
[idx
];
4102 /* Build the type node. */
4103 tree CFI_cdesc_t
= make_node (RECORD_TYPE
);
4104 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
4106 sprintf (name
, "CFI_cdesc_t" GFC_RANK_PRINTF_FORMAT
, dimen
);
4107 TYPE_NAME (CFI_cdesc_t
) = get_identifier (dimen
< 0 ? "CFI_cdesc_t" : name
);
4108 TYPE_NAMELESS (CFI_cdesc_t
) = 1;
4112 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("base_addr"),
4113 (restricted
? prvoid_type_node
4114 : ptr_type_node
), &chain
);
4115 suppress_warning (field
);
4116 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("elem_len"),
4117 size_type_node
, &chain
);
4118 suppress_warning (field
);
4119 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("version"),
4120 integer_type_node
, &chain
);
4121 suppress_warning (field
);
4122 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("rank"),
4123 signed_char_type_node
, &chain
);
4124 suppress_warning (field
);
4125 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("attribute"),
4126 signed_char_type_node
, &chain
);
4127 suppress_warning (field
);
4128 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("type"),
4129 get_typenode_from_name (INT16_TYPE
),
4131 suppress_warning (field
);
4135 tree range
= NULL_TREE
;
4137 range
= gfc_rank_cst
[dimen
- 1];
4138 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
4140 tree CFI_dim_t
= build_array_type (gfc_get_cfi_dim_type (), range
);
4141 field
= gfc_add_field_to_struct_1 (CFI_cdesc_t
, get_identifier ("dim"),
4143 suppress_warning (field
);
4146 TYPE_TYPELESS_STORAGE (CFI_cdesc_t
) = 1;
4147 gfc_finish_type (CFI_cdesc_t
);
4148 gfc_cfi_descriptor_base
[idx
] = CFI_cdesc_t
;
4152 #include "gt-fortran-trans-types.h"