1 /* Backend support for Fortran 95 basic types and derived types.
2 Copyright (C) 2002-2018 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
)
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
->attr
.result
2205 && sym
->ts
.type
== BT_CHARACTER
2206 && sym
->ts
.u
.cl
->backend_decl
== NULL_TREE
2207 && sym
->ns
->proc_name
->ts
.u
.cl
->backend_decl
!= NULL_TREE
)
2208 sym
->ts
.u
.cl
->backend_decl
= sym
->ns
->proc_name
->ts
.u
.cl
->backend_decl
;
2210 if (sym
->ts
.type
== BT_CHARACTER
2211 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
)
2212 || (sym
->attr
.result
2213 && sym
->ns
->proc_name
2214 && sym
->ns
->proc_name
->attr
.is_bind_c
)
2215 || (sym
->ts
.deferred
&& (!sym
->ts
.u
.cl
2216 || !sym
->ts
.u
.cl
->backend_decl
))))
2217 type
= gfc_character1_type_node
;
2219 type
= gfc_typenode_for_spec (&sym
->ts
, sym
->attr
.codimension
);
2221 if (sym
->attr
.dummy
&& !sym
->attr
.function
&& !sym
->attr
.value
)
2226 restricted
= !sym
->attr
.target
&& !sym
->attr
.pointer
2227 && !sym
->attr
.proc_pointer
&& !sym
->attr
.cray_pointee
;
2229 type
= gfc_nonrestricted_type (type
);
2231 if (sym
->attr
.dimension
|| sym
->attr
.codimension
)
2233 if (gfc_is_nodesc_array (sym
))
2235 /* If this is a character argument of unknown length, just use the
2237 if (sym
->ts
.type
!= BT_CHARACTER
2238 || !(sym
->attr
.dummy
|| sym
->attr
.function
)
2239 || sym
->ts
.u
.cl
->backend_decl
)
2241 type
= gfc_get_nodesc_array_type (type
, sym
->as
,
2250 enum gfc_array_kind akind
= GFC_ARRAY_UNKNOWN
;
2251 if (sym
->attr
.pointer
)
2252 akind
= sym
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2253 : GFC_ARRAY_POINTER
;
2254 else if (sym
->attr
.allocatable
)
2255 akind
= GFC_ARRAY_ALLOCATABLE
;
2256 type
= gfc_build_array_type (type
, sym
->as
, akind
, restricted
,
2257 sym
->attr
.contiguous
, false);
2262 if (sym
->attr
.allocatable
|| sym
->attr
.pointer
2263 || gfc_is_associate_pointer (sym
))
2264 type
= gfc_build_pointer_type (sym
, type
);
2267 /* We currently pass all parameters by reference.
2268 See f95_get_function_decl. For dummy function parameters return the
2272 /* We must use pointer types for potentially absent variables. The
2273 optimizers assume a reference type argument is never NULL. */
2274 if (sym
->attr
.optional
2275 || (sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.entry_master
))
2276 type
= build_pointer_type (type
);
2279 type
= build_reference_type (type
);
2281 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
2288 /* Layout and output debug info for a record type. */
2291 gfc_finish_type (tree type
)
2295 decl
= build_decl (input_location
,
2296 TYPE_DECL
, NULL_TREE
, type
);
2297 TYPE_STUB_DECL (type
) = decl
;
2299 rest_of_type_compilation (type
, 1);
2300 rest_of_decl_compilation (decl
, 1, 0);
2303 /* Add a field of given NAME and TYPE to the context of a UNION_TYPE
2304 or RECORD_TYPE pointed to by CONTEXT. The new field is chained
2305 to the end of the field list pointed to by *CHAIN.
2307 Returns a pointer to the new field. */
2310 gfc_add_field_to_struct_1 (tree context
, tree name
, tree type
, tree
**chain
)
2312 tree decl
= build_decl (input_location
, FIELD_DECL
, name
, type
);
2314 DECL_CONTEXT (decl
) = context
;
2315 DECL_CHAIN (decl
) = NULL_TREE
;
2316 if (TYPE_FIELDS (context
) == NULL_TREE
)
2317 TYPE_FIELDS (context
) = decl
;
2322 *chain
= &DECL_CHAIN (decl
);
2328 /* Like `gfc_add_field_to_struct_1', but adds alignment
2332 gfc_add_field_to_struct (tree context
, tree name
, tree type
, tree
**chain
)
2334 tree decl
= gfc_add_field_to_struct_1 (context
, name
, type
, chain
);
2336 DECL_INITIAL (decl
) = 0;
2337 SET_DECL_ALIGN (decl
, 0);
2338 DECL_USER_ALIGN (decl
) = 0;
2344 /* Copy the backend_decl and component backend_decls if
2345 the two derived type symbols are "equal", as described
2346 in 4.4.2 and resolved by gfc_compare_derived_types. */
2349 gfc_copy_dt_decls_ifequal (gfc_symbol
*from
, gfc_symbol
*to
,
2352 gfc_component
*to_cm
;
2353 gfc_component
*from_cm
;
2358 if (from
->backend_decl
== NULL
2359 || !gfc_compare_derived_types (from
, to
))
2362 to
->backend_decl
= from
->backend_decl
;
2364 to_cm
= to
->components
;
2365 from_cm
= from
->components
;
2367 /* Copy the component declarations. If a component is itself
2368 a derived type, we need a copy of its component declarations.
2369 This is done by recursing into gfc_get_derived_type and
2370 ensures that the component's component declarations have
2371 been built. If it is a character, we need the character
2373 for (; to_cm
; to_cm
= to_cm
->next
, from_cm
= from_cm
->next
)
2375 to_cm
->backend_decl
= from_cm
->backend_decl
;
2376 to_cm
->caf_token
= from_cm
->caf_token
;
2377 if (from_cm
->ts
.type
== BT_UNION
)
2378 gfc_get_union_type (to_cm
->ts
.u
.derived
);
2379 else if (from_cm
->ts
.type
== BT_DERIVED
2380 && (!from_cm
->attr
.pointer
|| from_gsym
))
2381 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2382 else if (from_cm
->ts
.type
== BT_CLASS
2383 && (!CLASS_DATA (from_cm
)->attr
.class_pointer
|| from_gsym
))
2384 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2385 else if (from_cm
->ts
.type
== BT_CHARACTER
)
2386 to_cm
->ts
.u
.cl
->backend_decl
= from_cm
->ts
.u
.cl
->backend_decl
;
2393 /* Build a tree node for a procedure pointer component. */
2396 gfc_get_ppc_type (gfc_component
* c
)
2400 /* Explicit interface. */
2401 if (c
->attr
.if_source
!= IFSRC_UNKNOWN
&& c
->ts
.interface
)
2402 return build_pointer_type (gfc_get_function_type (c
->ts
.interface
));
2404 /* Implicit interface (only return value may be known). */
2405 if (c
->attr
.function
&& !c
->attr
.dimension
&& c
->ts
.type
!= BT_CHARACTER
)
2406 t
= gfc_typenode_for_spec (&c
->ts
);
2410 return build_pointer_type (build_function_type_list (t
, NULL_TREE
));
2414 /* Build a tree node for a union type. Requires building each map
2415 structure which is an element of the union. */
2418 gfc_get_union_type (gfc_symbol
*un
)
2420 gfc_component
*map
= NULL
;
2421 tree typenode
= NULL
, map_type
= NULL
, map_field
= NULL
;
2424 if (un
->backend_decl
)
2426 if (TYPE_FIELDS (un
->backend_decl
) || un
->attr
.proc_pointer_comp
)
2427 return un
->backend_decl
;
2429 typenode
= un
->backend_decl
;
2433 typenode
= make_node (UNION_TYPE
);
2434 TYPE_NAME (typenode
) = get_identifier (un
->name
);
2437 /* Add each contained MAP as a field. */
2438 for (map
= un
->components
; map
; map
= map
->next
)
2440 gcc_assert (map
->ts
.type
== BT_DERIVED
);
2442 /* The map's type node, which is defined within this union's context. */
2443 map_type
= gfc_get_derived_type (map
->ts
.u
.derived
);
2444 TYPE_CONTEXT (map_type
) = typenode
;
2446 /* The map field's declaration. */
2447 map_field
= gfc_add_field_to_struct(typenode
, get_identifier(map
->name
),
2450 gfc_set_decl_location (map_field
, &map
->loc
);
2451 else if (un
->declared_at
.lb
)
2452 gfc_set_decl_location (map_field
, &un
->declared_at
);
2454 DECL_PACKED (map_field
) |= TYPE_PACKED (typenode
);
2455 DECL_NAMELESS(map_field
) = true;
2457 /* We should never clobber another backend declaration for this map,
2458 because each map component is unique. */
2459 if (!map
->backend_decl
)
2460 map
->backend_decl
= map_field
;
2463 un
->backend_decl
= typenode
;
2464 gfc_finish_type (typenode
);
2470 /* Build a tree node for a derived type. If there are equal
2471 derived types, with different local names, these are built
2472 at the same time. If an equal derived type has been built
2473 in a parent namespace, this is used. */
2476 gfc_get_derived_type (gfc_symbol
* derived
, int codimen
)
2478 tree typenode
= NULL
, field
= NULL
, field_type
= NULL
;
2479 tree canonical
= NULL_TREE
;
2481 bool got_canonical
= false;
2482 bool unlimited_entity
= false;
2489 coarray_flag
= flag_coarray
== GFC_FCOARRAY_LIB
2490 && derived
->module
&& !derived
->attr
.vtype
;
2492 gcc_assert (!derived
->attr
.pdt_template
);
2494 if (derived
->attr
.unlimited_polymorphic
2495 || (flag_coarray
== GFC_FCOARRAY_LIB
2496 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2497 && (derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
2498 || derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)))
2499 return ptr_type_node
;
2501 if (flag_coarray
!= GFC_FCOARRAY_LIB
2502 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2503 && derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2504 return gfc_get_int_type (gfc_default_integer_kind
);
2506 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
2507 && derived
->attr
.generic
)
2508 derived
= gfc_find_dt_in_generic (derived
);
2510 /* See if it's one of the iso_c_binding derived types. */
2511 if (derived
->attr
.is_iso_c
== 1 || derived
->ts
.f90_type
== BT_VOID
)
2513 if (derived
->backend_decl
)
2514 return derived
->backend_decl
;
2516 if (derived
->intmod_sym_id
== ISOCBINDING_PTR
)
2517 derived
->backend_decl
= ptr_type_node
;
2519 derived
->backend_decl
= pfunc_type_node
;
2521 derived
->ts
.kind
= gfc_index_integer_kind
;
2522 derived
->ts
.type
= BT_INTEGER
;
2523 /* Set the f90_type to BT_VOID as a way to recognize something of type
2524 BT_INTEGER that needs to fit a void * for the purpose of the
2525 iso_c_binding derived types. */
2526 derived
->ts
.f90_type
= BT_VOID
;
2528 return derived
->backend_decl
;
2531 /* If use associated, use the module type for this one. */
2532 if (derived
->backend_decl
== NULL
2533 && derived
->attr
.use_assoc
2535 && gfc_get_module_backend_decl (derived
))
2536 goto copy_derived_types
;
2538 /* The derived types from an earlier namespace can be used as the
2540 if (derived
->backend_decl
== NULL
&& !derived
->attr
.use_assoc
2541 && gfc_global_ns_list
)
2543 for (ns
= gfc_global_ns_list
;
2544 ns
->translated
&& !got_canonical
;
2547 dt
= ns
->derived_types
;
2548 for (; dt
&& !canonical
; dt
= dt
->next
)
2550 gfc_copy_dt_decls_ifequal (dt
->derived
, derived
, true);
2551 if (derived
->backend_decl
)
2552 got_canonical
= true;
2557 /* Store up the canonical type to be added to this one. */
2560 if (TYPE_CANONICAL (derived
->backend_decl
))
2561 canonical
= TYPE_CANONICAL (derived
->backend_decl
);
2563 canonical
= derived
->backend_decl
;
2565 derived
->backend_decl
= NULL_TREE
;
2568 /* derived->backend_decl != 0 means we saw it before, but its
2569 components' backend_decl may have not been built. */
2570 if (derived
->backend_decl
)
2572 /* Its components' backend_decl have been built or we are
2573 seeing recursion through the formal arglist of a procedure
2574 pointer component. */
2575 if (TYPE_FIELDS (derived
->backend_decl
))
2576 return derived
->backend_decl
;
2577 else if (derived
->attr
.abstract
2578 && derived
->attr
.proc_pointer_comp
)
2580 /* If an abstract derived type with procedure pointer
2581 components has no other type of component, return the
2582 backend_decl. Otherwise build the components if any of the
2583 non-procedure pointer components have no backend_decl. */
2584 for (c
= derived
->components
; c
; c
= c
->next
)
2586 bool same_alloc_type
= c
->attr
.allocatable
2587 && derived
== c
->ts
.u
.derived
;
2588 if (!c
->attr
.proc_pointer
2590 && c
->backend_decl
== NULL
)
2592 else if (c
->next
== NULL
)
2593 return derived
->backend_decl
;
2595 typenode
= derived
->backend_decl
;
2598 typenode
= derived
->backend_decl
;
2602 /* We see this derived type first time, so build the type node. */
2603 typenode
= make_node (RECORD_TYPE
);
2604 TYPE_NAME (typenode
) = get_identifier (derived
->name
);
2605 TYPE_PACKED (typenode
) = flag_pack_derived
;
2606 derived
->backend_decl
= typenode
;
2609 if (derived
->components
2610 && derived
->components
->ts
.type
== BT_DERIVED
2611 && strcmp (derived
->components
->name
, "_data") == 0
2612 && derived
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
2613 unlimited_entity
= true;
2615 /* Go through the derived type components, building them as
2616 necessary. The reason for doing this now is that it is
2617 possible to recurse back to this derived type through a
2618 pointer component (PR24092). If this happens, the fields
2619 will be built and so we can return the type. */
2620 for (c
= derived
->components
; c
; c
= c
->next
)
2622 bool same_alloc_type
= c
->attr
.allocatable
2623 && derived
== c
->ts
.u
.derived
;
2625 if (c
->ts
.type
== BT_UNION
&& c
->ts
.u
.derived
->backend_decl
== NULL
)
2626 c
->ts
.u
.derived
->backend_decl
= gfc_get_union_type (c
->ts
.u
.derived
);
2628 if (c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
2631 if ((!c
->attr
.pointer
&& !c
->attr
.proc_pointer
2632 && !same_alloc_type
)
2633 || c
->ts
.u
.derived
->backend_decl
== NULL
)
2635 int local_codim
= c
->attr
.codimension
? c
->as
->corank
: codimen
;
2636 c
->ts
.u
.derived
->backend_decl
= gfc_get_derived_type (c
->ts
.u
.derived
,
2640 if (c
->ts
.u
.derived
->attr
.is_iso_c
)
2642 /* Need to copy the modified ts from the derived type. The
2643 typespec was modified because C_PTR/C_FUNPTR are translated
2644 into (void *) from derived types. */
2645 c
->ts
.type
= c
->ts
.u
.derived
->ts
.type
;
2646 c
->ts
.kind
= c
->ts
.u
.derived
->ts
.kind
;
2647 c
->ts
.f90_type
= c
->ts
.u
.derived
->ts
.f90_type
;
2650 c
->initializer
->ts
.type
= c
->ts
.type
;
2651 c
->initializer
->ts
.kind
= c
->ts
.kind
;
2652 c
->initializer
->ts
.f90_type
= c
->ts
.f90_type
;
2653 c
->initializer
->expr_type
= EXPR_NULL
;
2658 if (TYPE_FIELDS (derived
->backend_decl
))
2659 return derived
->backend_decl
;
2661 /* Build the type member list. Install the newly created RECORD_TYPE
2662 node as DECL_CONTEXT of each FIELD_DECL. In this case we must go
2663 through only the top-level linked list of components so we correctly
2664 build UNION_TYPE nodes for BT_UNION components. MAPs and other nested
2665 types are built as part of gfc_get_union_type. */
2666 for (c
= derived
->components
; c
; c
= c
->next
)
2668 bool same_alloc_type
= c
->attr
.allocatable
2669 && derived
== c
->ts
.u
.derived
;
2670 /* Prevent infinite recursion, when the procedure pointer type is
2671 the same as derived, by forcing the procedure pointer component to
2672 be built as if the explicit interface does not exist. */
2673 if (c
->attr
.proc_pointer
2674 && (c
->ts
.type
!= BT_DERIVED
|| (c
->ts
.u
.derived
2675 && !gfc_compare_derived_types (derived
, c
->ts
.u
.derived
)))
2676 && (c
->ts
.type
!= BT_CLASS
|| (CLASS_DATA (c
)->ts
.u
.derived
2677 && !gfc_compare_derived_types (derived
, CLASS_DATA (c
)->ts
.u
.derived
))))
2678 field_type
= gfc_get_ppc_type (c
);
2679 else if (c
->attr
.proc_pointer
&& derived
->backend_decl
)
2681 tmp
= build_function_type_list (derived
->backend_decl
, NULL_TREE
);
2682 field_type
= build_pointer_type (tmp
);
2684 else if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
2685 field_type
= c
->ts
.u
.derived
->backend_decl
;
2686 else if (c
->attr
.caf_token
)
2687 field_type
= pvoid_type_node
;
2690 if (c
->ts
.type
== BT_CHARACTER
2691 && !c
->ts
.deferred
&& !c
->attr
.pdt_string
)
2693 /* Evaluate the string length. */
2694 gfc_conv_const_charlen (c
->ts
.u
.cl
);
2695 gcc_assert (c
->ts
.u
.cl
->backend_decl
);
2697 else if (c
->ts
.type
== BT_CHARACTER
)
2698 c
->ts
.u
.cl
->backend_decl
2699 = build_int_cst (gfc_charlen_type_node
, 0);
2701 field_type
= gfc_typenode_for_spec (&c
->ts
, codimen
);
2704 /* This returns an array descriptor type. Initialization may be
2706 if ((c
->attr
.dimension
|| c
->attr
.codimension
) && !c
->attr
.proc_pointer
)
2708 if (c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_array
)
2710 enum gfc_array_kind akind
;
2711 if (c
->attr
.pointer
)
2712 akind
= c
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2713 : GFC_ARRAY_POINTER
;
2715 akind
= GFC_ARRAY_ALLOCATABLE
;
2716 /* Pointers to arrays aren't actually pointer types. The
2717 descriptors are separate, but the data is common. */
2718 field_type
= gfc_build_array_type (field_type
, c
->as
, akind
,
2720 && !c
->attr
.pointer
,
2725 field_type
= gfc_get_nodesc_array_type (field_type
, c
->as
,
2729 else if ((c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_string
)
2730 && !c
->attr
.proc_pointer
2731 && !(unlimited_entity
&& c
== derived
->components
))
2732 field_type
= build_pointer_type (field_type
);
2734 if (c
->attr
.pointer
|| same_alloc_type
)
2735 field_type
= gfc_nonrestricted_type (field_type
);
2737 /* vtype fields can point to different types to the base type. */
2738 if (c
->ts
.type
== BT_DERIVED
2739 && c
->ts
.u
.derived
&& c
->ts
.u
.derived
->attr
.vtype
)
2740 field_type
= build_pointer_type_for_mode (TREE_TYPE (field_type
),
2743 /* Ensure that the CLASS language specific flag is set. */
2744 if (c
->ts
.type
== BT_CLASS
)
2746 if (POINTER_TYPE_P (field_type
))
2747 GFC_CLASS_TYPE_P (TREE_TYPE (field_type
)) = 1;
2749 GFC_CLASS_TYPE_P (field_type
) = 1;
2752 field
= gfc_add_field_to_struct (typenode
,
2753 get_identifier (c
->name
),
2754 field_type
, &chain
);
2756 gfc_set_decl_location (field
, &c
->loc
);
2757 else if (derived
->declared_at
.lb
)
2758 gfc_set_decl_location (field
, &derived
->declared_at
);
2760 gfc_finish_decl_attrs (field
, &c
->attr
);
2762 DECL_PACKED (field
) |= TYPE_PACKED (typenode
);
2765 if (!c
->backend_decl
)
2766 c
->backend_decl
= field
;
2768 if (c
->attr
.pointer
&& c
->attr
.dimension
2769 && !(c
->ts
.type
== BT_DERIVED
2770 && strcmp (c
->name
, "_data") == 0))
2771 GFC_DECL_PTR_ARRAY_P (c
->backend_decl
) = 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 (c
= derived
->components
; c
; c
= c
->next
)
2799 /* Do not add a caf_token field for class container components. */
2800 if ((codimen
|| coarray_flag
)
2801 && !c
->attr
.dimension
&& !c
->attr
.codimension
2802 && (c
->attr
.allocatable
|| c
->attr
.pointer
)
2803 && !derived
->attr
.is_class
)
2805 char caf_name
[GFC_MAX_SYMBOL_LEN
];
2806 gfc_component
*token
;
2807 snprintf (caf_name
, GFC_MAX_SYMBOL_LEN
, "_caf_%s", c
->name
);
2808 token
= gfc_find_component (derived
, caf_name
, true, true, NULL
);
2810 c
->caf_token
= token
->backend_decl
;
2811 TREE_NO_WARNING (c
->caf_token
) = 1;
2815 for (dt
= gfc_derived_types
; dt
; dt
= dt
->next
)
2816 gfc_copy_dt_decls_ifequal (derived
, dt
->derived
, false);
2818 return derived
->backend_decl
;
2823 gfc_return_by_reference (gfc_symbol
* sym
)
2825 if (!sym
->attr
.function
)
2828 if (sym
->attr
.dimension
)
2831 if (sym
->ts
.type
== BT_CHARACTER
2832 && !sym
->attr
.is_bind_c
2833 && (!sym
->attr
.result
2834 || !sym
->ns
->proc_name
2835 || !sym
->ns
->proc_name
->attr
.is_bind_c
))
2838 /* Possibly return complex numbers by reference for g77 compatibility.
2839 We don't do this for calls to intrinsics (as the library uses the
2840 -fno-f2c calling convention), nor for calls to functions which always
2841 require an explicit interface, as no compatibility problems can
2843 if (flag_f2c
&& sym
->ts
.type
== BT_COMPLEX
2844 && !sym
->attr
.intrinsic
&& !sym
->attr
.always_explicit
)
2851 gfc_get_mixed_entry_union (gfc_namespace
*ns
)
2855 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2856 gfc_entry_list
*el
, *el2
;
2858 gcc_assert (ns
->proc_name
->attr
.mixed_entry_master
);
2859 gcc_assert (memcmp (ns
->proc_name
->name
, "master.", 7) == 0);
2861 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "munion.%s", ns
->proc_name
->name
+ 7);
2863 /* Build the type node. */
2864 type
= make_node (UNION_TYPE
);
2866 TYPE_NAME (type
) = get_identifier (name
);
2868 for (el
= ns
->entries
; el
; el
= el
->next
)
2870 /* Search for duplicates. */
2871 for (el2
= ns
->entries
; el2
!= el
; el2
= el2
->next
)
2872 if (el2
->sym
->result
== el
->sym
->result
)
2876 gfc_add_field_to_struct_1 (type
,
2877 get_identifier (el
->sym
->result
->name
),
2878 gfc_sym_type (el
->sym
->result
), &chain
);
2881 /* Finish off the type. */
2882 gfc_finish_type (type
);
2883 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
2887 /* Create a "fn spec" based on the formal arguments;
2888 cf. create_function_arglist. */
2891 create_fn_spec (gfc_symbol
*sym
, tree fntype
)
2895 gfc_formal_arglist
*f
;
2898 memset (&spec
, 0, sizeof (spec
));
2902 if (sym
->attr
.entry_master
)
2903 spec
[spec_len
++] = 'R';
2904 if (gfc_return_by_reference (sym
))
2906 gfc_symbol
*result
= sym
->result
? sym
->result
: sym
;
2908 if (result
->attr
.pointer
|| sym
->attr
.proc_pointer
)
2909 spec
[spec_len
++] = '.';
2911 spec
[spec_len
++] = 'w';
2912 if (sym
->ts
.type
== BT_CHARACTER
)
2913 spec
[spec_len
++] = 'R';
2916 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2917 if (spec_len
< sizeof (spec
))
2919 if (!f
->sym
|| f
->sym
->attr
.pointer
|| f
->sym
->attr
.target
2920 || f
->sym
->attr
.external
|| f
->sym
->attr
.cray_pointer
2921 || (f
->sym
->ts
.type
== BT_DERIVED
2922 && (f
->sym
->ts
.u
.derived
->attr
.proc_pointer_comp
2923 || f
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
2924 || (f
->sym
->ts
.type
== BT_CLASS
2925 && (CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.proc_pointer_comp
2926 || CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.pointer_comp
)))
2927 spec
[spec_len
++] = '.';
2928 else if (f
->sym
->attr
.intent
== INTENT_IN
)
2929 spec
[spec_len
++] = 'r';
2931 spec
[spec_len
++] = 'w';
2934 tmp
= build_tree_list (NULL_TREE
, build_string (spec_len
, spec
));
2935 tmp
= tree_cons (get_identifier ("fn spec"), tmp
, TYPE_ATTRIBUTES (fntype
));
2936 return build_type_attribute_variant (fntype
, tmp
);
2941 gfc_get_function_type (gfc_symbol
* sym
)
2944 vec
<tree
, va_gc
> *typelist
= NULL
;
2945 gfc_formal_arglist
*f
;
2947 int alternate_return
= 0;
2948 bool is_varargs
= true;
2950 /* Make sure this symbol is a function, a subroutine or the main
2952 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
2953 || sym
->attr
.flavor
== FL_PROGRAM
);
2955 /* To avoid recursing infinitely on recursive types, we use error_mark_node
2956 so that they can be detected here and handled further down. */
2957 if (sym
->backend_decl
== NULL
)
2958 sym
->backend_decl
= error_mark_node
;
2959 else if (sym
->backend_decl
== error_mark_node
)
2960 goto arg_type_list_done
;
2961 else if (sym
->attr
.proc_pointer
)
2962 return TREE_TYPE (TREE_TYPE (sym
->backend_decl
));
2964 return TREE_TYPE (sym
->backend_decl
);
2966 if (sym
->attr
.entry_master
)
2967 /* Additional parameter for selecting an entry point. */
2968 vec_safe_push (typelist
, gfc_array_index_type
);
2975 if (arg
->ts
.type
== BT_CHARACTER
)
2976 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
2978 /* Some functions we use an extra parameter for the return value. */
2979 if (gfc_return_by_reference (sym
))
2981 type
= gfc_sym_type (arg
);
2982 if (arg
->ts
.type
== BT_COMPLEX
2983 || arg
->attr
.dimension
2984 || arg
->ts
.type
== BT_CHARACTER
)
2985 type
= build_reference_type (type
);
2987 vec_safe_push (typelist
, type
);
2988 if (arg
->ts
.type
== BT_CHARACTER
)
2990 if (!arg
->ts
.deferred
)
2991 /* Transfer by value. */
2992 vec_safe_push (typelist
, gfc_charlen_type_node
);
2994 /* Deferred character lengths are transferred by reference
2995 so that the value can be returned. */
2996 vec_safe_push (typelist
, build_pointer_type(gfc_charlen_type_node
));
3000 /* Build the argument types for the function. */
3001 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3006 /* Evaluate constant character lengths here so that they can be
3007 included in the type. */
3008 if (arg
->ts
.type
== BT_CHARACTER
)
3009 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
3011 if (arg
->attr
.flavor
== FL_PROCEDURE
)
3013 type
= gfc_get_function_type (arg
);
3014 type
= build_pointer_type (type
);
3017 type
= gfc_sym_type (arg
);
3019 /* Parameter Passing Convention
3021 We currently pass all parameters by reference.
3022 Parameters with INTENT(IN) could be passed by value.
3023 The problem arises if a function is called via an implicit
3024 prototype. In this situation the INTENT is not known.
3025 For this reason all parameters to global functions must be
3026 passed by reference. Passing by value would potentially
3027 generate bad code. Worse there would be no way of telling that
3028 this code was bad, except that it would give incorrect results.
3030 Contained procedures could pass by value as these are never
3031 used without an explicit interface, and cannot be passed as
3032 actual parameters for a dummy procedure. */
3034 vec_safe_push (typelist
, type
);
3038 if (sym
->attr
.subroutine
)
3039 alternate_return
= 1;
3043 /* Add hidden string length parameters. */
3044 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
3047 if (arg
&& arg
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.is_bind_c
)
3049 if (!arg
->ts
.deferred
)
3050 /* Transfer by value. */
3051 type
= gfc_charlen_type_node
;
3053 /* Deferred character lengths are transferred by reference
3054 so that the value can be returned. */
3055 type
= build_pointer_type (gfc_charlen_type_node
);
3057 vec_safe_push (typelist
, type
);
3061 if (!vec_safe_is_empty (typelist
)
3062 || sym
->attr
.is_main_program
3063 || sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
3066 if (sym
->backend_decl
== error_mark_node
)
3067 sym
->backend_decl
= NULL_TREE
;
3071 if (alternate_return
)
3072 type
= integer_type_node
;
3073 else if (!sym
->attr
.function
|| gfc_return_by_reference (sym
))
3074 type
= void_type_node
;
3075 else if (sym
->attr
.mixed_entry_master
)
3076 type
= gfc_get_mixed_entry_union (sym
->ns
);
3077 else if (flag_f2c
&& sym
->ts
.type
== BT_REAL
3078 && sym
->ts
.kind
== gfc_default_real_kind
3079 && !sym
->attr
.always_explicit
)
3081 /* Special case: f2c calling conventions require that (scalar)
3082 default REAL functions return the C type double instead. f2c
3083 compatibility is only an issue with functions that don't
3084 require an explicit interface, as only these could be
3085 implemented in Fortran 77. */
3086 sym
->ts
.kind
= gfc_default_double_kind
;
3087 type
= gfc_typenode_for_spec (&sym
->ts
);
3088 sym
->ts
.kind
= gfc_default_real_kind
;
3090 else if (sym
->result
&& sym
->result
->attr
.proc_pointer
)
3091 /* Procedure pointer return values. */
3093 if (sym
->result
->attr
.result
&& strcmp (sym
->name
,"ppr@") != 0)
3095 /* Unset proc_pointer as gfc_get_function_type
3096 is called recursively. */
3097 sym
->result
->attr
.proc_pointer
= 0;
3098 type
= build_pointer_type (gfc_get_function_type (sym
->result
));
3099 sym
->result
->attr
.proc_pointer
= 1;
3102 type
= gfc_sym_type (sym
->result
);
3105 type
= gfc_sym_type (sym
);
3108 type
= build_varargs_function_type_vec (type
, typelist
);
3110 type
= build_function_type_vec (type
, typelist
);
3111 type
= create_fn_spec (sym
, type
);
3116 /* Language hooks for middle-end access to type nodes. */
3118 /* Return an integer type with BITS bits of precision,
3119 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3122 gfc_type_for_size (unsigned bits
, int unsignedp
)
3127 for (i
= 0; i
<= MAX_INT_KINDS
; ++i
)
3129 tree type
= gfc_integer_types
[i
];
3130 if (type
&& bits
== TYPE_PRECISION (type
))
3134 /* Handle TImode as a special case because it is used by some backends
3135 (e.g. ARM) even though it is not available for normal use. */
3136 #if HOST_BITS_PER_WIDE_INT >= 64
3137 if (bits
== TYPE_PRECISION (intTI_type_node
))
3138 return intTI_type_node
;
3141 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3142 return intQI_type_node
;
3143 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3144 return intHI_type_node
;
3145 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3146 return intSI_type_node
;
3147 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3148 return intDI_type_node
;
3149 if (bits
<= TYPE_PRECISION (intTI_type_node
))
3150 return intTI_type_node
;
3154 if (bits
<= TYPE_PRECISION (unsigned_intQI_type_node
))
3155 return unsigned_intQI_type_node
;
3156 if (bits
<= TYPE_PRECISION (unsigned_intHI_type_node
))
3157 return unsigned_intHI_type_node
;
3158 if (bits
<= TYPE_PRECISION (unsigned_intSI_type_node
))
3159 return unsigned_intSI_type_node
;
3160 if (bits
<= TYPE_PRECISION (unsigned_intDI_type_node
))
3161 return unsigned_intDI_type_node
;
3162 if (bits
<= TYPE_PRECISION (unsigned_intTI_type_node
))
3163 return unsigned_intTI_type_node
;
3169 /* Return a data type that has machine mode MODE. If the mode is an
3170 integer, then UNSIGNEDP selects between signed and unsigned types. */
3173 gfc_type_for_mode (machine_mode mode
, int unsignedp
)
3177 scalar_int_mode int_mode
;
3179 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3180 base
= gfc_real_types
;
3181 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
3182 base
= gfc_complex_types
;
3183 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
3185 tree type
= gfc_type_for_size (GET_MODE_PRECISION (int_mode
), unsignedp
);
3186 return type
!= NULL_TREE
&& mode
== TYPE_MODE (type
) ? type
: NULL_TREE
;
3188 else if (VECTOR_MODE_P (mode
)
3189 && valid_vector_subparts_p (GET_MODE_NUNITS (mode
)))
3191 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3192 tree inner_type
= gfc_type_for_mode (inner_mode
, unsignedp
);
3193 if (inner_type
!= NULL_TREE
)
3194 return build_vector_type_for_mode (inner_type
, mode
);
3200 for (i
= 0; i
<= MAX_REAL_KINDS
; ++i
)
3202 tree type
= base
[i
];
3203 if (type
&& mode
== TYPE_MODE (type
))
3210 /* Return TRUE if TYPE is a type with a hidden descriptor, fill in INFO
3214 gfc_get_array_descr_info (const_tree type
, struct array_descr_info
*info
)
3217 bool indirect
= false;
3218 tree etype
, ptype
, t
, base_decl
;
3219 tree data_off
, dim_off
, dtype_off
, dim_size
, elem_size
;
3220 tree lower_suboff
, upper_suboff
, stride_suboff
;
3222 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3224 if (! POINTER_TYPE_P (type
))
3226 type
= TREE_TYPE (type
);
3227 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3232 rank
= GFC_TYPE_ARRAY_RANK (type
);
3233 if (rank
>= (int) (sizeof (info
->dimen
) / sizeof (info
->dimen
[0])))
3236 etype
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
3237 gcc_assert (POINTER_TYPE_P (etype
));
3238 etype
= TREE_TYPE (etype
);
3240 /* If the type is not a scalar coarray. */
3241 if (TREE_CODE (etype
) == ARRAY_TYPE
)
3242 etype
= TREE_TYPE (etype
);
3244 /* Can't handle variable sized elements yet. */
3245 if (int_size_in_bytes (etype
) <= 0)
3247 /* Nor non-constant lower bounds in assumed shape arrays. */
3248 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3249 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3251 for (dim
= 0; dim
< rank
; dim
++)
3252 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
3253 || TREE_CODE (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) != INTEGER_CST
)
3257 memset (info
, '\0', sizeof (*info
));
3258 info
->ndimensions
= rank
;
3259 info
->ordering
= array_descr_ordering_column_major
;
3260 info
->element_type
= etype
;
3261 ptype
= build_pointer_type (gfc_array_index_type
);
3262 base_decl
= GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
);
3265 base_decl
= make_node (DEBUG_EXPR_DECL
);
3266 DECL_ARTIFICIAL (base_decl
) = 1;
3267 TREE_TYPE (base_decl
) = indirect
? build_pointer_type (ptype
) : ptype
;
3268 SET_DECL_MODE (base_decl
, TYPE_MODE (TREE_TYPE (base_decl
)));
3269 GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
) = base_decl
;
3271 info
->base_decl
= base_decl
;
3273 base_decl
= build1 (INDIRECT_REF
, ptype
, base_decl
);
3275 elem_size
= fold_convert (gfc_array_index_type
, TYPE_SIZE_UNIT (etype
));
3277 gfc_get_descriptor_offsets_for_info (type
, &data_off
, &dtype_off
, &dim_off
,
3278 &dim_size
, &stride_suboff
,
3279 &lower_suboff
, &upper_suboff
);
3282 if (!integer_zerop (data_off
))
3283 t
= fold_build_pointer_plus (t
, data_off
);
3284 t
= build1 (NOP_EXPR
, build_pointer_type (ptr_type_node
), t
);
3285 info
->data_location
= build1 (INDIRECT_REF
, ptr_type_node
, t
);
3286 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ALLOCATABLE
)
3287 info
->allocated
= build2 (NE_EXPR
, logical_type_node
,
3288 info
->data_location
, null_pointer_node
);
3289 else if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER
3290 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER_CONT
)
3291 info
->associated
= build2 (NE_EXPR
, logical_type_node
,
3292 info
->data_location
, null_pointer_node
);
3293 if ((GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK
3294 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK_CONT
)
3295 && dwarf_version
>= 5)
3298 info
->ndimensions
= 1;
3300 if (!integer_zerop (dtype_off
))
3301 t
= fold_build_pointer_plus (t
, dtype_off
);
3302 t
= build1 (NOP_EXPR
, build_pointer_type (gfc_array_index_type
), t
);
3303 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3304 info
->rank
= build2 (BIT_AND_EXPR
, gfc_array_index_type
, t
,
3305 build_int_cst (gfc_array_index_type
,
3306 GFC_DTYPE_RANK_MASK
));
3307 t
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (dim_off
));
3308 t
= size_binop (MULT_EXPR
, t
, dim_size
);
3309 dim_off
= build2 (PLUS_EXPR
, TREE_TYPE (dim_off
), t
, dim_off
);
3312 for (dim
= 0; dim
< rank
; dim
++)
3314 t
= fold_build_pointer_plus (base_decl
,
3315 size_binop (PLUS_EXPR
,
3316 dim_off
, lower_suboff
));
3317 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3318 info
->dimen
[dim
].lower_bound
= t
;
3319 t
= fold_build_pointer_plus (base_decl
,
3320 size_binop (PLUS_EXPR
,
3321 dim_off
, upper_suboff
));
3322 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3323 info
->dimen
[dim
].upper_bound
= t
;
3324 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3325 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3327 /* Assumed shape arrays have known lower bounds. */
3328 info
->dimen
[dim
].upper_bound
3329 = build2 (MINUS_EXPR
, gfc_array_index_type
,
3330 info
->dimen
[dim
].upper_bound
,
3331 info
->dimen
[dim
].lower_bound
);
3332 info
->dimen
[dim
].lower_bound
3333 = fold_convert (gfc_array_index_type
,
3334 GFC_TYPE_ARRAY_LBOUND (type
, dim
));
3335 info
->dimen
[dim
].upper_bound
3336 = build2 (PLUS_EXPR
, gfc_array_index_type
,
3337 info
->dimen
[dim
].lower_bound
,
3338 info
->dimen
[dim
].upper_bound
);
3340 t
= fold_build_pointer_plus (base_decl
,
3341 size_binop (PLUS_EXPR
,
3342 dim_off
, stride_suboff
));
3343 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3344 t
= build2 (MULT_EXPR
, gfc_array_index_type
, t
, elem_size
);
3345 info
->dimen
[dim
].stride
= t
;
3347 dim_off
= size_binop (PLUS_EXPR
, dim_off
, dim_size
);
3354 /* Create a type to handle vector subscripts for coarray library calls. It
3356 struct caf_vector_t {
3357 size_t nvec; // size of the vector
3364 ptrdiff_t lower_bound;
3365 ptrdiff_t upper_bound;
3370 where nvec == 0 for DIMEN_ELEMENT or DIMEN_RANGE and nvec being the vector
3371 size in case of DIMEN_VECTOR, where kind is the integer type of the vector. */
3374 gfc_get_caf_vector_type (int dim
)
3376 static tree vector_types
[GFC_MAX_DIMENSIONS
];
3377 static tree vec_type
= NULL_TREE
;
3378 tree triplet_struct_type
, vect_struct_type
, union_type
, tmp
, *chain
;
3380 if (vector_types
[dim
-1] != NULL_TREE
)
3381 return vector_types
[dim
-1];
3383 if (vec_type
== NULL_TREE
)
3386 vect_struct_type
= make_node (RECORD_TYPE
);
3387 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3388 get_identifier ("vector"),
3389 pvoid_type_node
, &chain
);
3390 TREE_NO_WARNING (tmp
) = 1;
3391 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3392 get_identifier ("kind"),
3393 integer_type_node
, &chain
);
3394 TREE_NO_WARNING (tmp
) = 1;
3395 gfc_finish_type (vect_struct_type
);
3398 triplet_struct_type
= make_node (RECORD_TYPE
);
3399 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3400 get_identifier ("lower_bound"),
3401 gfc_array_index_type
, &chain
);
3402 TREE_NO_WARNING (tmp
) = 1;
3403 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3404 get_identifier ("upper_bound"),
3405 gfc_array_index_type
, &chain
);
3406 TREE_NO_WARNING (tmp
) = 1;
3407 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
, get_identifier ("stride"),
3408 gfc_array_index_type
, &chain
);
3409 TREE_NO_WARNING (tmp
) = 1;
3410 gfc_finish_type (triplet_struct_type
);
3413 union_type
= make_node (UNION_TYPE
);
3414 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3415 vect_struct_type
, &chain
);
3416 TREE_NO_WARNING (tmp
) = 1;
3417 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("triplet"),
3418 triplet_struct_type
, &chain
);
3419 TREE_NO_WARNING (tmp
) = 1;
3420 gfc_finish_type (union_type
);
3423 vec_type
= make_node (RECORD_TYPE
);
3424 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("nvec"),
3425 size_type_node
, &chain
);
3426 TREE_NO_WARNING (tmp
) = 1;
3427 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("u"),
3428 union_type
, &chain
);
3429 TREE_NO_WARNING (tmp
) = 1;
3430 gfc_finish_type (vec_type
);
3431 TYPE_NAME (vec_type
) = get_identifier ("caf_vector_t");
3434 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3435 gfc_rank_cst
[dim
-1]);
3436 vector_types
[dim
-1] = build_array_type (vec_type
, tmp
);
3437 return vector_types
[dim
-1];
3442 gfc_get_caf_reference_type ()
3444 static tree reference_type
= NULL_TREE
;
3445 tree c_struct_type
, s_struct_type
, v_struct_type
, union_type
, dim_union_type
,
3446 a_struct_type
, u_union_type
, tmp
, *chain
;
3448 if (reference_type
!= NULL_TREE
)
3449 return reference_type
;
3452 c_struct_type
= make_node (RECORD_TYPE
);
3453 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3454 get_identifier ("offset"),
3455 gfc_array_index_type
, &chain
);
3456 TREE_NO_WARNING (tmp
) = 1;
3457 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3458 get_identifier ("caf_token_offset"),
3459 gfc_array_index_type
, &chain
);
3460 TREE_NO_WARNING (tmp
) = 1;
3461 gfc_finish_type (c_struct_type
);
3464 s_struct_type
= make_node (RECORD_TYPE
);
3465 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3466 get_identifier ("start"),
3467 gfc_array_index_type
, &chain
);
3468 TREE_NO_WARNING (tmp
) = 1;
3469 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3470 get_identifier ("end"),
3471 gfc_array_index_type
, &chain
);
3472 TREE_NO_WARNING (tmp
) = 1;
3473 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3474 get_identifier ("stride"),
3475 gfc_array_index_type
, &chain
);
3476 TREE_NO_WARNING (tmp
) = 1;
3477 gfc_finish_type (s_struct_type
);
3480 v_struct_type
= make_node (RECORD_TYPE
);
3481 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3482 get_identifier ("vector"),
3483 pvoid_type_node
, &chain
);
3484 TREE_NO_WARNING (tmp
) = 1;
3485 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3486 get_identifier ("nvec"),
3487 size_type_node
, &chain
);
3488 TREE_NO_WARNING (tmp
) = 1;
3489 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3490 get_identifier ("kind"),
3491 integer_type_node
, &chain
);
3492 TREE_NO_WARNING (tmp
) = 1;
3493 gfc_finish_type (v_struct_type
);
3496 union_type
= make_node (UNION_TYPE
);
3497 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("s"),
3498 s_struct_type
, &chain
);
3499 TREE_NO_WARNING (tmp
) = 1;
3500 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3501 v_struct_type
, &chain
);
3502 TREE_NO_WARNING (tmp
) = 1;
3503 gfc_finish_type (union_type
);
3505 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3506 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1]);
3507 dim_union_type
= build_array_type (union_type
, tmp
);
3510 a_struct_type
= make_node (RECORD_TYPE
);
3511 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("mode"),
3512 build_array_type (unsigned_char_type_node
,
3513 build_range_type (gfc_array_index_type
,
3514 gfc_index_zero_node
,
3515 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1])),
3517 TREE_NO_WARNING (tmp
) = 1;
3518 tmp
= gfc_add_field_to_struct_1 (a_struct_type
,
3519 get_identifier ("static_array_type"),
3520 integer_type_node
, &chain
);
3521 TREE_NO_WARNING (tmp
) = 1;
3522 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("dim"),
3523 dim_union_type
, &chain
);
3524 TREE_NO_WARNING (tmp
) = 1;
3525 gfc_finish_type (a_struct_type
);
3528 u_union_type
= make_node (UNION_TYPE
);
3529 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("c"),
3530 c_struct_type
, &chain
);
3531 TREE_NO_WARNING (tmp
) = 1;
3532 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("a"),
3533 a_struct_type
, &chain
);
3534 TREE_NO_WARNING (tmp
) = 1;
3535 gfc_finish_type (u_union_type
);
3538 reference_type
= make_node (RECORD_TYPE
);
3539 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("next"),
3540 build_pointer_type (reference_type
), &chain
);
3541 TREE_NO_WARNING (tmp
) = 1;
3542 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("type"),
3543 integer_type_node
, &chain
);
3544 TREE_NO_WARNING (tmp
) = 1;
3545 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("item_size"),
3546 size_type_node
, &chain
);
3547 TREE_NO_WARNING (tmp
) = 1;
3548 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("u"),
3549 u_union_type
, &chain
);
3550 TREE_NO_WARNING (tmp
) = 1;
3551 gfc_finish_type (reference_type
);
3552 TYPE_NAME (reference_type
) = get_identifier ("caf_reference_t");
3554 return reference_type
;
3557 #include "gt-fortran-trans-types.h"