1 /* Backend support for Fortran 95 basic types and derived types.
2 Copyright (C) 2002-2017 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.c -- 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. */
43 #if (GFC_MAX_DIMENSIONS < 10)
44 #define GFC_RANK_DIGITS 1
45 #define GFC_RANK_PRINTF_FORMAT "%01d"
46 #elif (GFC_MAX_DIMENSIONS < 100)
47 #define GFC_RANK_DIGITS 2
48 #define GFC_RANK_PRINTF_FORMAT "%02d"
50 #error If you really need >99 dimensions, continue the sequence above...
53 /* array of structs so we don't have to worry about xmalloc or free */
54 CInteropKind_t c_interop_kinds_table
[ISOCBINDING_NUMBER
];
56 tree gfc_array_index_type
;
57 tree gfc_array_range_type
;
58 tree gfc_character1_type_node
;
60 tree prvoid_type_node
;
61 tree ppvoid_type_node
;
65 tree logical_type_node
;
66 tree logical_true_node
;
67 tree logical_false_node
;
68 tree gfc_charlen_type_node
;
70 tree gfc_float128_type_node
= NULL_TREE
;
71 tree gfc_complex_float128_type_node
= NULL_TREE
;
73 bool gfc_real16_is_float128
= false;
75 static GTY(()) tree gfc_desc_dim_type
;
76 static GTY(()) tree gfc_max_array_element_size
;
77 static GTY(()) tree gfc_array_descriptor_base
[2 * (GFC_MAX_DIMENSIONS
+1)];
78 static GTY(()) tree gfc_array_descriptor_base_caf
[2 * (GFC_MAX_DIMENSIONS
+1)];
80 /* Arrays for all integral and real kinds. We'll fill this in at runtime
81 after the target has a chance to process command-line options. */
83 #define MAX_INT_KINDS 5
84 gfc_integer_info gfc_integer_kinds
[MAX_INT_KINDS
+ 1];
85 gfc_logical_info gfc_logical_kinds
[MAX_INT_KINDS
+ 1];
86 static GTY(()) tree gfc_integer_types
[MAX_INT_KINDS
+ 1];
87 static GTY(()) tree gfc_logical_types
[MAX_INT_KINDS
+ 1];
89 #define MAX_REAL_KINDS 5
90 gfc_real_info gfc_real_kinds
[MAX_REAL_KINDS
+ 1];
91 static GTY(()) tree gfc_real_types
[MAX_REAL_KINDS
+ 1];
92 static GTY(()) tree gfc_complex_types
[MAX_REAL_KINDS
+ 1];
94 #define MAX_CHARACTER_KINDS 2
95 gfc_character_info gfc_character_kinds
[MAX_CHARACTER_KINDS
+ 1];
96 static GTY(()) tree gfc_character_types
[MAX_CHARACTER_KINDS
+ 1];
97 static GTY(()) tree gfc_pcharacter_types
[MAX_CHARACTER_KINDS
+ 1];
99 static tree
gfc_add_field_to_struct_1 (tree
, tree
, tree
, tree
**);
101 /* The integer kind to use for array indices. This will be set to the
102 proper value based on target information from the backend. */
104 int gfc_index_integer_kind
;
106 /* The default kinds of the various types. */
108 int gfc_default_integer_kind
;
109 int gfc_max_integer_kind
;
110 int gfc_default_real_kind
;
111 int gfc_default_double_kind
;
112 int gfc_default_character_kind
;
113 int gfc_default_logical_kind
;
114 int gfc_default_complex_kind
;
116 int gfc_atomic_int_kind
;
117 int gfc_atomic_logical_kind
;
119 /* The kind size used for record offsets. If the target system supports
120 kind=8, this will be set to 8, otherwise it is set to 4. */
123 /* The integer kind used to store character lengths. */
124 int gfc_charlen_int_kind
;
126 /* The size of the numeric storage unit and character storage unit. */
127 int gfc_numeric_storage_size
;
128 int gfc_character_storage_size
;
132 gfc_check_any_c_kind (gfc_typespec
*ts
)
136 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
138 /* Check for any C interoperable kind for the given type/kind in ts.
139 This can be used after verify_c_interop to make sure that the
140 Fortran kind being used exists in at least some form for C. */
141 if (c_interop_kinds_table
[i
].f90_type
== ts
->type
&&
142 c_interop_kinds_table
[i
].value
== ts
->kind
)
151 get_real_kind_from_node (tree type
)
155 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
156 if (gfc_real_kinds
[i
].mode_precision
== TYPE_PRECISION (type
))
157 return gfc_real_kinds
[i
].kind
;
163 get_int_kind_from_node (tree type
)
170 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
171 if (gfc_integer_kinds
[i
].bit_size
== TYPE_PRECISION (type
))
172 return gfc_integer_kinds
[i
].kind
;
177 /* Return a typenode for the "standard" C type with a given name. */
179 get_typenode_from_name (const char *name
)
181 if (name
== NULL
|| *name
== '\0')
184 if (strcmp (name
, "char") == 0)
185 return char_type_node
;
186 if (strcmp (name
, "unsigned char") == 0)
187 return unsigned_char_type_node
;
188 if (strcmp (name
, "signed char") == 0)
189 return signed_char_type_node
;
191 if (strcmp (name
, "short int") == 0)
192 return short_integer_type_node
;
193 if (strcmp (name
, "short unsigned int") == 0)
194 return short_unsigned_type_node
;
196 if (strcmp (name
, "int") == 0)
197 return integer_type_node
;
198 if (strcmp (name
, "unsigned int") == 0)
199 return unsigned_type_node
;
201 if (strcmp (name
, "long int") == 0)
202 return long_integer_type_node
;
203 if (strcmp (name
, "long unsigned int") == 0)
204 return long_unsigned_type_node
;
206 if (strcmp (name
, "long long int") == 0)
207 return long_long_integer_type_node
;
208 if (strcmp (name
, "long long unsigned int") == 0)
209 return long_long_unsigned_type_node
;
215 get_int_kind_from_name (const char *name
)
217 return get_int_kind_from_node (get_typenode_from_name (name
));
221 /* Get the kind number corresponding to an integer of given size,
222 following the required return values for ISO_FORTRAN_ENV INT* constants:
223 -2 is returned if we support a kind of larger size, -1 otherwise. */
225 gfc_get_int_kind_from_width_isofortranenv (int size
)
229 /* Look for a kind with matching storage size. */
230 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
231 if (gfc_integer_kinds
[i
].bit_size
== size
)
232 return gfc_integer_kinds
[i
].kind
;
234 /* Look for a kind with larger storage size. */
235 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
236 if (gfc_integer_kinds
[i
].bit_size
> size
)
243 /* Get the kind number corresponding to a real of a given storage size.
244 If two real's have the same storage size, then choose the real with
245 the largest precision. If a kind type is unavailable and a real
246 exists with wider storage, then return -2; otherwise, return -1. */
249 gfc_get_real_kind_from_width_isofortranenv (int size
)
258 /* Look for a kind with matching storage size. */
259 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
260 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) == size
)
262 if (gfc_real_kinds
[i
].digits
> digits
)
264 digits
= gfc_real_kinds
[i
].digits
;
265 kind
= gfc_real_kinds
[i
].kind
;
272 /* Look for a kind with larger storage size. */
273 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
274 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) > size
)
283 get_int_kind_from_width (int size
)
287 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
288 if (gfc_integer_kinds
[i
].bit_size
== size
)
289 return gfc_integer_kinds
[i
].kind
;
295 get_int_kind_from_minimal_width (int size
)
299 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
300 if (gfc_integer_kinds
[i
].bit_size
>= size
)
301 return gfc_integer_kinds
[i
].kind
;
307 /* Generate the CInteropKind_t objects for the C interoperable
311 gfc_init_c_interop_kinds (void)
315 /* init all pointers in the list to NULL */
316 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
318 /* Initialize the name and value fields. */
319 c_interop_kinds_table
[i
].name
[0] = '\0';
320 c_interop_kinds_table
[i
].value
= -100;
321 c_interop_kinds_table
[i
].f90_type
= BT_UNKNOWN
;
324 #define NAMED_INTCST(a,b,c,d) \
325 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
326 c_interop_kinds_table[a].f90_type = BT_INTEGER; \
327 c_interop_kinds_table[a].value = c;
328 #define NAMED_REALCST(a,b,c,d) \
329 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
330 c_interop_kinds_table[a].f90_type = BT_REAL; \
331 c_interop_kinds_table[a].value = c;
332 #define NAMED_CMPXCST(a,b,c,d) \
333 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
334 c_interop_kinds_table[a].f90_type = BT_COMPLEX; \
335 c_interop_kinds_table[a].value = c;
336 #define NAMED_LOGCST(a,b,c) \
337 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
338 c_interop_kinds_table[a].f90_type = BT_LOGICAL; \
339 c_interop_kinds_table[a].value = c;
340 #define NAMED_CHARKNDCST(a,b,c) \
341 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
342 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
343 c_interop_kinds_table[a].value = c;
344 #define NAMED_CHARCST(a,b,c) \
345 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
346 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
347 c_interop_kinds_table[a].value = c;
348 #define DERIVED_TYPE(a,b,c) \
349 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
350 c_interop_kinds_table[a].f90_type = BT_DERIVED; \
351 c_interop_kinds_table[a].value = c;
352 #define NAMED_FUNCTION(a,b,c,d) \
353 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
354 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
355 c_interop_kinds_table[a].value = c;
356 #define NAMED_SUBROUTINE(a,b,c,d) \
357 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
358 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
359 c_interop_kinds_table[a].value = c;
360 #include "iso-c-binding.def"
364 /* Query the target to determine which machine modes are available for
365 computation. Choose KIND numbers for them. */
368 gfc_init_kinds (void)
370 opt_scalar_int_mode int_mode_iter
;
371 opt_scalar_float_mode float_mode_iter
;
372 int i_index
, r_index
, kind
;
373 bool saw_i4
= false, saw_i8
= false;
374 bool saw_r4
= false, saw_r8
= false, saw_r10
= false, saw_r16
= false;
377 FOR_EACH_MODE_IN_CLASS (int_mode_iter
, MODE_INT
)
379 scalar_int_mode mode
= int_mode_iter
.require ();
382 if (!targetm
.scalar_mode_supported_p (mode
))
385 /* The middle end doesn't support constants larger than 2*HWI.
386 Perhaps the target hook shouldn't have accepted these either,
387 but just to be safe... */
388 bitsize
= GET_MODE_BITSIZE (mode
);
389 if (bitsize
> 2*HOST_BITS_PER_WIDE_INT
)
392 gcc_assert (i_index
!= MAX_INT_KINDS
);
394 /* Let the kind equal the bit size divided by 8. This insulates the
395 programmer from the underlying byte size. */
403 gfc_integer_kinds
[i_index
].kind
= kind
;
404 gfc_integer_kinds
[i_index
].radix
= 2;
405 gfc_integer_kinds
[i_index
].digits
= bitsize
- 1;
406 gfc_integer_kinds
[i_index
].bit_size
= bitsize
;
408 gfc_logical_kinds
[i_index
].kind
= kind
;
409 gfc_logical_kinds
[i_index
].bit_size
= bitsize
;
414 /* Set the kind used to match GFC_INT_IO in libgfortran. This is
415 used for large file access. */
422 /* If we do not at least have kind = 4, everything is pointless. */
425 /* Set the maximum integer kind. Used with at least BOZ constants. */
426 gfc_max_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
429 FOR_EACH_MODE_IN_CLASS (float_mode_iter
, MODE_FLOAT
)
431 scalar_float_mode mode
= float_mode_iter
.require ();
432 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
437 if (!targetm
.scalar_mode_supported_p (mode
))
440 /* Only let float, double, long double and __float128 go through.
441 Runtime support for others is not provided, so they would be
443 if (!targetm
.libgcc_floating_mode_supported_p (mode
))
445 if (mode
!= TYPE_MODE (float_type_node
)
446 && (mode
!= TYPE_MODE (double_type_node
))
447 && (mode
!= TYPE_MODE (long_double_type_node
))
448 #if defined(HAVE_TFmode) && defined(ENABLE_LIBQUADMATH_SUPPORT)
454 /* Let the kind equal the precision divided by 8, rounding up. Again,
455 this insulates the programmer from the underlying byte size.
457 Also, it effectively deals with IEEE extended formats. There, the
458 total size of the type may equal 16, but it's got 6 bytes of padding
459 and the increased size can get in the way of a real IEEE quad format
460 which may also be supported by the target.
462 We round up so as to handle IA-64 __floatreg (RFmode), which is an
463 82 bit type. Not to be confused with __float80 (XFmode), which is
464 an 80 bit type also supported by IA-64. So XFmode should come out
465 to be kind=10, and RFmode should come out to be kind=11. Egads. */
467 kind
= (GET_MODE_PRECISION (mode
) + 7) / 8;
478 /* Careful we don't stumble a weird internal mode. */
479 gcc_assert (r_index
<= 0 || gfc_real_kinds
[r_index
-1].kind
!= kind
);
480 /* Or have too many modes for the allocated space. */
481 gcc_assert (r_index
!= MAX_REAL_KINDS
);
483 gfc_real_kinds
[r_index
].kind
= kind
;
484 gfc_real_kinds
[r_index
].radix
= fmt
->b
;
485 gfc_real_kinds
[r_index
].digits
= fmt
->p
;
486 gfc_real_kinds
[r_index
].min_exponent
= fmt
->emin
;
487 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
;
488 if (fmt
->pnan
< fmt
->p
)
489 /* This is an IBM extended double format (or the MIPS variant)
490 made up of two IEEE doubles. The value of the long double is
491 the sum of the values of the two parts. The most significant
492 part is required to be the value of the long double rounded
493 to the nearest double. If we use emax of 1024 then we can't
494 represent huge(x) = (1 - b**(-p)) * b**(emax-1) * b, because
495 rounding will make the most significant part overflow. */
496 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
- 1;
497 gfc_real_kinds
[r_index
].mode_precision
= GET_MODE_PRECISION (mode
);
501 /* Choose the default integer kind. We choose 4 unless the user directs us
502 otherwise. Even if the user specified that the default integer kind is 8,
503 the numeric storage size is not 64 bits. In this case, a warning will be
504 issued when NUMERIC_STORAGE_SIZE is used. Set NUMERIC_STORAGE_SIZE to 32. */
506 gfc_numeric_storage_size
= 4 * 8;
508 if (flag_default_integer
)
511 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
512 "%<-fdefault-integer-8%> option");
514 gfc_default_integer_kind
= 8;
517 else if (flag_integer4_kind
== 8)
520 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
521 "%<-finteger-4-integer-8%> option");
523 gfc_default_integer_kind
= 8;
527 gfc_default_integer_kind
= 4;
531 gfc_default_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
532 gfc_numeric_storage_size
= gfc_integer_kinds
[i_index
- 1].bit_size
;
535 /* Choose the default real kind. Again, we choose 4 when possible. */
536 if (flag_default_real_8
)
539 gfc_fatal_error ("REAL(KIND=8) is not available for "
540 "%<-fdefault-real-8%> option");
542 gfc_default_real_kind
= 8;
544 else if (flag_default_real_10
)
547 gfc_fatal_error ("REAL(KIND=10) is not available for "
548 "%<-fdefault-real-10%> option");
550 gfc_default_real_kind
= 10;
552 else if (flag_default_real_16
)
555 gfc_fatal_error ("REAL(KIND=16) is not available for "
556 "%<-fdefault-real-16%> option");
558 gfc_default_real_kind
= 16;
560 else if (flag_real4_kind
== 8)
563 gfc_fatal_error ("REAL(KIND=8) is not available for %<-freal-4-real-8%> "
566 gfc_default_real_kind
= 8;
568 else if (flag_real4_kind
== 10)
571 gfc_fatal_error ("REAL(KIND=10) is not available for "
572 "%<-freal-4-real-10%> option");
574 gfc_default_real_kind
= 10;
576 else if (flag_real4_kind
== 16)
579 gfc_fatal_error ("REAL(KIND=16) is not available for "
580 "%<-freal-4-real-16%> option");
582 gfc_default_real_kind
= 16;
585 gfc_default_real_kind
= 4;
587 gfc_default_real_kind
= gfc_real_kinds
[0].kind
;
589 /* Choose the default double kind. If -fdefault-real and -fdefault-double
590 are specified, we use kind=8, if it's available. If -fdefault-real is
591 specified without -fdefault-double, we use kind=16, if it's available.
592 Otherwise we do not change anything. */
593 if (flag_default_double
&& saw_r8
)
594 gfc_default_double_kind
= 8;
595 else if (flag_default_real_8
|| flag_default_real_10
|| flag_default_real_16
)
597 /* Use largest available kind. */
599 gfc_default_double_kind
= 16;
601 gfc_default_double_kind
= 10;
603 gfc_default_double_kind
= 8;
605 gfc_default_double_kind
= gfc_default_real_kind
;
607 else if (flag_real8_kind
== 4)
610 gfc_fatal_error ("REAL(KIND=4) is not available for "
611 "%<-freal-8-real-4%> option");
613 gfc_default_double_kind
= 4;
615 else if (flag_real8_kind
== 10 )
618 gfc_fatal_error ("REAL(KIND=10) is not available for "
619 "%<-freal-8-real-10%> option");
621 gfc_default_double_kind
= 10;
623 else if (flag_real8_kind
== 16 )
626 gfc_fatal_error ("REAL(KIND=10) is not available for "
627 "%<-freal-8-real-16%> option");
629 gfc_default_double_kind
= 16;
631 else if (saw_r4
&& saw_r8
)
632 gfc_default_double_kind
= 8;
635 /* F95 14.6.3.1: A nonpointer scalar object of type double precision
636 real ... occupies two contiguous numeric storage units.
638 Therefore we must be supplied a kind twice as large as we chose
639 for single precision. There are loopholes, in that double
640 precision must *occupy* two storage units, though it doesn't have
641 to *use* two storage units. Which means that you can make this
642 kind artificially wide by padding it. But at present there are
643 no GCC targets for which a two-word type does not exist, so we
644 just let gfc_validate_kind abort and tell us if something breaks. */
646 gfc_default_double_kind
647 = gfc_validate_kind (BT_REAL
, gfc_default_real_kind
* 2, false);
650 /* The default logical kind is constrained to be the same as the
651 default integer kind. Similarly with complex and real. */
652 gfc_default_logical_kind
= gfc_default_integer_kind
;
653 gfc_default_complex_kind
= gfc_default_real_kind
;
655 /* We only have two character kinds: ASCII and UCS-4.
656 ASCII corresponds to a 8-bit integer type, if one is available.
657 UCS-4 corresponds to a 32-bit integer type, if one is available. */
659 if ((kind
= get_int_kind_from_width (8)) > 0)
661 gfc_character_kinds
[i_index
].kind
= kind
;
662 gfc_character_kinds
[i_index
].bit_size
= 8;
663 gfc_character_kinds
[i_index
].name
= "ascii";
666 if ((kind
= get_int_kind_from_width (32)) > 0)
668 gfc_character_kinds
[i_index
].kind
= kind
;
669 gfc_character_kinds
[i_index
].bit_size
= 32;
670 gfc_character_kinds
[i_index
].name
= "iso_10646";
674 /* Choose the smallest integer kind for our default character. */
675 gfc_default_character_kind
= gfc_character_kinds
[0].kind
;
676 gfc_character_storage_size
= gfc_default_character_kind
* 8;
678 gfc_index_integer_kind
= get_int_kind_from_name (PTRDIFF_TYPE
);
680 /* Pick a kind the same size as the C "int" type. */
681 gfc_c_int_kind
= INT_TYPE_SIZE
/ 8;
683 /* Choose atomic kinds to match C's int. */
684 gfc_atomic_int_kind
= gfc_c_int_kind
;
685 gfc_atomic_logical_kind
= gfc_c_int_kind
;
689 /* Make sure that a valid kind is present. Returns an index into the
690 associated kinds array, -1 if the kind is not present. */
693 validate_integer (int kind
)
697 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
698 if (gfc_integer_kinds
[i
].kind
== kind
)
705 validate_real (int kind
)
709 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
710 if (gfc_real_kinds
[i
].kind
== kind
)
717 validate_logical (int kind
)
721 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
722 if (gfc_logical_kinds
[i
].kind
== kind
)
729 validate_character (int kind
)
733 for (i
= 0; gfc_character_kinds
[i
].kind
; i
++)
734 if (gfc_character_kinds
[i
].kind
== kind
)
740 /* Validate a kind given a basic type. The return value is the same
741 for the child functions, with -1 indicating nonexistence of the
742 type. If MAY_FAIL is false, then -1 is never returned, and we ICE. */
745 gfc_validate_kind (bt type
, int kind
, bool may_fail
)
751 case BT_REAL
: /* Fall through */
753 rc
= validate_real (kind
);
756 rc
= validate_integer (kind
);
759 rc
= validate_logical (kind
);
762 rc
= validate_character (kind
);
766 gfc_internal_error ("gfc_validate_kind(): Got bad type");
769 if (rc
< 0 && !may_fail
)
770 gfc_internal_error ("gfc_validate_kind(): Got bad kind");
776 /* Four subroutines of gfc_init_types. Create type nodes for the given kind.
777 Reuse common type nodes where possible. Recognize if the kind matches up
778 with a C type. This will be used later in determining which routines may
779 be scarfed from libm. */
782 gfc_build_int_type (gfc_integer_info
*info
)
784 int mode_precision
= info
->bit_size
;
786 if (mode_precision
== CHAR_TYPE_SIZE
)
788 if (mode_precision
== SHORT_TYPE_SIZE
)
790 if (mode_precision
== INT_TYPE_SIZE
)
792 if (mode_precision
== LONG_TYPE_SIZE
)
794 if (mode_precision
== LONG_LONG_TYPE_SIZE
)
795 info
->c_long_long
= 1;
797 if (TYPE_PRECISION (intQI_type_node
) == mode_precision
)
798 return intQI_type_node
;
799 if (TYPE_PRECISION (intHI_type_node
) == mode_precision
)
800 return intHI_type_node
;
801 if (TYPE_PRECISION (intSI_type_node
) == mode_precision
)
802 return intSI_type_node
;
803 if (TYPE_PRECISION (intDI_type_node
) == mode_precision
)
804 return intDI_type_node
;
805 if (TYPE_PRECISION (intTI_type_node
) == mode_precision
)
806 return intTI_type_node
;
808 return make_signed_type (mode_precision
);
812 gfc_build_uint_type (int size
)
814 if (size
== CHAR_TYPE_SIZE
)
815 return unsigned_char_type_node
;
816 if (size
== SHORT_TYPE_SIZE
)
817 return short_unsigned_type_node
;
818 if (size
== INT_TYPE_SIZE
)
819 return unsigned_type_node
;
820 if (size
== LONG_TYPE_SIZE
)
821 return long_unsigned_type_node
;
822 if (size
== LONG_LONG_TYPE_SIZE
)
823 return long_long_unsigned_type_node
;
825 return make_unsigned_type (size
);
830 gfc_build_real_type (gfc_real_info
*info
)
832 int mode_precision
= info
->mode_precision
;
835 if (mode_precision
== FLOAT_TYPE_SIZE
)
837 if (mode_precision
== DOUBLE_TYPE_SIZE
)
839 if (mode_precision
== LONG_DOUBLE_TYPE_SIZE
)
840 info
->c_long_double
= 1;
841 if (mode_precision
!= LONG_DOUBLE_TYPE_SIZE
&& mode_precision
== 128)
843 info
->c_float128
= 1;
844 gfc_real16_is_float128
= true;
847 if (TYPE_PRECISION (float_type_node
) == mode_precision
)
848 return float_type_node
;
849 if (TYPE_PRECISION (double_type_node
) == mode_precision
)
850 return double_type_node
;
851 if (TYPE_PRECISION (long_double_type_node
) == mode_precision
)
852 return long_double_type_node
;
854 new_type
= make_node (REAL_TYPE
);
855 TYPE_PRECISION (new_type
) = mode_precision
;
856 layout_type (new_type
);
861 gfc_build_complex_type (tree scalar_type
)
865 if (scalar_type
== NULL
)
867 if (scalar_type
== float_type_node
)
868 return complex_float_type_node
;
869 if (scalar_type
== double_type_node
)
870 return complex_double_type_node
;
871 if (scalar_type
== long_double_type_node
)
872 return complex_long_double_type_node
;
874 new_type
= make_node (COMPLEX_TYPE
);
875 TREE_TYPE (new_type
) = scalar_type
;
876 layout_type (new_type
);
881 gfc_build_logical_type (gfc_logical_info
*info
)
883 int bit_size
= info
->bit_size
;
886 if (bit_size
== BOOL_TYPE_SIZE
)
889 return boolean_type_node
;
892 new_type
= make_unsigned_type (bit_size
);
893 TREE_SET_CODE (new_type
, BOOLEAN_TYPE
);
894 TYPE_MAX_VALUE (new_type
) = build_int_cst (new_type
, 1);
895 TYPE_PRECISION (new_type
) = 1;
901 /* Create the backend type nodes. We map them to their
902 equivalent C type, at least for now. We also give
903 names to the types here, and we push them in the
904 global binding level context.*/
907 gfc_init_types (void)
914 /* Create and name the types. */
915 #define PUSH_TYPE(name, node) \
916 pushdecl (build_decl (input_location, \
917 TYPE_DECL, get_identifier (name), node))
919 for (index
= 0; gfc_integer_kinds
[index
].kind
!= 0; ++index
)
921 type
= gfc_build_int_type (&gfc_integer_kinds
[index
]);
922 /* Ensure integer(kind=1) doesn't have TYPE_STRING_FLAG set. */
923 if (TYPE_STRING_FLAG (type
))
924 type
= make_signed_type (gfc_integer_kinds
[index
].bit_size
);
925 gfc_integer_types
[index
] = type
;
926 snprintf (name_buf
, sizeof(name_buf
), "integer(kind=%d)",
927 gfc_integer_kinds
[index
].kind
);
928 PUSH_TYPE (name_buf
, type
);
931 for (index
= 0; gfc_logical_kinds
[index
].kind
!= 0; ++index
)
933 type
= gfc_build_logical_type (&gfc_logical_kinds
[index
]);
934 gfc_logical_types
[index
] = type
;
935 snprintf (name_buf
, sizeof(name_buf
), "logical(kind=%d)",
936 gfc_logical_kinds
[index
].kind
);
937 PUSH_TYPE (name_buf
, type
);
940 for (index
= 0; gfc_real_kinds
[index
].kind
!= 0; index
++)
942 type
= gfc_build_real_type (&gfc_real_kinds
[index
]);
943 gfc_real_types
[index
] = type
;
944 snprintf (name_buf
, sizeof(name_buf
), "real(kind=%d)",
945 gfc_real_kinds
[index
].kind
);
946 PUSH_TYPE (name_buf
, type
);
948 if (gfc_real_kinds
[index
].c_float128
)
949 gfc_float128_type_node
= type
;
951 type
= gfc_build_complex_type (type
);
952 gfc_complex_types
[index
] = type
;
953 snprintf (name_buf
, sizeof(name_buf
), "complex(kind=%d)",
954 gfc_real_kinds
[index
].kind
);
955 PUSH_TYPE (name_buf
, type
);
957 if (gfc_real_kinds
[index
].c_float128
)
958 gfc_complex_float128_type_node
= type
;
961 for (index
= 0; gfc_character_kinds
[index
].kind
!= 0; ++index
)
963 type
= gfc_build_uint_type (gfc_character_kinds
[index
].bit_size
);
964 type
= build_qualified_type (type
, TYPE_UNQUALIFIED
);
965 snprintf (name_buf
, sizeof(name_buf
), "character(kind=%d)",
966 gfc_character_kinds
[index
].kind
);
967 PUSH_TYPE (name_buf
, type
);
968 gfc_character_types
[index
] = type
;
969 gfc_pcharacter_types
[index
] = build_pointer_type (type
);
971 gfc_character1_type_node
= gfc_character_types
[0];
973 PUSH_TYPE ("byte", unsigned_char_type_node
);
974 PUSH_TYPE ("void", void_type_node
);
976 /* DBX debugging output gets upset if these aren't set. */
977 if (!TYPE_NAME (integer_type_node
))
978 PUSH_TYPE ("c_integer", integer_type_node
);
979 if (!TYPE_NAME (char_type_node
))
980 PUSH_TYPE ("c_char", char_type_node
);
984 pvoid_type_node
= build_pointer_type (void_type_node
);
985 prvoid_type_node
= build_qualified_type (pvoid_type_node
, TYPE_QUAL_RESTRICT
);
986 ppvoid_type_node
= build_pointer_type (pvoid_type_node
);
987 pchar_type_node
= build_pointer_type (gfc_character1_type_node
);
989 = build_pointer_type (build_function_type_list (void_type_node
, NULL_TREE
));
991 gfc_array_index_type
= gfc_get_int_type (gfc_index_integer_kind
);
992 /* We cannot use gfc_index_zero_node in definition of gfc_array_range_type,
993 since this function is called before gfc_init_constants. */
995 = build_range_type (gfc_array_index_type
,
996 build_int_cst (gfc_array_index_type
, 0),
999 /* The maximum array element size that can be handled is determined
1000 by the number of bits available to store this field in the array
1003 n
= TYPE_PRECISION (gfc_array_index_type
) - GFC_DTYPE_SIZE_SHIFT
;
1004 gfc_max_array_element_size
1005 = wide_int_to_tree (size_type_node
,
1006 wi::mask (n
, UNSIGNED
,
1007 TYPE_PRECISION (size_type_node
)));
1010 logical_type_node
= gfc_get_logical_type (gfc_default_logical_kind
);
1011 logical_true_node
= build_int_cst (logical_type_node
, 1);
1012 logical_false_node
= build_int_cst (logical_type_node
, 0);
1014 /* ??? Shouldn't this be based on gfc_index_integer_kind or so? */
1015 gfc_charlen_int_kind
= 4;
1016 gfc_charlen_type_node
= gfc_get_int_type (gfc_charlen_int_kind
);
1019 /* Get the type node for the given type and kind. */
1022 gfc_get_int_type (int kind
)
1024 int index
= gfc_validate_kind (BT_INTEGER
, kind
, true);
1025 return index
< 0 ? 0 : gfc_integer_types
[index
];
1029 gfc_get_real_type (int kind
)
1031 int index
= gfc_validate_kind (BT_REAL
, kind
, true);
1032 return index
< 0 ? 0 : gfc_real_types
[index
];
1036 gfc_get_complex_type (int kind
)
1038 int index
= gfc_validate_kind (BT_COMPLEX
, kind
, true);
1039 return index
< 0 ? 0 : gfc_complex_types
[index
];
1043 gfc_get_logical_type (int kind
)
1045 int index
= gfc_validate_kind (BT_LOGICAL
, kind
, true);
1046 return index
< 0 ? 0 : gfc_logical_types
[index
];
1050 gfc_get_char_type (int kind
)
1052 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1053 return index
< 0 ? 0 : gfc_character_types
[index
];
1057 gfc_get_pchar_type (int kind
)
1059 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1060 return index
< 0 ? 0 : gfc_pcharacter_types
[index
];
1064 /* Create a character type with the given kind and length. */
1067 gfc_get_character_type_len_for_eltype (tree eltype
, tree len
)
1071 bounds
= build_range_type (gfc_charlen_type_node
, gfc_index_one_node
, len
);
1072 type
= build_array_type (eltype
, bounds
);
1073 TYPE_STRING_FLAG (type
) = 1;
1079 gfc_get_character_type_len (int kind
, tree len
)
1081 gfc_validate_kind (BT_CHARACTER
, kind
, false);
1082 return gfc_get_character_type_len_for_eltype (gfc_get_char_type (kind
), len
);
1086 /* Get a type node for a character kind. */
1089 gfc_get_character_type (int kind
, gfc_charlen
* cl
)
1093 len
= (cl
== NULL
) ? NULL_TREE
: cl
->backend_decl
;
1094 if (len
&& POINTER_TYPE_P (TREE_TYPE (len
)))
1095 len
= build_fold_indirect_ref (len
);
1097 return gfc_get_character_type_len (kind
, len
);
1100 /* Convert a basic type. This will be an array for character types. */
1103 gfc_typenode_for_spec (gfc_typespec
* spec
, int codim
)
1113 /* We use INTEGER(c_intptr_t) for C_PTR and C_FUNPTR once the symbol
1114 has been resolved. This is done so we can convert C_PTR and
1115 C_FUNPTR to simple variables that get translated to (void *). */
1116 if (spec
->f90_type
== BT_VOID
)
1119 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1120 basetype
= ptr_type_node
;
1122 basetype
= pfunc_type_node
;
1125 basetype
= gfc_get_int_type (spec
->kind
);
1129 basetype
= gfc_get_real_type (spec
->kind
);
1133 basetype
= gfc_get_complex_type (spec
->kind
);
1137 basetype
= gfc_get_logical_type (spec
->kind
);
1141 basetype
= gfc_get_character_type (spec
->kind
, spec
->u
.cl
);
1145 /* Since this cannot be used, return a length one character. */
1146 basetype
= gfc_get_character_type_len (gfc_default_character_kind
,
1147 gfc_index_one_node
);
1151 basetype
= gfc_get_union_type (spec
->u
.derived
);
1156 basetype
= gfc_get_derived_type (spec
->u
.derived
, codim
);
1158 if (spec
->type
== BT_CLASS
)
1159 GFC_CLASS_TYPE_P (basetype
) = 1;
1161 /* If we're dealing with either C_PTR or C_FUNPTR, we modified the
1162 type and kind to fit a (void *) and the basetype returned was a
1163 ptr_type_node. We need to pass up this new information to the
1164 symbol that was declared of type C_PTR or C_FUNPTR. */
1165 if (spec
->u
.derived
->ts
.f90_type
== BT_VOID
)
1167 spec
->type
= BT_INTEGER
;
1168 spec
->kind
= gfc_index_integer_kind
;
1169 spec
->f90_type
= BT_VOID
;
1174 /* This is for the second arg to c_f_pointer and c_f_procpointer
1175 of the iso_c_binding module, to accept any ptr type. */
1176 basetype
= ptr_type_node
;
1177 if (spec
->f90_type
== BT_VOID
)
1180 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1181 basetype
= ptr_type_node
;
1183 basetype
= pfunc_type_node
;
1192 /* Build an INT_CST for constant expressions, otherwise return NULL_TREE. */
1195 gfc_conv_array_bound (gfc_expr
* expr
)
1197 /* If expr is an integer constant, return that. */
1198 if (expr
!= NULL
&& expr
->expr_type
== EXPR_CONSTANT
)
1199 return gfc_conv_mpz_to_tree (expr
->value
.integer
, gfc_index_integer_kind
);
1201 /* Otherwise return NULL. */
1205 /* Return the type of an element of the array. Note that scalar coarrays
1206 are special. In particular, for GFC_ARRAY_TYPE_P, the original argument
1207 (with POINTER_TYPE stripped) is returned. */
1210 gfc_get_element_type (tree type
)
1214 if (GFC_ARRAY_TYPE_P (type
))
1216 if (TREE_CODE (type
) == POINTER_TYPE
)
1217 type
= TREE_TYPE (type
);
1218 if (GFC_TYPE_ARRAY_RANK (type
) == 0)
1220 gcc_assert (GFC_TYPE_ARRAY_CORANK (type
) > 0);
1225 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
1226 element
= TREE_TYPE (type
);
1231 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
));
1232 element
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
1234 gcc_assert (TREE_CODE (element
) == POINTER_TYPE
);
1235 element
= TREE_TYPE (element
);
1237 /* For arrays, which are not scalar coarrays. */
1238 if (TREE_CODE (element
) == ARRAY_TYPE
&& !TYPE_STRING_FLAG (element
))
1239 element
= TREE_TYPE (element
);
1245 /* Build an array. This function is called from gfc_sym_type().
1246 Actually returns array descriptor type.
1248 Format of array descriptors is as follows:
1250 struct gfc_array_descriptor
1255 struct descriptor_dimension dimension[N_DIM];
1258 struct descriptor_dimension
1265 Translation code should use gfc_conv_descriptor_* rather than
1266 accessing the descriptor directly. Any changes to the array
1267 descriptor type will require changes in gfc_conv_descriptor_* and
1268 gfc_build_array_initializer.
1270 This is represented internally as a RECORD_TYPE. The index nodes
1271 are gfc_array_index_type and the data node is a pointer to the
1272 data. See below for the handling of character types.
1274 The dtype member is formatted as follows:
1275 rank = dtype & GFC_DTYPE_RANK_MASK // 3 bits
1276 type = (dtype & GFC_DTYPE_TYPE_MASK) >> GFC_DTYPE_TYPE_SHIFT // 3 bits
1277 size = dtype >> GFC_DTYPE_SIZE_SHIFT
1279 I originally used nested ARRAY_TYPE nodes to represent arrays, but
1280 this generated poor code for assumed/deferred size arrays. These
1281 require use of PLACEHOLDER_EXPR/WITH_RECORD_EXPR, which isn't part
1282 of the GENERIC grammar. Also, there is no way to explicitly set
1283 the array stride, so all data must be packed(1). I've tried to
1284 mark all the functions which would require modification with a GCC
1287 The data component points to the first element in the array. The
1288 offset field is the position of the origin of the array (i.e. element
1289 (0, 0 ...)). This may be outside the bounds of the array.
1291 An element is accessed by
1292 data[offset + index0*stride0 + index1*stride1 + index2*stride2]
1293 This gives good performance as the computation does not involve the
1294 bounds of the array. For packed arrays, this is optimized further
1295 by substituting the known strides.
1297 This system has one problem: all array bounds must be within 2^31
1298 elements of the origin (2^63 on 64-bit machines). For example
1299 integer, dimension (80000:90000, 80000:90000, 2) :: array
1300 may not work properly on 32-bit machines because 80000*80000 >
1301 2^31, so the calculation for stride2 would overflow. This may
1302 still work, but I haven't checked, and it relies on the overflow
1303 doing the right thing.
1305 The way to fix this problem is to access elements as follows:
1306 data[(index0-lbound0)*stride0 + (index1-lbound1)*stride1]
1307 Obviously this is much slower. I will make this a compile time
1308 option, something like -fsmall-array-offsets. Mixing code compiled
1309 with and without this switch will work.
1311 (1) This can be worked around by modifying the upper bound of the
1312 previous dimension. This requires extra fields in the descriptor
1313 (both real_ubound and fake_ubound). */
1316 /* Returns true if the array sym does not require a descriptor. */
1319 gfc_is_nodesc_array (gfc_symbol
* sym
)
1321 symbol_attribute
*array_attr
;
1323 bool is_classarray
= IS_CLASS_ARRAY (sym
);
1325 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
1326 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
1328 gcc_assert (array_attr
->dimension
|| array_attr
->codimension
);
1330 /* We only want local arrays. */
1331 if ((sym
->ts
.type
!= BT_CLASS
&& sym
->attr
.pointer
)
1332 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->attr
.class_pointer
)
1333 || array_attr
->allocatable
)
1336 /* We want a descriptor for associate-name arrays that do not have an
1337 explicitly known shape already. */
1338 if (sym
->assoc
&& as
->type
!= AS_EXPLICIT
)
1341 /* The dummy is stored in sym and not in the component. */
1342 if (sym
->attr
.dummy
)
1343 return as
->type
!= AS_ASSUMED_SHAPE
1344 && as
->type
!= AS_ASSUMED_RANK
;
1346 if (sym
->attr
.result
|| sym
->attr
.function
)
1349 gcc_assert (as
->type
== AS_EXPLICIT
|| as
->cp_was_assumed
);
1355 /* Create an array descriptor type. */
1358 gfc_build_array_type (tree type
, gfc_array_spec
* as
,
1359 enum gfc_array_kind akind
, bool restricted
,
1360 bool contiguous
, int codim
)
1362 tree lbound
[GFC_MAX_DIMENSIONS
];
1363 tree ubound
[GFC_MAX_DIMENSIONS
];
1366 /* Assumed-shape arrays do not have codimension information stored in the
1368 corank
= MAX (as
->corank
, codim
);
1369 if (as
->type
== AS_ASSUMED_SHAPE
||
1370 (as
->type
== AS_ASSUMED_RANK
&& akind
== GFC_ARRAY_ALLOCATABLE
))
1373 if (as
->type
== AS_ASSUMED_RANK
)
1374 for (n
= 0; n
< GFC_MAX_DIMENSIONS
; n
++)
1376 lbound
[n
] = NULL_TREE
;
1377 ubound
[n
] = NULL_TREE
;
1380 for (n
= 0; n
< as
->rank
; n
++)
1382 /* Create expressions for the known bounds of the array. */
1383 if (as
->type
== AS_ASSUMED_SHAPE
&& as
->lower
[n
] == NULL
)
1384 lbound
[n
] = gfc_index_one_node
;
1386 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1387 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1390 for (n
= as
->rank
; n
< as
->rank
+ corank
; n
++)
1392 if (as
->type
!= AS_DEFERRED
&& as
->lower
[n
] == NULL
)
1393 lbound
[n
] = gfc_index_one_node
;
1395 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1397 if (n
< as
->rank
+ corank
- 1)
1398 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1401 if (as
->type
== AS_ASSUMED_SHAPE
)
1402 akind
= contiguous
? GFC_ARRAY_ASSUMED_SHAPE_CONT
1403 : GFC_ARRAY_ASSUMED_SHAPE
;
1404 else if (as
->type
== AS_ASSUMED_RANK
)
1405 akind
= contiguous
? GFC_ARRAY_ASSUMED_RANK_CONT
1406 : GFC_ARRAY_ASSUMED_RANK
;
1407 return gfc_get_array_type_bounds (type
, as
->rank
== -1
1408 ? GFC_MAX_DIMENSIONS
: as
->rank
,
1409 corank
, lbound
, ubound
, 0, akind
,
1413 /* Returns the struct descriptor_dimension type. */
1416 gfc_get_desc_dim_type (void)
1419 tree decl
, *chain
= NULL
;
1421 if (gfc_desc_dim_type
)
1422 return gfc_desc_dim_type
;
1424 /* Build the type node. */
1425 type
= make_node (RECORD_TYPE
);
1427 TYPE_NAME (type
) = get_identifier ("descriptor_dimension");
1428 TYPE_PACKED (type
) = 1;
1430 /* Consists of the stride, lbound and ubound members. */
1431 decl
= gfc_add_field_to_struct_1 (type
,
1432 get_identifier ("stride"),
1433 gfc_array_index_type
, &chain
);
1434 TREE_NO_WARNING (decl
) = 1;
1436 decl
= gfc_add_field_to_struct_1 (type
,
1437 get_identifier ("lbound"),
1438 gfc_array_index_type
, &chain
);
1439 TREE_NO_WARNING (decl
) = 1;
1441 decl
= gfc_add_field_to_struct_1 (type
,
1442 get_identifier ("ubound"),
1443 gfc_array_index_type
, &chain
);
1444 TREE_NO_WARNING (decl
) = 1;
1446 /* Finish off the type. */
1447 gfc_finish_type (type
);
1448 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
1450 gfc_desc_dim_type
= type
;
1455 /* Return the DTYPE for an array. This describes the type and type parameters
1457 /* TODO: Only call this when the value is actually used, and make all the
1458 unknown cases abort. */
1461 gfc_get_dtype_rank_type (int rank
, tree etype
)
1469 switch (TREE_CODE (etype
))
1487 /* We will never have arrays of arrays. */
1501 /* TODO: Don't do dtype for temporary descriptorless arrays. */
1502 /* We can strange array types for temporary arrays. */
1503 return gfc_index_zero_node
;
1506 gcc_assert (rank
<= GFC_DTYPE_RANK_MASK
);
1507 size
= TYPE_SIZE_UNIT (etype
);
1509 i
= rank
| (n
<< GFC_DTYPE_TYPE_SHIFT
);
1510 if (size
&& INTEGER_CST_P (size
))
1512 if (tree_int_cst_lt (gfc_max_array_element_size
, size
))
1513 gfc_fatal_error ("Array element size too big at %C");
1515 i
+= TREE_INT_CST_LOW (size
) << GFC_DTYPE_SIZE_SHIFT
;
1517 dtype
= build_int_cst (gfc_array_index_type
, i
);
1519 if (size
&& !INTEGER_CST_P (size
))
1521 tmp
= build_int_cst (gfc_array_index_type
, GFC_DTYPE_SIZE_SHIFT
);
1522 tmp
= fold_build2_loc (input_location
, LSHIFT_EXPR
,
1523 gfc_array_index_type
,
1524 fold_convert (gfc_array_index_type
, size
), tmp
);
1525 dtype
= fold_build2_loc (input_location
, PLUS_EXPR
, gfc_array_index_type
,
1528 /* If we don't know the size we leave it as zero. This should never happen
1529 for anything that is actually used. */
1530 /* TODO: Check this is actually true, particularly when repacking
1531 assumed size parameters. */
1538 gfc_get_dtype (tree type
)
1544 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
) || GFC_ARRAY_TYPE_P (type
));
1546 if (GFC_TYPE_ARRAY_DTYPE (type
))
1547 return GFC_TYPE_ARRAY_DTYPE (type
);
1549 rank
= GFC_TYPE_ARRAY_RANK (type
);
1550 etype
= gfc_get_element_type (type
);
1551 dtype
= gfc_get_dtype_rank_type (rank
, etype
);
1553 GFC_TYPE_ARRAY_DTYPE (type
) = dtype
;
1558 /* Build an array type for use without a descriptor, packed according
1559 to the value of PACKED. */
1562 gfc_get_nodesc_array_type (tree etype
, gfc_array_spec
* as
, gfc_packed packed
,
1576 mpz_init_set_ui (offset
, 0);
1577 mpz_init_set_ui (stride
, 1);
1580 /* We don't use build_array_type because this does not include include
1581 lang-specific information (i.e. the bounds of the array) when checking
1584 type
= make_node (ARRAY_TYPE
);
1586 type
= build_variant_type_copy (etype
);
1588 GFC_ARRAY_TYPE_P (type
) = 1;
1589 TYPE_LANG_SPECIFIC (type
) = ggc_cleared_alloc
<struct lang_type
> ();
1591 known_stride
= (packed
!= PACKED_NO
);
1593 for (n
= 0; n
< as
->rank
; n
++)
1595 /* Fill in the stride and bound components of the type. */
1597 tmp
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1600 GFC_TYPE_ARRAY_STRIDE (type
, n
) = tmp
;
1602 expr
= as
->lower
[n
];
1603 if (expr
->expr_type
== EXPR_CONSTANT
)
1605 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1606 gfc_index_integer_kind
);
1613 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1617 /* Calculate the offset. */
1618 mpz_mul (delta
, stride
, as
->lower
[n
]->value
.integer
);
1619 mpz_sub (offset
, offset
, delta
);
1624 expr
= as
->upper
[n
];
1625 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1627 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1628 gfc_index_integer_kind
);
1635 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1639 /* Calculate the stride. */
1640 mpz_sub (delta
, as
->upper
[n
]->value
.integer
,
1641 as
->lower
[n
]->value
.integer
);
1642 mpz_add_ui (delta
, delta
, 1);
1643 mpz_mul (stride
, stride
, delta
);
1646 /* Only the first stride is known for partial packed arrays. */
1647 if (packed
== PACKED_NO
|| packed
== PACKED_PARTIAL
)
1650 for (n
= as
->rank
; n
< as
->rank
+ as
->corank
; n
++)
1652 expr
= as
->lower
[n
];
1653 if (expr
->expr_type
== EXPR_CONSTANT
)
1654 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1655 gfc_index_integer_kind
);
1658 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1660 expr
= as
->upper
[n
];
1661 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1662 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1663 gfc_index_integer_kind
);
1666 if (n
< as
->rank
+ as
->corank
- 1)
1667 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1672 GFC_TYPE_ARRAY_OFFSET (type
) =
1673 gfc_conv_mpz_to_tree (offset
, gfc_index_integer_kind
);
1676 GFC_TYPE_ARRAY_OFFSET (type
) = NULL_TREE
;
1680 GFC_TYPE_ARRAY_SIZE (type
) =
1681 gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1684 GFC_TYPE_ARRAY_SIZE (type
) = NULL_TREE
;
1686 GFC_TYPE_ARRAY_RANK (type
) = as
->rank
;
1687 GFC_TYPE_ARRAY_CORANK (type
) = as
->corank
;
1688 GFC_TYPE_ARRAY_DTYPE (type
) = NULL_TREE
;
1689 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
1691 /* TODO: use main type if it is unbounded. */
1692 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1693 build_pointer_type (build_array_type (etype
, range
));
1695 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1696 build_qualified_type (GFC_TYPE_ARRAY_DATAPTR_TYPE (type
),
1697 TYPE_QUAL_RESTRICT
);
1701 if (packed
!= PACKED_STATIC
|| flag_coarray
== GFC_FCOARRAY_LIB
)
1703 type
= build_pointer_type (type
);
1706 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
1708 GFC_ARRAY_TYPE_P (type
) = 1;
1709 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
1717 mpz_sub_ui (stride
, stride
, 1);
1718 range
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1723 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
, range
);
1724 TYPE_DOMAIN (type
) = range
;
1726 build_pointer_type (etype
);
1727 TREE_TYPE (type
) = etype
;
1735 /* Represent packed arrays as multi-dimensional if they have rank >
1736 1 and with proper bounds, instead of flat arrays. This makes for
1737 better debug info. */
1740 tree gtype
= etype
, rtype
, type_decl
;
1742 for (n
= as
->rank
- 1; n
>= 0; n
--)
1744 rtype
= build_range_type (gfc_array_index_type
,
1745 GFC_TYPE_ARRAY_LBOUND (type
, n
),
1746 GFC_TYPE_ARRAY_UBOUND (type
, n
));
1747 gtype
= build_array_type (gtype
, rtype
);
1749 TYPE_NAME (type
) = type_decl
= build_decl (input_location
,
1750 TYPE_DECL
, NULL
, gtype
);
1751 DECL_ORIGINAL_TYPE (type_decl
) = gtype
;
1754 if (packed
!= PACKED_STATIC
|| !known_stride
1755 || (as
->corank
&& flag_coarray
== GFC_FCOARRAY_LIB
))
1757 /* For dummy arrays and automatic (heap allocated) arrays we
1758 want a pointer to the array. */
1759 type
= build_pointer_type (type
);
1761 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
1762 GFC_ARRAY_TYPE_P (type
) = 1;
1763 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
1769 /* Return or create the base type for an array descriptor. */
1772 gfc_get_array_descriptor_base (int dimen
, int codimen
, bool restricted
)
1774 tree fat_type
, decl
, arraytype
, *chain
= NULL
;
1775 char name
[16 + 2*GFC_RANK_DIGITS
+ 1 + 1];
1778 /* Assumed-rank array. */
1780 dimen
= GFC_MAX_DIMENSIONS
;
1782 idx
= 2 * (codimen
+ dimen
) + restricted
;
1784 gcc_assert (codimen
+ dimen
>= 0 && codimen
+ dimen
<= GFC_MAX_DIMENSIONS
);
1786 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1788 if (gfc_array_descriptor_base_caf
[idx
])
1789 return gfc_array_descriptor_base_caf
[idx
];
1791 else if (gfc_array_descriptor_base
[idx
])
1792 return gfc_array_descriptor_base
[idx
];
1794 /* Build the type node. */
1795 fat_type
= make_node (RECORD_TYPE
);
1797 sprintf (name
, "array_descriptor" GFC_RANK_PRINTF_FORMAT
, dimen
+ codimen
);
1798 TYPE_NAME (fat_type
) = get_identifier (name
);
1799 TYPE_NAMELESS (fat_type
) = 1;
1801 /* Add the data member as the first element of the descriptor. */
1802 decl
= gfc_add_field_to_struct_1 (fat_type
,
1803 get_identifier ("data"),
1806 : ptr_type_node
), &chain
);
1808 /* Add the base component. */
1809 decl
= gfc_add_field_to_struct_1 (fat_type
,
1810 get_identifier ("offset"),
1811 gfc_array_index_type
, &chain
);
1812 TREE_NO_WARNING (decl
) = 1;
1814 /* Add the dtype component. */
1815 decl
= gfc_add_field_to_struct_1 (fat_type
,
1816 get_identifier ("dtype"),
1817 gfc_array_index_type
, &chain
);
1818 TREE_NO_WARNING (decl
) = 1;
1820 /* Add the span component. */
1821 decl
= gfc_add_field_to_struct_1 (fat_type
,
1822 get_identifier ("span"),
1823 gfc_array_index_type
, &chain
);
1824 TREE_NO_WARNING (decl
) = 1;
1826 /* Build the array type for the stride and bound components. */
1827 if (dimen
+ codimen
> 0)
1830 build_array_type (gfc_get_desc_dim_type (),
1831 build_range_type (gfc_array_index_type
,
1832 gfc_index_zero_node
,
1833 gfc_rank_cst
[codimen
+ dimen
- 1]));
1835 decl
= gfc_add_field_to_struct_1 (fat_type
, get_identifier ("dim"),
1837 TREE_NO_WARNING (decl
) = 1;
1840 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1842 decl
= gfc_add_field_to_struct_1 (fat_type
,
1843 get_identifier ("token"),
1844 prvoid_type_node
, &chain
);
1845 TREE_NO_WARNING (decl
) = 1;
1848 /* Finish off the type. */
1849 gfc_finish_type (fat_type
);
1850 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (fat_type
)) = 1;
1852 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1853 gfc_array_descriptor_base_caf
[idx
] = fat_type
;
1855 gfc_array_descriptor_base
[idx
] = fat_type
;
1861 /* Build an array (descriptor) type with given bounds. */
1864 gfc_get_array_type_bounds (tree etype
, int dimen
, int codimen
, tree
* lbound
,
1865 tree
* ubound
, int packed
,
1866 enum gfc_array_kind akind
, bool restricted
)
1868 char name
[8 + 2*GFC_RANK_DIGITS
+ 1 + GFC_MAX_SYMBOL_LEN
];
1869 tree fat_type
, base_type
, arraytype
, lower
, upper
, stride
, tmp
, rtype
;
1870 const char *type_name
;
1873 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, restricted
);
1874 fat_type
= build_distinct_type_copy (base_type
);
1875 /* Make sure that nontarget and target array type have the same canonical
1876 type (and same stub decl for debug info). */
1877 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, false);
1878 TYPE_CANONICAL (fat_type
) = base_type
;
1879 TYPE_STUB_DECL (fat_type
) = TYPE_STUB_DECL (base_type
);
1881 tmp
= TYPE_NAME (etype
);
1882 if (tmp
&& TREE_CODE (tmp
) == TYPE_DECL
)
1883 tmp
= DECL_NAME (tmp
);
1885 type_name
= IDENTIFIER_POINTER (tmp
);
1887 type_name
= "unknown";
1888 sprintf (name
, "array" GFC_RANK_PRINTF_FORMAT
"_%.*s", dimen
+ codimen
,
1889 GFC_MAX_SYMBOL_LEN
, type_name
);
1890 TYPE_NAME (fat_type
) = get_identifier (name
);
1891 TYPE_NAMELESS (fat_type
) = 1;
1893 GFC_DESCRIPTOR_TYPE_P (fat_type
) = 1;
1894 TYPE_LANG_SPECIFIC (fat_type
) = ggc_cleared_alloc
<struct lang_type
> ();
1896 GFC_TYPE_ARRAY_RANK (fat_type
) = dimen
;
1897 GFC_TYPE_ARRAY_CORANK (fat_type
) = codimen
;
1898 GFC_TYPE_ARRAY_DTYPE (fat_type
) = NULL_TREE
;
1899 GFC_TYPE_ARRAY_AKIND (fat_type
) = akind
;
1901 /* Build an array descriptor record type. */
1903 stride
= gfc_index_one_node
;
1906 for (n
= 0; n
< dimen
+ codimen
; n
++)
1909 GFC_TYPE_ARRAY_STRIDE (fat_type
, n
) = stride
;
1916 if (lower
!= NULL_TREE
)
1918 if (INTEGER_CST_P (lower
))
1919 GFC_TYPE_ARRAY_LBOUND (fat_type
, n
) = lower
;
1924 if (codimen
&& n
== dimen
+ codimen
- 1)
1928 if (upper
!= NULL_TREE
)
1930 if (INTEGER_CST_P (upper
))
1931 GFC_TYPE_ARRAY_UBOUND (fat_type
, n
) = upper
;
1939 if (upper
!= NULL_TREE
&& lower
!= NULL_TREE
&& stride
!= NULL_TREE
)
1941 tmp
= fold_build2_loc (input_location
, MINUS_EXPR
,
1942 gfc_array_index_type
, upper
, lower
);
1943 tmp
= fold_build2_loc (input_location
, PLUS_EXPR
,
1944 gfc_array_index_type
, tmp
,
1945 gfc_index_one_node
);
1946 stride
= fold_build2_loc (input_location
, MULT_EXPR
,
1947 gfc_array_index_type
, tmp
, stride
);
1948 /* Check the folding worked. */
1949 gcc_assert (INTEGER_CST_P (stride
));
1954 GFC_TYPE_ARRAY_SIZE (fat_type
) = stride
;
1956 /* TODO: known offsets for descriptors. */
1957 GFC_TYPE_ARRAY_OFFSET (fat_type
) = NULL_TREE
;
1961 arraytype
= build_pointer_type (etype
);
1963 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
1965 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
1969 /* We define data as an array with the correct size if possible.
1970 Much better than doing pointer arithmetic. */
1972 rtype
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
1973 int_const_binop (MINUS_EXPR
, stride
,
1974 build_int_cst (TREE_TYPE (stride
), 1)));
1976 rtype
= gfc_array_range_type
;
1977 arraytype
= build_array_type (etype
, rtype
);
1978 arraytype
= build_pointer_type (arraytype
);
1980 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
1981 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
1983 /* This will generate the base declarations we need to emit debug
1984 information for this type. FIXME: there must be a better way to
1985 avoid divergence between compilations with and without debug
1988 struct array_descr_info info
;
1989 gfc_get_array_descr_info (fat_type
, &info
);
1990 gfc_get_array_descr_info (build_pointer_type (fat_type
), &info
);
1996 /* Build a pointer type. This function is called from gfc_sym_type(). */
1999 gfc_build_pointer_type (gfc_symbol
* sym
, tree type
)
2001 /* Array pointer types aren't actually pointers. */
2002 if (sym
->attr
.dimension
)
2005 return build_pointer_type (type
);
2008 static tree
gfc_nonrestricted_type (tree t
);
2009 /* Given two record or union type nodes TO and FROM, ensure
2010 that all fields in FROM have a corresponding field in TO,
2011 their type being nonrestrict variants. This accepts a TO
2012 node that already has a prefix of the fields in FROM. */
2014 mirror_fields (tree to
, tree from
)
2019 /* Forward to the end of TOs fields. */
2020 fto
= TYPE_FIELDS (to
);
2021 ffrom
= TYPE_FIELDS (from
);
2022 chain
= &TYPE_FIELDS (to
);
2025 gcc_assert (ffrom
&& DECL_NAME (fto
) == DECL_NAME (ffrom
));
2026 chain
= &DECL_CHAIN (fto
);
2027 fto
= DECL_CHAIN (fto
);
2028 ffrom
= DECL_CHAIN (ffrom
);
2031 /* Now add all fields remaining in FROM (starting with ffrom). */
2032 for (; ffrom
; ffrom
= DECL_CHAIN (ffrom
))
2034 tree newfield
= copy_node (ffrom
);
2035 DECL_CONTEXT (newfield
) = to
;
2036 /* The store to DECL_CHAIN might seem redundant with the
2037 stores to *chain, but not clearing it here would mean
2038 leaving a chain into the old fields. If ever
2039 our called functions would look at them confusion
2041 DECL_CHAIN (newfield
) = NULL_TREE
;
2043 chain
= &DECL_CHAIN (newfield
);
2045 if (TREE_CODE (ffrom
) == FIELD_DECL
)
2047 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (ffrom
));
2048 TREE_TYPE (newfield
) = elemtype
;
2054 /* Given a type T, returns a different type of the same structure,
2055 except that all types it refers to (recursively) are always
2056 non-restrict qualified types. */
2058 gfc_nonrestricted_type (tree t
)
2062 /* If the type isn't laid out yet, don't copy it. If something
2063 needs it for real it should wait until the type got finished. */
2067 if (!TYPE_LANG_SPECIFIC (t
))
2068 TYPE_LANG_SPECIFIC (t
) = ggc_cleared_alloc
<struct lang_type
> ();
2069 /* If we're dealing with this very node already further up
2070 the call chain (recursion via pointers and struct members)
2071 we haven't yet determined if we really need a new type node.
2072 Assume we don't, return T itself. */
2073 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
== error_mark_node
)
2076 /* If we have calculated this all already, just return it. */
2077 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
)
2078 return TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
;
2080 /* Mark this type. */
2081 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= error_mark_node
;
2083 switch (TREE_CODE (t
))
2089 case REFERENCE_TYPE
:
2091 tree totype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2092 if (totype
== TREE_TYPE (t
))
2094 else if (TREE_CODE (t
) == POINTER_TYPE
)
2095 ret
= build_pointer_type (totype
);
2097 ret
= build_reference_type (totype
);
2098 ret
= build_qualified_type (ret
,
2099 TYPE_QUALS (t
) & ~TYPE_QUAL_RESTRICT
);
2105 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2106 if (elemtype
== TREE_TYPE (t
))
2110 ret
= build_variant_type_copy (t
);
2111 TREE_TYPE (ret
) = elemtype
;
2112 if (TYPE_LANG_SPECIFIC (t
)
2113 && GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2115 tree dataptr_type
= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
);
2116 dataptr_type
= gfc_nonrestricted_type (dataptr_type
);
2117 if (dataptr_type
!= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2119 TYPE_LANG_SPECIFIC (ret
)
2120 = ggc_cleared_alloc
<struct lang_type
> ();
2121 *TYPE_LANG_SPECIFIC (ret
) = *TYPE_LANG_SPECIFIC (t
);
2122 GFC_TYPE_ARRAY_DATAPTR_TYPE (ret
) = dataptr_type
;
2131 case QUAL_UNION_TYPE
:
2134 /* First determine if we need a new type at all.
2135 Careful, the two calls to gfc_nonrestricted_type per field
2136 might return different values. That happens exactly when
2137 one of the fields reaches back to this very record type
2138 (via pointers). The first calls will assume that we don't
2139 need to copy T (see the error_mark_node marking). If there
2140 are any reasons for copying T apart from having to copy T,
2141 we'll indeed copy it, and the second calls to
2142 gfc_nonrestricted_type will use that new node if they
2144 for (field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
2145 if (TREE_CODE (field
) == FIELD_DECL
)
2147 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (field
));
2148 if (elemtype
!= TREE_TYPE (field
))
2153 ret
= build_variant_type_copy (t
);
2154 TYPE_FIELDS (ret
) = NULL_TREE
;
2156 /* Here we make sure that as soon as we know we have to copy
2157 T, that also fields reaching back to us will use the new
2158 copy. It's okay if that copy still contains the old fields,
2159 we won't look at them. */
2160 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2161 mirror_fields (ret
, t
);
2166 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2171 /* Return the type for a symbol. Special handling is required for character
2172 types to get the correct level of indirection.
2173 For functions return the return type.
2174 For subroutines return void_type_node.
2175 Calling this multiple times for the same symbol should be avoided,
2176 especially for character and array types. */
2179 gfc_sym_type (gfc_symbol
* sym
)
2185 /* Procedure Pointers inside COMMON blocks. */
2186 if (sym
->attr
.proc_pointer
&& sym
->attr
.in_common
)
2188 /* Unset proc_pointer as gfc_get_function_type calls gfc_sym_type. */
2189 sym
->attr
.proc_pointer
= 0;
2190 type
= build_pointer_type (gfc_get_function_type (sym
));
2191 sym
->attr
.proc_pointer
= 1;
2195 if (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
2196 return void_type_node
;
2198 /* In the case of a function the fake result variable may have a
2199 type different from the function type, so don't return early in
2201 if (sym
->backend_decl
&& !sym
->attr
.function
)
2202 return TREE_TYPE (sym
->backend_decl
);
2204 if (sym
->ts
.type
== BT_CHARACTER
2205 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
)
2206 || (sym
->attr
.result
2207 && sym
->ns
->proc_name
2208 && sym
->ns
->proc_name
->attr
.is_bind_c
)
2209 || (sym
->ts
.deferred
&& (!sym
->ts
.u
.cl
2210 || !sym
->ts
.u
.cl
->backend_decl
))))
2211 type
= gfc_character1_type_node
;
2213 type
= gfc_typenode_for_spec (&sym
->ts
, sym
->attr
.codimension
);
2215 if (sym
->attr
.dummy
&& !sym
->attr
.function
&& !sym
->attr
.value
)
2220 restricted
= !sym
->attr
.target
&& !sym
->attr
.pointer
2221 && !sym
->attr
.proc_pointer
&& !sym
->attr
.cray_pointee
;
2223 type
= gfc_nonrestricted_type (type
);
2225 if (sym
->attr
.dimension
|| sym
->attr
.codimension
)
2227 if (gfc_is_nodesc_array (sym
))
2229 /* If this is a character argument of unknown length, just use the
2231 if (sym
->ts
.type
!= BT_CHARACTER
2232 || !(sym
->attr
.dummy
|| sym
->attr
.function
)
2233 || sym
->ts
.u
.cl
->backend_decl
)
2235 type
= gfc_get_nodesc_array_type (type
, sym
->as
,
2244 enum gfc_array_kind akind
= GFC_ARRAY_UNKNOWN
;
2245 if (sym
->attr
.pointer
)
2246 akind
= sym
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2247 : GFC_ARRAY_POINTER
;
2248 else if (sym
->attr
.allocatable
)
2249 akind
= GFC_ARRAY_ALLOCATABLE
;
2250 type
= gfc_build_array_type (type
, sym
->as
, akind
, restricted
,
2251 sym
->attr
.contiguous
, false);
2256 if (sym
->attr
.allocatable
|| sym
->attr
.pointer
2257 || gfc_is_associate_pointer (sym
))
2258 type
= gfc_build_pointer_type (sym
, type
);
2261 /* We currently pass all parameters by reference.
2262 See f95_get_function_decl. For dummy function parameters return the
2266 /* We must use pointer types for potentially absent variables. The
2267 optimizers assume a reference type argument is never NULL. */
2268 if (sym
->attr
.optional
2269 || (sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.entry_master
))
2270 type
= build_pointer_type (type
);
2273 type
= build_reference_type (type
);
2275 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
2282 /* Layout and output debug info for a record type. */
2285 gfc_finish_type (tree type
)
2289 decl
= build_decl (input_location
,
2290 TYPE_DECL
, NULL_TREE
, type
);
2291 TYPE_STUB_DECL (type
) = decl
;
2293 rest_of_type_compilation (type
, 1);
2294 rest_of_decl_compilation (decl
, 1, 0);
2297 /* Add a field of given NAME and TYPE to the context of a UNION_TYPE
2298 or RECORD_TYPE pointed to by CONTEXT. The new field is chained
2299 to the end of the field list pointed to by *CHAIN.
2301 Returns a pointer to the new field. */
2304 gfc_add_field_to_struct_1 (tree context
, tree name
, tree type
, tree
**chain
)
2306 tree decl
= build_decl (input_location
, FIELD_DECL
, name
, type
);
2308 DECL_CONTEXT (decl
) = context
;
2309 DECL_CHAIN (decl
) = NULL_TREE
;
2310 if (TYPE_FIELDS (context
) == NULL_TREE
)
2311 TYPE_FIELDS (context
) = decl
;
2316 *chain
= &DECL_CHAIN (decl
);
2322 /* Like `gfc_add_field_to_struct_1', but adds alignment
2326 gfc_add_field_to_struct (tree context
, tree name
, tree type
, tree
**chain
)
2328 tree decl
= gfc_add_field_to_struct_1 (context
, name
, type
, chain
);
2330 DECL_INITIAL (decl
) = 0;
2331 SET_DECL_ALIGN (decl
, 0);
2332 DECL_USER_ALIGN (decl
) = 0;
2338 /* Copy the backend_decl and component backend_decls if
2339 the two derived type symbols are "equal", as described
2340 in 4.4.2 and resolved by gfc_compare_derived_types. */
2343 gfc_copy_dt_decls_ifequal (gfc_symbol
*from
, gfc_symbol
*to
,
2346 gfc_component
*to_cm
;
2347 gfc_component
*from_cm
;
2352 if (from
->backend_decl
== NULL
2353 || !gfc_compare_derived_types (from
, to
))
2356 to
->backend_decl
= from
->backend_decl
;
2358 to_cm
= to
->components
;
2359 from_cm
= from
->components
;
2361 /* Copy the component declarations. If a component is itself
2362 a derived type, we need a copy of its component declarations.
2363 This is done by recursing into gfc_get_derived_type and
2364 ensures that the component's component declarations have
2365 been built. If it is a character, we need the character
2367 for (; to_cm
; to_cm
= to_cm
->next
, from_cm
= from_cm
->next
)
2369 to_cm
->backend_decl
= from_cm
->backend_decl
;
2370 if (from_cm
->ts
.type
== BT_UNION
)
2371 gfc_get_union_type (to_cm
->ts
.u
.derived
);
2372 else if (from_cm
->ts
.type
== BT_DERIVED
2373 && (!from_cm
->attr
.pointer
|| from_gsym
))
2374 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2375 else if (from_cm
->ts
.type
== BT_CLASS
2376 && (!CLASS_DATA (from_cm
)->attr
.class_pointer
|| from_gsym
))
2377 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2378 else if (from_cm
->ts
.type
== BT_CHARACTER
)
2379 to_cm
->ts
.u
.cl
->backend_decl
= from_cm
->ts
.u
.cl
->backend_decl
;
2386 /* Build a tree node for a procedure pointer component. */
2389 gfc_get_ppc_type (gfc_component
* c
)
2393 /* Explicit interface. */
2394 if (c
->attr
.if_source
!= IFSRC_UNKNOWN
&& c
->ts
.interface
)
2395 return build_pointer_type (gfc_get_function_type (c
->ts
.interface
));
2397 /* Implicit interface (only return value may be known). */
2398 if (c
->attr
.function
&& !c
->attr
.dimension
&& c
->ts
.type
!= BT_CHARACTER
)
2399 t
= gfc_typenode_for_spec (&c
->ts
);
2403 return build_pointer_type (build_function_type_list (t
, NULL_TREE
));
2407 /* Build a tree node for a union type. Requires building each map
2408 structure which is an element of the union. */
2411 gfc_get_union_type (gfc_symbol
*un
)
2413 gfc_component
*map
= NULL
;
2414 tree typenode
= NULL
, map_type
= NULL
, map_field
= NULL
;
2417 if (un
->backend_decl
)
2419 if (TYPE_FIELDS (un
->backend_decl
) || un
->attr
.proc_pointer_comp
)
2420 return un
->backend_decl
;
2422 typenode
= un
->backend_decl
;
2426 typenode
= make_node (UNION_TYPE
);
2427 TYPE_NAME (typenode
) = get_identifier (un
->name
);
2430 /* Add each contained MAP as a field. */
2431 for (map
= un
->components
; map
; map
= map
->next
)
2433 gcc_assert (map
->ts
.type
== BT_DERIVED
);
2435 /* The map's type node, which is defined within this union's context. */
2436 map_type
= gfc_get_derived_type (map
->ts
.u
.derived
);
2437 TYPE_CONTEXT (map_type
) = typenode
;
2439 /* The map field's declaration. */
2440 map_field
= gfc_add_field_to_struct(typenode
, get_identifier(map
->name
),
2443 gfc_set_decl_location (map_field
, &map
->loc
);
2444 else if (un
->declared_at
.lb
)
2445 gfc_set_decl_location (map_field
, &un
->declared_at
);
2447 DECL_PACKED (map_field
) |= TYPE_PACKED (typenode
);
2448 DECL_NAMELESS(map_field
) = true;
2450 /* We should never clobber another backend declaration for this map,
2451 because each map component is unique. */
2452 if (!map
->backend_decl
)
2453 map
->backend_decl
= map_field
;
2456 un
->backend_decl
= typenode
;
2457 gfc_finish_type (typenode
);
2463 /* Build a tree node for a derived type. If there are equal
2464 derived types, with different local names, these are built
2465 at the same time. If an equal derived type has been built
2466 in a parent namespace, this is used. */
2469 gfc_get_derived_type (gfc_symbol
* derived
, int codimen
)
2471 tree typenode
= NULL
, field
= NULL
, field_type
= NULL
;
2472 tree canonical
= NULL_TREE
;
2474 bool got_canonical
= false;
2475 bool unlimited_entity
= false;
2481 gcc_assert (!derived
->attr
.pdt_template
);
2483 if (derived
->attr
.unlimited_polymorphic
2484 || (flag_coarray
== GFC_FCOARRAY_LIB
2485 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2486 && (derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
2487 || derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)))
2488 return ptr_type_node
;
2490 if (flag_coarray
!= GFC_FCOARRAY_LIB
2491 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2492 && derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2493 return gfc_get_int_type (gfc_default_integer_kind
);
2495 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
2496 && derived
->attr
.generic
)
2497 derived
= gfc_find_dt_in_generic (derived
);
2499 /* See if it's one of the iso_c_binding derived types. */
2500 if (derived
->attr
.is_iso_c
== 1 || derived
->ts
.f90_type
== BT_VOID
)
2502 if (derived
->backend_decl
)
2503 return derived
->backend_decl
;
2505 if (derived
->intmod_sym_id
== ISOCBINDING_PTR
)
2506 derived
->backend_decl
= ptr_type_node
;
2508 derived
->backend_decl
= pfunc_type_node
;
2510 derived
->ts
.kind
= gfc_index_integer_kind
;
2511 derived
->ts
.type
= BT_INTEGER
;
2512 /* Set the f90_type to BT_VOID as a way to recognize something of type
2513 BT_INTEGER that needs to fit a void * for the purpose of the
2514 iso_c_binding derived types. */
2515 derived
->ts
.f90_type
= BT_VOID
;
2517 return derived
->backend_decl
;
2520 /* If use associated, use the module type for this one. */
2521 if (derived
->backend_decl
== NULL
2522 && derived
->attr
.use_assoc
2524 && gfc_get_module_backend_decl (derived
))
2525 goto copy_derived_types
;
2527 /* The derived types from an earlier namespace can be used as the
2529 if (derived
->backend_decl
== NULL
&& !derived
->attr
.use_assoc
2530 && gfc_global_ns_list
)
2532 for (ns
= gfc_global_ns_list
;
2533 ns
->translated
&& !got_canonical
;
2536 dt
= ns
->derived_types
;
2537 for (; dt
&& !canonical
; dt
= dt
->next
)
2539 gfc_copy_dt_decls_ifequal (dt
->derived
, derived
, true);
2540 if (derived
->backend_decl
)
2541 got_canonical
= true;
2546 /* Store up the canonical type to be added to this one. */
2549 if (TYPE_CANONICAL (derived
->backend_decl
))
2550 canonical
= TYPE_CANONICAL (derived
->backend_decl
);
2552 canonical
= derived
->backend_decl
;
2554 derived
->backend_decl
= NULL_TREE
;
2557 /* derived->backend_decl != 0 means we saw it before, but its
2558 components' backend_decl may have not been built. */
2559 if (derived
->backend_decl
)
2561 /* Its components' backend_decl have been built or we are
2562 seeing recursion through the formal arglist of a procedure
2563 pointer component. */
2564 if (TYPE_FIELDS (derived
->backend_decl
))
2565 return derived
->backend_decl
;
2566 else if (derived
->attr
.abstract
2567 && derived
->attr
.proc_pointer_comp
)
2569 /* If an abstract derived type with procedure pointer
2570 components has no other type of component, return the
2571 backend_decl. Otherwise build the components if any of the
2572 non-procedure pointer components have no backend_decl. */
2573 for (c
= derived
->components
; c
; c
= c
->next
)
2575 bool same_alloc_type
= c
->attr
.allocatable
2576 && derived
== c
->ts
.u
.derived
;
2577 if (!c
->attr
.proc_pointer
2579 && c
->backend_decl
== NULL
)
2581 else if (c
->next
== NULL
)
2582 return derived
->backend_decl
;
2584 typenode
= derived
->backend_decl
;
2587 typenode
= derived
->backend_decl
;
2591 /* We see this derived type first time, so build the type node. */
2592 typenode
= make_node (RECORD_TYPE
);
2593 TYPE_NAME (typenode
) = get_identifier (derived
->name
);
2594 TYPE_PACKED (typenode
) = flag_pack_derived
;
2595 derived
->backend_decl
= typenode
;
2598 if (derived
->components
2599 && derived
->components
->ts
.type
== BT_DERIVED
2600 && strcmp (derived
->components
->name
, "_data") == 0
2601 && derived
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
2602 unlimited_entity
= true;
2604 /* Go through the derived type components, building them as
2605 necessary. The reason for doing this now is that it is
2606 possible to recurse back to this derived type through a
2607 pointer component (PR24092). If this happens, the fields
2608 will be built and so we can return the type. */
2609 for (c
= derived
->components
; c
; c
= c
->next
)
2611 bool same_alloc_type
= c
->attr
.allocatable
2612 && derived
== c
->ts
.u
.derived
;
2614 if (c
->ts
.type
== BT_UNION
&& c
->ts
.u
.derived
->backend_decl
== NULL
)
2615 c
->ts
.u
.derived
->backend_decl
= gfc_get_union_type (c
->ts
.u
.derived
);
2617 if (c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
2620 if ((!c
->attr
.pointer
&& !c
->attr
.proc_pointer
2621 && !same_alloc_type
)
2622 || c
->ts
.u
.derived
->backend_decl
== NULL
)
2624 int local_codim
= c
->attr
.codimension
? c
->as
->corank
: codimen
;
2625 c
->ts
.u
.derived
->backend_decl
= gfc_get_derived_type (c
->ts
.u
.derived
,
2629 if (c
->ts
.u
.derived
->attr
.is_iso_c
)
2631 /* Need to copy the modified ts from the derived type. The
2632 typespec was modified because C_PTR/C_FUNPTR are translated
2633 into (void *) from derived types. */
2634 c
->ts
.type
= c
->ts
.u
.derived
->ts
.type
;
2635 c
->ts
.kind
= c
->ts
.u
.derived
->ts
.kind
;
2636 c
->ts
.f90_type
= c
->ts
.u
.derived
->ts
.f90_type
;
2639 c
->initializer
->ts
.type
= c
->ts
.type
;
2640 c
->initializer
->ts
.kind
= c
->ts
.kind
;
2641 c
->initializer
->ts
.f90_type
= c
->ts
.f90_type
;
2642 c
->initializer
->expr_type
= EXPR_NULL
;
2647 if (TYPE_FIELDS (derived
->backend_decl
))
2648 return derived
->backend_decl
;
2650 /* Build the type member list. Install the newly created RECORD_TYPE
2651 node as DECL_CONTEXT of each FIELD_DECL. In this case we must go
2652 through only the top-level linked list of components so we correctly
2653 build UNION_TYPE nodes for BT_UNION components. MAPs and other nested
2654 types are built as part of gfc_get_union_type. */
2655 for (c
= derived
->components
; c
; c
= c
->next
)
2657 bool same_alloc_type
= c
->attr
.allocatable
2658 && derived
== c
->ts
.u
.derived
;
2659 /* Prevent infinite recursion, when the procedure pointer type is
2660 the same as derived, by forcing the procedure pointer component to
2661 be built as if the explicit interface does not exist. */
2662 if (c
->attr
.proc_pointer
2663 && (c
->ts
.type
!= BT_DERIVED
|| (c
->ts
.u
.derived
2664 && !gfc_compare_derived_types (derived
, c
->ts
.u
.derived
)))
2665 && (c
->ts
.type
!= BT_CLASS
|| (CLASS_DATA (c
)->ts
.u
.derived
2666 && !gfc_compare_derived_types (derived
, CLASS_DATA (c
)->ts
.u
.derived
))))
2667 field_type
= gfc_get_ppc_type (c
);
2668 else if (c
->attr
.proc_pointer
&& derived
->backend_decl
)
2670 tmp
= build_function_type_list (derived
->backend_decl
, NULL_TREE
);
2671 field_type
= build_pointer_type (tmp
);
2673 else if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
2674 field_type
= c
->ts
.u
.derived
->backend_decl
;
2677 if (c
->ts
.type
== BT_CHARACTER
2678 && !c
->ts
.deferred
&& !c
->attr
.pdt_string
)
2680 /* Evaluate the string length. */
2681 gfc_conv_const_charlen (c
->ts
.u
.cl
);
2682 gcc_assert (c
->ts
.u
.cl
->backend_decl
);
2684 else if (c
->ts
.type
== BT_CHARACTER
)
2685 c
->ts
.u
.cl
->backend_decl
2686 = build_int_cst (gfc_charlen_type_node
, 0);
2688 field_type
= gfc_typenode_for_spec (&c
->ts
, codimen
);
2691 /* This returns an array descriptor type. Initialization may be
2693 if ((c
->attr
.dimension
|| c
->attr
.codimension
) && !c
->attr
.proc_pointer
)
2695 if (c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_array
)
2697 enum gfc_array_kind akind
;
2698 if (c
->attr
.pointer
)
2699 akind
= c
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2700 : GFC_ARRAY_POINTER
;
2702 akind
= GFC_ARRAY_ALLOCATABLE
;
2703 /* Pointers to arrays aren't actually pointer types. The
2704 descriptors are separate, but the data is common. */
2705 field_type
= gfc_build_array_type (field_type
, c
->as
, akind
,
2707 && !c
->attr
.pointer
,
2712 field_type
= gfc_get_nodesc_array_type (field_type
, c
->as
,
2716 else if ((c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_string
)
2717 && !c
->attr
.proc_pointer
2718 && !(unlimited_entity
&& c
== derived
->components
))
2719 field_type
= build_pointer_type (field_type
);
2721 if (c
->attr
.pointer
|| same_alloc_type
)
2722 field_type
= gfc_nonrestricted_type (field_type
);
2724 /* vtype fields can point to different types to the base type. */
2725 if (c
->ts
.type
== BT_DERIVED
2726 && c
->ts
.u
.derived
&& c
->ts
.u
.derived
->attr
.vtype
)
2727 field_type
= build_pointer_type_for_mode (TREE_TYPE (field_type
),
2730 /* Ensure that the CLASS language specific flag is set. */
2731 if (c
->ts
.type
== BT_CLASS
)
2733 if (POINTER_TYPE_P (field_type
))
2734 GFC_CLASS_TYPE_P (TREE_TYPE (field_type
)) = 1;
2736 GFC_CLASS_TYPE_P (field_type
) = 1;
2739 field
= gfc_add_field_to_struct (typenode
,
2740 get_identifier (c
->name
),
2741 field_type
, &chain
);
2743 gfc_set_decl_location (field
, &c
->loc
);
2744 else if (derived
->declared_at
.lb
)
2745 gfc_set_decl_location (field
, &derived
->declared_at
);
2747 gfc_finish_decl_attrs (field
, &c
->attr
);
2749 DECL_PACKED (field
) |= TYPE_PACKED (typenode
);
2752 if (!c
->backend_decl
)
2753 c
->backend_decl
= field
;
2755 if (c
->attr
.pointer
&& c
->attr
.dimension
2756 && !(c
->ts
.type
== BT_DERIVED
2757 && strcmp (c
->name
, "_data") == 0))
2758 GFC_DECL_PTR_ARRAY_P (c
->backend_decl
) = 1;
2760 /* Do not add a caf_token field for classes' data components. */
2761 if (codimen
&& !c
->attr
.dimension
&& !c
->attr
.codimension
2762 && (c
->attr
.allocatable
|| c
->attr
.pointer
)
2763 && c
->caf_token
== NULL_TREE
&& strcmp ("_data", c
->name
) != 0)
2765 char caf_name
[GFC_MAX_SYMBOL_LEN
];
2766 snprintf (caf_name
, GFC_MAX_SYMBOL_LEN
, "_caf_%s", c
->name
);
2767 c
->caf_token
= gfc_add_field_to_struct (typenode
,
2768 get_identifier (caf_name
),
2769 pvoid_type_node
, &chain
);
2770 TREE_NO_WARNING (c
->caf_token
) = 1;
2774 /* Now lay out the derived type, including the fields. */
2776 TYPE_CANONICAL (typenode
) = canonical
;
2778 gfc_finish_type (typenode
);
2779 gfc_set_decl_location (TYPE_STUB_DECL (typenode
), &derived
->declared_at
);
2780 if (derived
->module
&& derived
->ns
->proc_name
2781 && derived
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
2783 if (derived
->ns
->proc_name
->backend_decl
2784 && TREE_CODE (derived
->ns
->proc_name
->backend_decl
)
2787 TYPE_CONTEXT (typenode
) = derived
->ns
->proc_name
->backend_decl
;
2788 DECL_CONTEXT (TYPE_STUB_DECL (typenode
))
2789 = derived
->ns
->proc_name
->backend_decl
;
2793 derived
->backend_decl
= typenode
;
2797 for (dt
= gfc_derived_types
; dt
; dt
= dt
->next
)
2798 gfc_copy_dt_decls_ifequal (derived
, dt
->derived
, false);
2800 return derived
->backend_decl
;
2805 gfc_return_by_reference (gfc_symbol
* sym
)
2807 if (!sym
->attr
.function
)
2810 if (sym
->attr
.dimension
)
2813 if (sym
->ts
.type
== BT_CHARACTER
2814 && !sym
->attr
.is_bind_c
2815 && (!sym
->attr
.result
2816 || !sym
->ns
->proc_name
2817 || !sym
->ns
->proc_name
->attr
.is_bind_c
))
2820 /* Possibly return complex numbers by reference for g77 compatibility.
2821 We don't do this for calls to intrinsics (as the library uses the
2822 -fno-f2c calling convention), nor for calls to functions which always
2823 require an explicit interface, as no compatibility problems can
2825 if (flag_f2c
&& sym
->ts
.type
== BT_COMPLEX
2826 && !sym
->attr
.intrinsic
&& !sym
->attr
.always_explicit
)
2833 gfc_get_mixed_entry_union (gfc_namespace
*ns
)
2837 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2838 gfc_entry_list
*el
, *el2
;
2840 gcc_assert (ns
->proc_name
->attr
.mixed_entry_master
);
2841 gcc_assert (memcmp (ns
->proc_name
->name
, "master.", 7) == 0);
2843 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "munion.%s", ns
->proc_name
->name
+ 7);
2845 /* Build the type node. */
2846 type
= make_node (UNION_TYPE
);
2848 TYPE_NAME (type
) = get_identifier (name
);
2850 for (el
= ns
->entries
; el
; el
= el
->next
)
2852 /* Search for duplicates. */
2853 for (el2
= ns
->entries
; el2
!= el
; el2
= el2
->next
)
2854 if (el2
->sym
->result
== el
->sym
->result
)
2858 gfc_add_field_to_struct_1 (type
,
2859 get_identifier (el
->sym
->result
->name
),
2860 gfc_sym_type (el
->sym
->result
), &chain
);
2863 /* Finish off the type. */
2864 gfc_finish_type (type
);
2865 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
2869 /* Create a "fn spec" based on the formal arguments;
2870 cf. create_function_arglist. */
2873 create_fn_spec (gfc_symbol
*sym
, tree fntype
)
2877 gfc_formal_arglist
*f
;
2880 memset (&spec
, 0, sizeof (spec
));
2884 if (sym
->attr
.entry_master
)
2885 spec
[spec_len
++] = 'R';
2886 if (gfc_return_by_reference (sym
))
2888 gfc_symbol
*result
= sym
->result
? sym
->result
: sym
;
2890 if (result
->attr
.pointer
|| sym
->attr
.proc_pointer
)
2891 spec
[spec_len
++] = '.';
2893 spec
[spec_len
++] = 'w';
2894 if (sym
->ts
.type
== BT_CHARACTER
)
2895 spec
[spec_len
++] = 'R';
2898 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2899 if (spec_len
< sizeof (spec
))
2901 if (!f
->sym
|| f
->sym
->attr
.pointer
|| f
->sym
->attr
.target
2902 || f
->sym
->attr
.external
|| f
->sym
->attr
.cray_pointer
2903 || (f
->sym
->ts
.type
== BT_DERIVED
2904 && (f
->sym
->ts
.u
.derived
->attr
.proc_pointer_comp
2905 || f
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
2906 || (f
->sym
->ts
.type
== BT_CLASS
2907 && (CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.proc_pointer_comp
2908 || CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.pointer_comp
)))
2909 spec
[spec_len
++] = '.';
2910 else if (f
->sym
->attr
.intent
== INTENT_IN
)
2911 spec
[spec_len
++] = 'r';
2913 spec
[spec_len
++] = 'w';
2916 tmp
= build_tree_list (NULL_TREE
, build_string (spec_len
, spec
));
2917 tmp
= tree_cons (get_identifier ("fn spec"), tmp
, TYPE_ATTRIBUTES (fntype
));
2918 return build_type_attribute_variant (fntype
, tmp
);
2923 gfc_get_function_type (gfc_symbol
* sym
)
2926 vec
<tree
, va_gc
> *typelist
= NULL
;
2927 gfc_formal_arglist
*f
;
2929 int alternate_return
= 0;
2930 bool is_varargs
= true;
2932 /* Make sure this symbol is a function, a subroutine or the main
2934 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
2935 || sym
->attr
.flavor
== FL_PROGRAM
);
2937 /* To avoid recursing infinitely on recursive types, we use error_mark_node
2938 so that they can be detected here and handled further down. */
2939 if (sym
->backend_decl
== NULL
)
2940 sym
->backend_decl
= error_mark_node
;
2941 else if (sym
->backend_decl
== error_mark_node
)
2942 goto arg_type_list_done
;
2943 else if (sym
->attr
.proc_pointer
)
2944 return TREE_TYPE (TREE_TYPE (sym
->backend_decl
));
2946 return TREE_TYPE (sym
->backend_decl
);
2948 if (sym
->attr
.entry_master
)
2949 /* Additional parameter for selecting an entry point. */
2950 vec_safe_push (typelist
, gfc_array_index_type
);
2957 if (arg
->ts
.type
== BT_CHARACTER
)
2958 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
2960 /* Some functions we use an extra parameter for the return value. */
2961 if (gfc_return_by_reference (sym
))
2963 type
= gfc_sym_type (arg
);
2964 if (arg
->ts
.type
== BT_COMPLEX
2965 || arg
->attr
.dimension
2966 || arg
->ts
.type
== BT_CHARACTER
)
2967 type
= build_reference_type (type
);
2969 vec_safe_push (typelist
, type
);
2970 if (arg
->ts
.type
== BT_CHARACTER
)
2972 if (!arg
->ts
.deferred
)
2973 /* Transfer by value. */
2974 vec_safe_push (typelist
, gfc_charlen_type_node
);
2976 /* Deferred character lengths are transferred by reference
2977 so that the value can be returned. */
2978 vec_safe_push (typelist
, build_pointer_type(gfc_charlen_type_node
));
2982 /* Build the argument types for the function. */
2983 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2988 /* Evaluate constant character lengths here so that they can be
2989 included in the type. */
2990 if (arg
->ts
.type
== BT_CHARACTER
)
2991 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
2993 if (arg
->attr
.flavor
== FL_PROCEDURE
)
2995 type
= gfc_get_function_type (arg
);
2996 type
= build_pointer_type (type
);
2999 type
= gfc_sym_type (arg
);
3001 /* Parameter Passing Convention
3003 We currently pass all parameters by reference.
3004 Parameters with INTENT(IN) could be passed by value.
3005 The problem arises if a function is called via an implicit
3006 prototype. In this situation the INTENT is not known.
3007 For this reason all parameters to global functions must be
3008 passed by reference. Passing by value would potentially
3009 generate bad code. Worse there would be no way of telling that
3010 this code was bad, except that it would give incorrect results.
3012 Contained procedures could pass by value as these are never
3013 used without an explicit interface, and cannot be passed as
3014 actual parameters for a dummy procedure. */
3016 vec_safe_push (typelist
, type
);
3020 if (sym
->attr
.subroutine
)
3021 alternate_return
= 1;
3025 /* Add hidden string length parameters. */
3026 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3029 if (arg
&& arg
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.is_bind_c
)
3031 if (!arg
->ts
.deferred
)
3032 /* Transfer by value. */
3033 type
= gfc_charlen_type_node
;
3035 /* Deferred character lengths are transferred by reference
3036 so that the value can be returned. */
3037 type
= build_pointer_type (gfc_charlen_type_node
);
3039 vec_safe_push (typelist
, type
);
3043 if (!vec_safe_is_empty (typelist
)
3044 || sym
->attr
.is_main_program
3045 || sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
3048 if (sym
->backend_decl
== error_mark_node
)
3049 sym
->backend_decl
= NULL_TREE
;
3053 if (alternate_return
)
3054 type
= integer_type_node
;
3055 else if (!sym
->attr
.function
|| gfc_return_by_reference (sym
))
3056 type
= void_type_node
;
3057 else if (sym
->attr
.mixed_entry_master
)
3058 type
= gfc_get_mixed_entry_union (sym
->ns
);
3059 else if (flag_f2c
&& sym
->ts
.type
== BT_REAL
3060 && sym
->ts
.kind
== gfc_default_real_kind
3061 && !sym
->attr
.always_explicit
)
3063 /* Special case: f2c calling conventions require that (scalar)
3064 default REAL functions return the C type double instead. f2c
3065 compatibility is only an issue with functions that don't
3066 require an explicit interface, as only these could be
3067 implemented in Fortran 77. */
3068 sym
->ts
.kind
= gfc_default_double_kind
;
3069 type
= gfc_typenode_for_spec (&sym
->ts
);
3070 sym
->ts
.kind
= gfc_default_real_kind
;
3072 else if (sym
->result
&& sym
->result
->attr
.proc_pointer
)
3073 /* Procedure pointer return values. */
3075 if (sym
->result
->attr
.result
&& strcmp (sym
->name
,"ppr@") != 0)
3077 /* Unset proc_pointer as gfc_get_function_type
3078 is called recursively. */
3079 sym
->result
->attr
.proc_pointer
= 0;
3080 type
= build_pointer_type (gfc_get_function_type (sym
->result
));
3081 sym
->result
->attr
.proc_pointer
= 1;
3084 type
= gfc_sym_type (sym
->result
);
3087 type
= gfc_sym_type (sym
);
3090 type
= build_varargs_function_type_vec (type
, typelist
);
3092 type
= build_function_type_vec (type
, typelist
);
3093 type
= create_fn_spec (sym
, type
);
3098 /* Language hooks for middle-end access to type nodes. */
3100 /* Return an integer type with BITS bits of precision,
3101 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3104 gfc_type_for_size (unsigned bits
, int unsignedp
)
3109 for (i
= 0; i
<= MAX_INT_KINDS
; ++i
)
3111 tree type
= gfc_integer_types
[i
];
3112 if (type
&& bits
== TYPE_PRECISION (type
))
3116 /* Handle TImode as a special case because it is used by some backends
3117 (e.g. ARM) even though it is not available for normal use. */
3118 #if HOST_BITS_PER_WIDE_INT >= 64
3119 if (bits
== TYPE_PRECISION (intTI_type_node
))
3120 return intTI_type_node
;
3123 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3124 return intQI_type_node
;
3125 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3126 return intHI_type_node
;
3127 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3128 return intSI_type_node
;
3129 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3130 return intDI_type_node
;
3131 if (bits
<= TYPE_PRECISION (intTI_type_node
))
3132 return intTI_type_node
;
3136 if (bits
<= TYPE_PRECISION (unsigned_intQI_type_node
))
3137 return unsigned_intQI_type_node
;
3138 if (bits
<= TYPE_PRECISION (unsigned_intHI_type_node
))
3139 return unsigned_intHI_type_node
;
3140 if (bits
<= TYPE_PRECISION (unsigned_intSI_type_node
))
3141 return unsigned_intSI_type_node
;
3142 if (bits
<= TYPE_PRECISION (unsigned_intDI_type_node
))
3143 return unsigned_intDI_type_node
;
3144 if (bits
<= TYPE_PRECISION (unsigned_intTI_type_node
))
3145 return unsigned_intTI_type_node
;
3151 /* Return a data type that has machine mode MODE. If the mode is an
3152 integer, then UNSIGNEDP selects between signed and unsigned types. */
3155 gfc_type_for_mode (machine_mode mode
, int unsignedp
)
3159 scalar_int_mode int_mode
;
3161 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3162 base
= gfc_real_types
;
3163 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
3164 base
= gfc_complex_types
;
3165 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
3167 tree type
= gfc_type_for_size (GET_MODE_PRECISION (int_mode
), unsignedp
);
3168 return type
!= NULL_TREE
&& mode
== TYPE_MODE (type
) ? type
: NULL_TREE
;
3170 else if (VECTOR_MODE_P (mode
))
3172 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3173 tree inner_type
= gfc_type_for_mode (inner_mode
, unsignedp
);
3174 if (inner_type
!= NULL_TREE
)
3175 return build_vector_type_for_mode (inner_type
, mode
);
3181 for (i
= 0; i
<= MAX_REAL_KINDS
; ++i
)
3183 tree type
= base
[i
];
3184 if (type
&& mode
== TYPE_MODE (type
))
3191 /* Return TRUE if TYPE is a type with a hidden descriptor, fill in INFO
3195 gfc_get_array_descr_info (const_tree type
, struct array_descr_info
*info
)
3198 bool indirect
= false;
3199 tree etype
, ptype
, t
, base_decl
;
3200 tree data_off
, dim_off
, dtype_off
, dim_size
, elem_size
;
3201 tree lower_suboff
, upper_suboff
, stride_suboff
;
3203 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3205 if (! POINTER_TYPE_P (type
))
3207 type
= TREE_TYPE (type
);
3208 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3213 rank
= GFC_TYPE_ARRAY_RANK (type
);
3214 if (rank
>= (int) (sizeof (info
->dimen
) / sizeof (info
->dimen
[0])))
3217 etype
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
3218 gcc_assert (POINTER_TYPE_P (etype
));
3219 etype
= TREE_TYPE (etype
);
3221 /* If the type is not a scalar coarray. */
3222 if (TREE_CODE (etype
) == ARRAY_TYPE
)
3223 etype
= TREE_TYPE (etype
);
3225 /* Can't handle variable sized elements yet. */
3226 if (int_size_in_bytes (etype
) <= 0)
3228 /* Nor non-constant lower bounds in assumed shape arrays. */
3229 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3230 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3232 for (dim
= 0; dim
< rank
; dim
++)
3233 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
3234 || TREE_CODE (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) != INTEGER_CST
)
3238 memset (info
, '\0', sizeof (*info
));
3239 info
->ndimensions
= rank
;
3240 info
->ordering
= array_descr_ordering_column_major
;
3241 info
->element_type
= etype
;
3242 ptype
= build_pointer_type (gfc_array_index_type
);
3243 base_decl
= GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
);
3246 base_decl
= make_node (DEBUG_EXPR_DECL
);
3247 DECL_ARTIFICIAL (base_decl
) = 1;
3248 TREE_TYPE (base_decl
) = indirect
? build_pointer_type (ptype
) : ptype
;
3249 SET_DECL_MODE (base_decl
, TYPE_MODE (TREE_TYPE (base_decl
)));
3250 GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
) = base_decl
;
3252 info
->base_decl
= base_decl
;
3254 base_decl
= build1 (INDIRECT_REF
, ptype
, base_decl
);
3256 elem_size
= fold_convert (gfc_array_index_type
, TYPE_SIZE_UNIT (etype
));
3258 gfc_get_descriptor_offsets_for_info (type
, &data_off
, &dtype_off
, &dim_off
,
3259 &dim_size
, &stride_suboff
,
3260 &lower_suboff
, &upper_suboff
);
3263 if (!integer_zerop (data_off
))
3264 t
= fold_build_pointer_plus (t
, data_off
);
3265 t
= build1 (NOP_EXPR
, build_pointer_type (ptr_type_node
), t
);
3266 info
->data_location
= build1 (INDIRECT_REF
, ptr_type_node
, t
);
3267 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ALLOCATABLE
)
3268 info
->allocated
= build2 (NE_EXPR
, logical_type_node
,
3269 info
->data_location
, null_pointer_node
);
3270 else if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER
3271 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER_CONT
)
3272 info
->associated
= build2 (NE_EXPR
, logical_type_node
,
3273 info
->data_location
, null_pointer_node
);
3274 if ((GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK
3275 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK_CONT
)
3276 && dwarf_version
>= 5)
3279 info
->ndimensions
= 1;
3281 if (!integer_zerop (dtype_off
))
3282 t
= fold_build_pointer_plus (t
, dtype_off
);
3283 t
= build1 (NOP_EXPR
, build_pointer_type (gfc_array_index_type
), t
);
3284 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3285 info
->rank
= build2 (BIT_AND_EXPR
, gfc_array_index_type
, t
,
3286 build_int_cst (gfc_array_index_type
,
3287 GFC_DTYPE_RANK_MASK
));
3288 t
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (dim_off
));
3289 t
= size_binop (MULT_EXPR
, t
, dim_size
);
3290 dim_off
= build2 (PLUS_EXPR
, TREE_TYPE (dim_off
), t
, dim_off
);
3293 for (dim
= 0; dim
< rank
; dim
++)
3295 t
= fold_build_pointer_plus (base_decl
,
3296 size_binop (PLUS_EXPR
,
3297 dim_off
, lower_suboff
));
3298 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3299 info
->dimen
[dim
].lower_bound
= t
;
3300 t
= fold_build_pointer_plus (base_decl
,
3301 size_binop (PLUS_EXPR
,
3302 dim_off
, upper_suboff
));
3303 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3304 info
->dimen
[dim
].upper_bound
= t
;
3305 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3306 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3308 /* Assumed shape arrays have known lower bounds. */
3309 info
->dimen
[dim
].upper_bound
3310 = build2 (MINUS_EXPR
, gfc_array_index_type
,
3311 info
->dimen
[dim
].upper_bound
,
3312 info
->dimen
[dim
].lower_bound
);
3313 info
->dimen
[dim
].lower_bound
3314 = fold_convert (gfc_array_index_type
,
3315 GFC_TYPE_ARRAY_LBOUND (type
, dim
));
3316 info
->dimen
[dim
].upper_bound
3317 = build2 (PLUS_EXPR
, gfc_array_index_type
,
3318 info
->dimen
[dim
].lower_bound
,
3319 info
->dimen
[dim
].upper_bound
);
3321 t
= fold_build_pointer_plus (base_decl
,
3322 size_binop (PLUS_EXPR
,
3323 dim_off
, stride_suboff
));
3324 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3325 t
= build2 (MULT_EXPR
, gfc_array_index_type
, t
, elem_size
);
3326 info
->dimen
[dim
].stride
= t
;
3328 dim_off
= size_binop (PLUS_EXPR
, dim_off
, dim_size
);
3335 /* Create a type to handle vector subscripts for coarray library calls. It
3337 struct caf_vector_t {
3338 size_t nvec; // size of the vector
3345 ptrdiff_t lower_bound;
3346 ptrdiff_t upper_bound;
3351 where nvec == 0 for DIMEN_ELEMENT or DIMEN_RANGE and nvec being the vector
3352 size in case of DIMEN_VECTOR, where kind is the integer type of the vector. */
3355 gfc_get_caf_vector_type (int dim
)
3357 static tree vector_types
[GFC_MAX_DIMENSIONS
];
3358 static tree vec_type
= NULL_TREE
;
3359 tree triplet_struct_type
, vect_struct_type
, union_type
, tmp
, *chain
;
3361 if (vector_types
[dim
-1] != NULL_TREE
)
3362 return vector_types
[dim
-1];
3364 if (vec_type
== NULL_TREE
)
3367 vect_struct_type
= make_node (RECORD_TYPE
);
3368 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3369 get_identifier ("vector"),
3370 pvoid_type_node
, &chain
);
3371 TREE_NO_WARNING (tmp
) = 1;
3372 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3373 get_identifier ("kind"),
3374 integer_type_node
, &chain
);
3375 TREE_NO_WARNING (tmp
) = 1;
3376 gfc_finish_type (vect_struct_type
);
3379 triplet_struct_type
= make_node (RECORD_TYPE
);
3380 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3381 get_identifier ("lower_bound"),
3382 gfc_array_index_type
, &chain
);
3383 TREE_NO_WARNING (tmp
) = 1;
3384 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3385 get_identifier ("upper_bound"),
3386 gfc_array_index_type
, &chain
);
3387 TREE_NO_WARNING (tmp
) = 1;
3388 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
, get_identifier ("stride"),
3389 gfc_array_index_type
, &chain
);
3390 TREE_NO_WARNING (tmp
) = 1;
3391 gfc_finish_type (triplet_struct_type
);
3394 union_type
= make_node (UNION_TYPE
);
3395 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3396 vect_struct_type
, &chain
);
3397 TREE_NO_WARNING (tmp
) = 1;
3398 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("triplet"),
3399 triplet_struct_type
, &chain
);
3400 TREE_NO_WARNING (tmp
) = 1;
3401 gfc_finish_type (union_type
);
3404 vec_type
= make_node (RECORD_TYPE
);
3405 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("nvec"),
3406 size_type_node
, &chain
);
3407 TREE_NO_WARNING (tmp
) = 1;
3408 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("u"),
3409 union_type
, &chain
);
3410 TREE_NO_WARNING (tmp
) = 1;
3411 gfc_finish_type (vec_type
);
3412 TYPE_NAME (vec_type
) = get_identifier ("caf_vector_t");
3415 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3416 gfc_rank_cst
[dim
-1]);
3417 vector_types
[dim
-1] = build_array_type (vec_type
, tmp
);
3418 return vector_types
[dim
-1];
3423 gfc_get_caf_reference_type ()
3425 static tree reference_type
= NULL_TREE
;
3426 tree c_struct_type
, s_struct_type
, v_struct_type
, union_type
, dim_union_type
,
3427 a_struct_type
, u_union_type
, tmp
, *chain
;
3429 if (reference_type
!= NULL_TREE
)
3430 return reference_type
;
3433 c_struct_type
= make_node (RECORD_TYPE
);
3434 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3435 get_identifier ("offset"),
3436 gfc_array_index_type
, &chain
);
3437 TREE_NO_WARNING (tmp
) = 1;
3438 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3439 get_identifier ("caf_token_offset"),
3440 gfc_array_index_type
, &chain
);
3441 TREE_NO_WARNING (tmp
) = 1;
3442 gfc_finish_type (c_struct_type
);
3445 s_struct_type
= make_node (RECORD_TYPE
);
3446 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3447 get_identifier ("start"),
3448 gfc_array_index_type
, &chain
);
3449 TREE_NO_WARNING (tmp
) = 1;
3450 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3451 get_identifier ("end"),
3452 gfc_array_index_type
, &chain
);
3453 TREE_NO_WARNING (tmp
) = 1;
3454 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3455 get_identifier ("stride"),
3456 gfc_array_index_type
, &chain
);
3457 TREE_NO_WARNING (tmp
) = 1;
3458 gfc_finish_type (s_struct_type
);
3461 v_struct_type
= make_node (RECORD_TYPE
);
3462 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3463 get_identifier ("vector"),
3464 pvoid_type_node
, &chain
);
3465 TREE_NO_WARNING (tmp
) = 1;
3466 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3467 get_identifier ("nvec"),
3468 size_type_node
, &chain
);
3469 TREE_NO_WARNING (tmp
) = 1;
3470 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3471 get_identifier ("kind"),
3472 integer_type_node
, &chain
);
3473 TREE_NO_WARNING (tmp
) = 1;
3474 gfc_finish_type (v_struct_type
);
3477 union_type
= make_node (UNION_TYPE
);
3478 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("s"),
3479 s_struct_type
, &chain
);
3480 TREE_NO_WARNING (tmp
) = 1;
3481 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3482 v_struct_type
, &chain
);
3483 TREE_NO_WARNING (tmp
) = 1;
3484 gfc_finish_type (union_type
);
3486 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3487 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1]);
3488 dim_union_type
= build_array_type (union_type
, tmp
);
3491 a_struct_type
= make_node (RECORD_TYPE
);
3492 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("mode"),
3493 build_array_type (unsigned_char_type_node
,
3494 build_range_type (gfc_array_index_type
,
3495 gfc_index_zero_node
,
3496 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1])),
3498 TREE_NO_WARNING (tmp
) = 1;
3499 tmp
= gfc_add_field_to_struct_1 (a_struct_type
,
3500 get_identifier ("static_array_type"),
3501 integer_type_node
, &chain
);
3502 TREE_NO_WARNING (tmp
) = 1;
3503 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("dim"),
3504 dim_union_type
, &chain
);
3505 TREE_NO_WARNING (tmp
) = 1;
3506 gfc_finish_type (a_struct_type
);
3509 u_union_type
= make_node (UNION_TYPE
);
3510 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("c"),
3511 c_struct_type
, &chain
);
3512 TREE_NO_WARNING (tmp
) = 1;
3513 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("a"),
3514 a_struct_type
, &chain
);
3515 TREE_NO_WARNING (tmp
) = 1;
3516 gfc_finish_type (u_union_type
);
3519 reference_type
= make_node (RECORD_TYPE
);
3520 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("next"),
3521 build_pointer_type (reference_type
), &chain
);
3522 TREE_NO_WARNING (tmp
) = 1;
3523 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("type"),
3524 integer_type_node
, &chain
);
3525 TREE_NO_WARNING (tmp
) = 1;
3526 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("item_size"),
3527 size_type_node
, &chain
);
3528 TREE_NO_WARNING (tmp
) = 1;
3529 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("u"),
3530 u_union_type
, &chain
);
3531 TREE_NO_WARNING (tmp
) = 1;
3532 gfc_finish_type (reference_type
);
3533 TYPE_NAME (reference_type
) = get_identifier ("caf_reference_t");
3535 return reference_type
;
3538 #include "gt-fortran-trans-types.h"