1 /* Backend support for Fortran 95 basic types and derived types.
2 Copyright (C) 2002-2017 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
4 and Steven Bosscher <s.bosscher@student.tudelft.nl>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 /* trans-types.c -- gfortran backend types */
26 #include "coretypes.h"
31 #include "stringpool.h"
32 #include "fold-const.h"
33 #include "stor-layout.h"
34 #include "langhooks.h" /* For iso-c-bindings.def. */
35 #include "toplev.h" /* For rest_of_decl_compilation. */
36 #include "trans-types.h"
37 #include "trans-const.h"
38 #include "trans-array.h"
39 #include "dwarf2out.h" /* For struct array_descr_info. */
43 #if (GFC_MAX_DIMENSIONS < 10)
44 #define GFC_RANK_DIGITS 1
45 #define GFC_RANK_PRINTF_FORMAT "%01d"
46 #elif (GFC_MAX_DIMENSIONS < 100)
47 #define GFC_RANK_DIGITS 2
48 #define GFC_RANK_PRINTF_FORMAT "%02d"
50 #error If you really need >99 dimensions, continue the sequence above...
53 /* array of structs so we don't have to worry about xmalloc or free */
54 CInteropKind_t c_interop_kinds_table
[ISOCBINDING_NUMBER
];
56 tree gfc_array_index_type
;
57 tree gfc_array_range_type
;
58 tree gfc_character1_type_node
;
60 tree prvoid_type_node
;
61 tree ppvoid_type_node
;
65 tree gfc_charlen_type_node
;
67 tree gfc_float128_type_node
= NULL_TREE
;
68 tree gfc_complex_float128_type_node
= NULL_TREE
;
70 bool gfc_real16_is_float128
= false;
72 static GTY(()) tree gfc_desc_dim_type
;
73 static GTY(()) tree gfc_max_array_element_size
;
74 static GTY(()) tree gfc_array_descriptor_base
[2 * (GFC_MAX_DIMENSIONS
+1)];
75 static GTY(()) tree gfc_array_descriptor_base_caf
[2 * (GFC_MAX_DIMENSIONS
+1)];
77 /* Arrays for all integral and real kinds. We'll fill this in at runtime
78 after the target has a chance to process command-line options. */
80 #define MAX_INT_KINDS 5
81 gfc_integer_info gfc_integer_kinds
[MAX_INT_KINDS
+ 1];
82 gfc_logical_info gfc_logical_kinds
[MAX_INT_KINDS
+ 1];
83 static GTY(()) tree gfc_integer_types
[MAX_INT_KINDS
+ 1];
84 static GTY(()) tree gfc_logical_types
[MAX_INT_KINDS
+ 1];
86 #define MAX_REAL_KINDS 5
87 gfc_real_info gfc_real_kinds
[MAX_REAL_KINDS
+ 1];
88 static GTY(()) tree gfc_real_types
[MAX_REAL_KINDS
+ 1];
89 static GTY(()) tree gfc_complex_types
[MAX_REAL_KINDS
+ 1];
91 #define MAX_CHARACTER_KINDS 2
92 gfc_character_info gfc_character_kinds
[MAX_CHARACTER_KINDS
+ 1];
93 static GTY(()) tree gfc_character_types
[MAX_CHARACTER_KINDS
+ 1];
94 static GTY(()) tree gfc_pcharacter_types
[MAX_CHARACTER_KINDS
+ 1];
96 static tree
gfc_add_field_to_struct_1 (tree
, tree
, tree
, tree
**);
98 /* The integer kind to use for array indices. This will be set to the
99 proper value based on target information from the backend. */
101 int gfc_index_integer_kind
;
103 /* The default kinds of the various types. */
105 int gfc_default_integer_kind
;
106 int gfc_max_integer_kind
;
107 int gfc_default_real_kind
;
108 int gfc_default_double_kind
;
109 int gfc_default_character_kind
;
110 int gfc_default_logical_kind
;
111 int gfc_default_complex_kind
;
113 int gfc_atomic_int_kind
;
114 int gfc_atomic_logical_kind
;
116 /* The kind size used for record offsets. If the target system supports
117 kind=8, this will be set to 8, otherwise it is set to 4. */
120 /* The integer kind used to store character lengths. */
121 int gfc_charlen_int_kind
;
123 /* The size of the numeric storage unit and character storage unit. */
124 int gfc_numeric_storage_size
;
125 int gfc_character_storage_size
;
129 gfc_check_any_c_kind (gfc_typespec
*ts
)
133 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
135 /* Check for any C interoperable kind for the given type/kind in ts.
136 This can be used after verify_c_interop to make sure that the
137 Fortran kind being used exists in at least some form for C. */
138 if (c_interop_kinds_table
[i
].f90_type
== ts
->type
&&
139 c_interop_kinds_table
[i
].value
== ts
->kind
)
148 get_real_kind_from_node (tree type
)
152 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
153 if (gfc_real_kinds
[i
].mode_precision
== TYPE_PRECISION (type
))
154 return gfc_real_kinds
[i
].kind
;
160 get_int_kind_from_node (tree type
)
167 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
168 if (gfc_integer_kinds
[i
].bit_size
== TYPE_PRECISION (type
))
169 return gfc_integer_kinds
[i
].kind
;
174 /* Return a typenode for the "standard" C type with a given name. */
176 get_typenode_from_name (const char *name
)
178 if (name
== NULL
|| *name
== '\0')
181 if (strcmp (name
, "char") == 0)
182 return char_type_node
;
183 if (strcmp (name
, "unsigned char") == 0)
184 return unsigned_char_type_node
;
185 if (strcmp (name
, "signed char") == 0)
186 return signed_char_type_node
;
188 if (strcmp (name
, "short int") == 0)
189 return short_integer_type_node
;
190 if (strcmp (name
, "short unsigned int") == 0)
191 return short_unsigned_type_node
;
193 if (strcmp (name
, "int") == 0)
194 return integer_type_node
;
195 if (strcmp (name
, "unsigned int") == 0)
196 return unsigned_type_node
;
198 if (strcmp (name
, "long int") == 0)
199 return long_integer_type_node
;
200 if (strcmp (name
, "long unsigned int") == 0)
201 return long_unsigned_type_node
;
203 if (strcmp (name
, "long long int") == 0)
204 return long_long_integer_type_node
;
205 if (strcmp (name
, "long long unsigned int") == 0)
206 return long_long_unsigned_type_node
;
212 get_int_kind_from_name (const char *name
)
214 return get_int_kind_from_node (get_typenode_from_name (name
));
218 /* Get the kind number corresponding to an integer of given size,
219 following the required return values for ISO_FORTRAN_ENV INT* constants:
220 -2 is returned if we support a kind of larger size, -1 otherwise. */
222 gfc_get_int_kind_from_width_isofortranenv (int size
)
226 /* Look for a kind with matching storage size. */
227 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
228 if (gfc_integer_kinds
[i
].bit_size
== size
)
229 return gfc_integer_kinds
[i
].kind
;
231 /* Look for a kind with larger storage size. */
232 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
233 if (gfc_integer_kinds
[i
].bit_size
> size
)
240 /* Get the kind number corresponding to a real of a given storage size.
241 If two real's have the same storage size, then choose the real with
242 the largest precision. If a kind type is unavailable and a real
243 exists with wider storage, then return -2; otherwise, return -1. */
246 gfc_get_real_kind_from_width_isofortranenv (int size
)
255 /* Look for a kind with matching storage size. */
256 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
257 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) == size
)
259 if (gfc_real_kinds
[i
].digits
> digits
)
261 digits
= gfc_real_kinds
[i
].digits
;
262 kind
= gfc_real_kinds
[i
].kind
;
269 /* Look for a kind with larger storage size. */
270 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
271 if (int_size_in_bytes (gfc_get_real_type (gfc_real_kinds
[i
].kind
)) > size
)
280 get_int_kind_from_width (int size
)
284 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
285 if (gfc_integer_kinds
[i
].bit_size
== size
)
286 return gfc_integer_kinds
[i
].kind
;
292 get_int_kind_from_minimal_width (int size
)
296 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
297 if (gfc_integer_kinds
[i
].bit_size
>= size
)
298 return gfc_integer_kinds
[i
].kind
;
304 /* Generate the CInteropKind_t objects for the C interoperable
308 gfc_init_c_interop_kinds (void)
312 /* init all pointers in the list to NULL */
313 for (i
= 0; i
< ISOCBINDING_NUMBER
; i
++)
315 /* Initialize the name and value fields. */
316 c_interop_kinds_table
[i
].name
[0] = '\0';
317 c_interop_kinds_table
[i
].value
= -100;
318 c_interop_kinds_table
[i
].f90_type
= BT_UNKNOWN
;
321 #define NAMED_INTCST(a,b,c,d) \
322 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
323 c_interop_kinds_table[a].f90_type = BT_INTEGER; \
324 c_interop_kinds_table[a].value = c;
325 #define NAMED_REALCST(a,b,c,d) \
326 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
327 c_interop_kinds_table[a].f90_type = BT_REAL; \
328 c_interop_kinds_table[a].value = c;
329 #define NAMED_CMPXCST(a,b,c,d) \
330 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
331 c_interop_kinds_table[a].f90_type = BT_COMPLEX; \
332 c_interop_kinds_table[a].value = c;
333 #define NAMED_LOGCST(a,b,c) \
334 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
335 c_interop_kinds_table[a].f90_type = BT_LOGICAL; \
336 c_interop_kinds_table[a].value = c;
337 #define NAMED_CHARKNDCST(a,b,c) \
338 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
339 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
340 c_interop_kinds_table[a].value = c;
341 #define NAMED_CHARCST(a,b,c) \
342 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
343 c_interop_kinds_table[a].f90_type = BT_CHARACTER; \
344 c_interop_kinds_table[a].value = c;
345 #define DERIVED_TYPE(a,b,c) \
346 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
347 c_interop_kinds_table[a].f90_type = BT_DERIVED; \
348 c_interop_kinds_table[a].value = c;
349 #define NAMED_FUNCTION(a,b,c,d) \
350 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
351 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
352 c_interop_kinds_table[a].value = c;
353 #define NAMED_SUBROUTINE(a,b,c,d) \
354 strncpy (c_interop_kinds_table[a].name, b, strlen(b) + 1); \
355 c_interop_kinds_table[a].f90_type = BT_PROCEDURE; \
356 c_interop_kinds_table[a].value = c;
357 #include "iso-c-binding.def"
361 /* Query the target to determine which machine modes are available for
362 computation. Choose KIND numbers for them. */
365 gfc_init_kinds (void)
367 opt_scalar_int_mode int_mode_iter
;
368 opt_scalar_float_mode float_mode_iter
;
369 int i_index
, r_index
, kind
;
370 bool saw_i4
= false, saw_i8
= false;
371 bool saw_r4
= false, saw_r8
= false, saw_r10
= false, saw_r16
= false;
374 FOR_EACH_MODE_IN_CLASS (int_mode_iter
, MODE_INT
)
376 scalar_int_mode mode
= int_mode_iter
.require ();
379 if (!targetm
.scalar_mode_supported_p (mode
))
382 /* The middle end doesn't support constants larger than 2*HWI.
383 Perhaps the target hook shouldn't have accepted these either,
384 but just to be safe... */
385 bitsize
= GET_MODE_BITSIZE (mode
);
386 if (bitsize
> 2*HOST_BITS_PER_WIDE_INT
)
389 gcc_assert (i_index
!= MAX_INT_KINDS
);
391 /* Let the kind equal the bit size divided by 8. This insulates the
392 programmer from the underlying byte size. */
400 gfc_integer_kinds
[i_index
].kind
= kind
;
401 gfc_integer_kinds
[i_index
].radix
= 2;
402 gfc_integer_kinds
[i_index
].digits
= bitsize
- 1;
403 gfc_integer_kinds
[i_index
].bit_size
= bitsize
;
405 gfc_logical_kinds
[i_index
].kind
= kind
;
406 gfc_logical_kinds
[i_index
].bit_size
= bitsize
;
411 /* Set the kind used to match GFC_INT_IO in libgfortran. This is
412 used for large file access. */
419 /* If we do not at least have kind = 4, everything is pointless. */
422 /* Set the maximum integer kind. Used with at least BOZ constants. */
423 gfc_max_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
426 FOR_EACH_MODE_IN_CLASS (float_mode_iter
, MODE_FLOAT
)
428 scalar_float_mode mode
= float_mode_iter
.require ();
429 const struct real_format
*fmt
= REAL_MODE_FORMAT (mode
);
434 if (!targetm
.scalar_mode_supported_p (mode
))
437 /* Only let float, double, long double and __float128 go through.
438 Runtime support for others is not provided, so they would be
440 if (!targetm
.libgcc_floating_mode_supported_p (mode
))
442 if (mode
!= TYPE_MODE (float_type_node
)
443 && (mode
!= TYPE_MODE (double_type_node
))
444 && (mode
!= TYPE_MODE (long_double_type_node
))
445 #if defined(HAVE_TFmode) && defined(ENABLE_LIBQUADMATH_SUPPORT)
451 /* Let the kind equal the precision divided by 8, rounding up. Again,
452 this insulates the programmer from the underlying byte size.
454 Also, it effectively deals with IEEE extended formats. There, the
455 total size of the type may equal 16, but it's got 6 bytes of padding
456 and the increased size can get in the way of a real IEEE quad format
457 which may also be supported by the target.
459 We round up so as to handle IA-64 __floatreg (RFmode), which is an
460 82 bit type. Not to be confused with __float80 (XFmode), which is
461 an 80 bit type also supported by IA-64. So XFmode should come out
462 to be kind=10, and RFmode should come out to be kind=11. Egads. */
464 kind
= (GET_MODE_PRECISION (mode
) + 7) / 8;
475 /* Careful we don't stumble a weird internal mode. */
476 gcc_assert (r_index
<= 0 || gfc_real_kinds
[r_index
-1].kind
!= kind
);
477 /* Or have too many modes for the allocated space. */
478 gcc_assert (r_index
!= MAX_REAL_KINDS
);
480 gfc_real_kinds
[r_index
].kind
= kind
;
481 gfc_real_kinds
[r_index
].radix
= fmt
->b
;
482 gfc_real_kinds
[r_index
].digits
= fmt
->p
;
483 gfc_real_kinds
[r_index
].min_exponent
= fmt
->emin
;
484 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
;
485 if (fmt
->pnan
< fmt
->p
)
486 /* This is an IBM extended double format (or the MIPS variant)
487 made up of two IEEE doubles. The value of the long double is
488 the sum of the values of the two parts. The most significant
489 part is required to be the value of the long double rounded
490 to the nearest double. If we use emax of 1024 then we can't
491 represent huge(x) = (1 - b**(-p)) * b**(emax-1) * b, because
492 rounding will make the most significant part overflow. */
493 gfc_real_kinds
[r_index
].max_exponent
= fmt
->emax
- 1;
494 gfc_real_kinds
[r_index
].mode_precision
= GET_MODE_PRECISION (mode
);
498 /* Choose the default integer kind. We choose 4 unless the user directs us
499 otherwise. Even if the user specified that the default integer kind is 8,
500 the numeric storage size is not 64 bits. In this case, a warning will be
501 issued when NUMERIC_STORAGE_SIZE is used. Set NUMERIC_STORAGE_SIZE to 32. */
503 gfc_numeric_storage_size
= 4 * 8;
505 if (flag_default_integer
)
508 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
509 "%<-fdefault-integer-8%> option");
511 gfc_default_integer_kind
= 8;
514 else if (flag_integer4_kind
== 8)
517 gfc_fatal_error ("INTEGER(KIND=8) is not available for "
518 "%<-finteger-4-integer-8%> option");
520 gfc_default_integer_kind
= 8;
524 gfc_default_integer_kind
= 4;
528 gfc_default_integer_kind
= gfc_integer_kinds
[i_index
- 1].kind
;
529 gfc_numeric_storage_size
= gfc_integer_kinds
[i_index
- 1].bit_size
;
532 /* Choose the default real kind. Again, we choose 4 when possible. */
533 if (flag_default_real
)
536 gfc_fatal_error ("REAL(KIND=8) is not available for "
537 "%<-fdefault-real-8%> option");
539 gfc_default_real_kind
= 8;
541 else if (flag_real4_kind
== 8)
544 gfc_fatal_error ("REAL(KIND=8) is not available for %<-freal-4-real-8%> "
547 gfc_default_real_kind
= 8;
549 else if (flag_real4_kind
== 10)
552 gfc_fatal_error ("REAL(KIND=10) is not available for "
553 "%<-freal-4-real-10%> option");
555 gfc_default_real_kind
= 10;
557 else if (flag_real4_kind
== 16)
560 gfc_fatal_error ("REAL(KIND=16) is not available for "
561 "%<-freal-4-real-16%> option");
563 gfc_default_real_kind
= 16;
566 gfc_default_real_kind
= 4;
568 gfc_default_real_kind
= gfc_real_kinds
[0].kind
;
570 /* Choose the default double kind. If -fdefault-real and -fdefault-double
571 are specified, we use kind=8, if it's available. If -fdefault-real is
572 specified without -fdefault-double, we use kind=16, if it's available.
573 Otherwise we do not change anything. */
574 if (flag_default_double
&& !flag_default_real
)
575 gfc_fatal_error ("Use of %<-fdefault-double-8%> requires "
576 "%<-fdefault-real-8%>");
578 if (flag_default_real
&& flag_default_double
&& saw_r8
)
579 gfc_default_double_kind
= 8;
580 else if (flag_default_real
&& saw_r16
)
581 gfc_default_double_kind
= 16;
582 else if (flag_real8_kind
== 4)
585 gfc_fatal_error ("REAL(KIND=4) is not available for "
586 "%<-freal-8-real-4%> option");
588 gfc_default_double_kind
= 4;
590 else if (flag_real8_kind
== 10 )
593 gfc_fatal_error ("REAL(KIND=10) is not available for "
594 "%<-freal-8-real-10%> option");
596 gfc_default_double_kind
= 10;
598 else if (flag_real8_kind
== 16 )
601 gfc_fatal_error ("REAL(KIND=10) is not available for "
602 "%<-freal-8-real-16%> option");
604 gfc_default_double_kind
= 16;
606 else if (saw_r4
&& saw_r8
)
607 gfc_default_double_kind
= 8;
610 /* F95 14.6.3.1: A nonpointer scalar object of type double precision
611 real ... occupies two contiguous numeric storage units.
613 Therefore we must be supplied a kind twice as large as we chose
614 for single precision. There are loopholes, in that double
615 precision must *occupy* two storage units, though it doesn't have
616 to *use* two storage units. Which means that you can make this
617 kind artificially wide by padding it. But at present there are
618 no GCC targets for which a two-word type does not exist, so we
619 just let gfc_validate_kind abort and tell us if something breaks. */
621 gfc_default_double_kind
622 = gfc_validate_kind (BT_REAL
, gfc_default_real_kind
* 2, false);
625 /* The default logical kind is constrained to be the same as the
626 default integer kind. Similarly with complex and real. */
627 gfc_default_logical_kind
= gfc_default_integer_kind
;
628 gfc_default_complex_kind
= gfc_default_real_kind
;
630 /* We only have two character kinds: ASCII and UCS-4.
631 ASCII corresponds to a 8-bit integer type, if one is available.
632 UCS-4 corresponds to a 32-bit integer type, if one is available. */
634 if ((kind
= get_int_kind_from_width (8)) > 0)
636 gfc_character_kinds
[i_index
].kind
= kind
;
637 gfc_character_kinds
[i_index
].bit_size
= 8;
638 gfc_character_kinds
[i_index
].name
= "ascii";
641 if ((kind
= get_int_kind_from_width (32)) > 0)
643 gfc_character_kinds
[i_index
].kind
= kind
;
644 gfc_character_kinds
[i_index
].bit_size
= 32;
645 gfc_character_kinds
[i_index
].name
= "iso_10646";
649 /* Choose the smallest integer kind for our default character. */
650 gfc_default_character_kind
= gfc_character_kinds
[0].kind
;
651 gfc_character_storage_size
= gfc_default_character_kind
* 8;
653 gfc_index_integer_kind
= get_int_kind_from_name (PTRDIFF_TYPE
);
655 /* Pick a kind the same size as the C "int" type. */
656 gfc_c_int_kind
= INT_TYPE_SIZE
/ 8;
658 /* Choose atomic kinds to match C's int. */
659 gfc_atomic_int_kind
= gfc_c_int_kind
;
660 gfc_atomic_logical_kind
= gfc_c_int_kind
;
664 /* Make sure that a valid kind is present. Returns an index into the
665 associated kinds array, -1 if the kind is not present. */
668 validate_integer (int kind
)
672 for (i
= 0; gfc_integer_kinds
[i
].kind
!= 0; i
++)
673 if (gfc_integer_kinds
[i
].kind
== kind
)
680 validate_real (int kind
)
684 for (i
= 0; gfc_real_kinds
[i
].kind
!= 0; i
++)
685 if (gfc_real_kinds
[i
].kind
== kind
)
692 validate_logical (int kind
)
696 for (i
= 0; gfc_logical_kinds
[i
].kind
; i
++)
697 if (gfc_logical_kinds
[i
].kind
== kind
)
704 validate_character (int kind
)
708 for (i
= 0; gfc_character_kinds
[i
].kind
; i
++)
709 if (gfc_character_kinds
[i
].kind
== kind
)
715 /* Validate a kind given a basic type. The return value is the same
716 for the child functions, with -1 indicating nonexistence of the
717 type. If MAY_FAIL is false, then -1 is never returned, and we ICE. */
720 gfc_validate_kind (bt type
, int kind
, bool may_fail
)
726 case BT_REAL
: /* Fall through */
728 rc
= validate_real (kind
);
731 rc
= validate_integer (kind
);
734 rc
= validate_logical (kind
);
737 rc
= validate_character (kind
);
741 gfc_internal_error ("gfc_validate_kind(): Got bad type");
744 if (rc
< 0 && !may_fail
)
745 gfc_internal_error ("gfc_validate_kind(): Got bad kind");
751 /* Four subroutines of gfc_init_types. Create type nodes for the given kind.
752 Reuse common type nodes where possible. Recognize if the kind matches up
753 with a C type. This will be used later in determining which routines may
754 be scarfed from libm. */
757 gfc_build_int_type (gfc_integer_info
*info
)
759 int mode_precision
= info
->bit_size
;
761 if (mode_precision
== CHAR_TYPE_SIZE
)
763 if (mode_precision
== SHORT_TYPE_SIZE
)
765 if (mode_precision
== INT_TYPE_SIZE
)
767 if (mode_precision
== LONG_TYPE_SIZE
)
769 if (mode_precision
== LONG_LONG_TYPE_SIZE
)
770 info
->c_long_long
= 1;
772 if (TYPE_PRECISION (intQI_type_node
) == mode_precision
)
773 return intQI_type_node
;
774 if (TYPE_PRECISION (intHI_type_node
) == mode_precision
)
775 return intHI_type_node
;
776 if (TYPE_PRECISION (intSI_type_node
) == mode_precision
)
777 return intSI_type_node
;
778 if (TYPE_PRECISION (intDI_type_node
) == mode_precision
)
779 return intDI_type_node
;
780 if (TYPE_PRECISION (intTI_type_node
) == mode_precision
)
781 return intTI_type_node
;
783 return make_signed_type (mode_precision
);
787 gfc_build_uint_type (int size
)
789 if (size
== CHAR_TYPE_SIZE
)
790 return unsigned_char_type_node
;
791 if (size
== SHORT_TYPE_SIZE
)
792 return short_unsigned_type_node
;
793 if (size
== INT_TYPE_SIZE
)
794 return unsigned_type_node
;
795 if (size
== LONG_TYPE_SIZE
)
796 return long_unsigned_type_node
;
797 if (size
== LONG_LONG_TYPE_SIZE
)
798 return long_long_unsigned_type_node
;
800 return make_unsigned_type (size
);
805 gfc_build_real_type (gfc_real_info
*info
)
807 int mode_precision
= info
->mode_precision
;
810 if (mode_precision
== FLOAT_TYPE_SIZE
)
812 if (mode_precision
== DOUBLE_TYPE_SIZE
)
814 if (mode_precision
== LONG_DOUBLE_TYPE_SIZE
)
815 info
->c_long_double
= 1;
816 if (mode_precision
!= LONG_DOUBLE_TYPE_SIZE
&& mode_precision
== 128)
818 info
->c_float128
= 1;
819 gfc_real16_is_float128
= true;
822 if (TYPE_PRECISION (float_type_node
) == mode_precision
)
823 return float_type_node
;
824 if (TYPE_PRECISION (double_type_node
) == mode_precision
)
825 return double_type_node
;
826 if (TYPE_PRECISION (long_double_type_node
) == mode_precision
)
827 return long_double_type_node
;
829 new_type
= make_node (REAL_TYPE
);
830 TYPE_PRECISION (new_type
) = mode_precision
;
831 layout_type (new_type
);
836 gfc_build_complex_type (tree scalar_type
)
840 if (scalar_type
== NULL
)
842 if (scalar_type
== float_type_node
)
843 return complex_float_type_node
;
844 if (scalar_type
== double_type_node
)
845 return complex_double_type_node
;
846 if (scalar_type
== long_double_type_node
)
847 return complex_long_double_type_node
;
849 new_type
= make_node (COMPLEX_TYPE
);
850 TREE_TYPE (new_type
) = scalar_type
;
851 layout_type (new_type
);
856 gfc_build_logical_type (gfc_logical_info
*info
)
858 int bit_size
= info
->bit_size
;
861 if (bit_size
== BOOL_TYPE_SIZE
)
864 return boolean_type_node
;
867 new_type
= make_unsigned_type (bit_size
);
868 TREE_SET_CODE (new_type
, BOOLEAN_TYPE
);
869 TYPE_MAX_VALUE (new_type
) = build_int_cst (new_type
, 1);
870 TYPE_PRECISION (new_type
) = 1;
876 /* Create the backend type nodes. We map them to their
877 equivalent C type, at least for now. We also give
878 names to the types here, and we push them in the
879 global binding level context.*/
882 gfc_init_types (void)
889 /* Create and name the types. */
890 #define PUSH_TYPE(name, node) \
891 pushdecl (build_decl (input_location, \
892 TYPE_DECL, get_identifier (name), node))
894 for (index
= 0; gfc_integer_kinds
[index
].kind
!= 0; ++index
)
896 type
= gfc_build_int_type (&gfc_integer_kinds
[index
]);
897 /* Ensure integer(kind=1) doesn't have TYPE_STRING_FLAG set. */
898 if (TYPE_STRING_FLAG (type
))
899 type
= make_signed_type (gfc_integer_kinds
[index
].bit_size
);
900 gfc_integer_types
[index
] = type
;
901 snprintf (name_buf
, sizeof(name_buf
), "integer(kind=%d)",
902 gfc_integer_kinds
[index
].kind
);
903 PUSH_TYPE (name_buf
, type
);
906 for (index
= 0; gfc_logical_kinds
[index
].kind
!= 0; ++index
)
908 type
= gfc_build_logical_type (&gfc_logical_kinds
[index
]);
909 gfc_logical_types
[index
] = type
;
910 snprintf (name_buf
, sizeof(name_buf
), "logical(kind=%d)",
911 gfc_logical_kinds
[index
].kind
);
912 PUSH_TYPE (name_buf
, type
);
915 for (index
= 0; gfc_real_kinds
[index
].kind
!= 0; index
++)
917 type
= gfc_build_real_type (&gfc_real_kinds
[index
]);
918 gfc_real_types
[index
] = type
;
919 snprintf (name_buf
, sizeof(name_buf
), "real(kind=%d)",
920 gfc_real_kinds
[index
].kind
);
921 PUSH_TYPE (name_buf
, type
);
923 if (gfc_real_kinds
[index
].c_float128
)
924 gfc_float128_type_node
= type
;
926 type
= gfc_build_complex_type (type
);
927 gfc_complex_types
[index
] = type
;
928 snprintf (name_buf
, sizeof(name_buf
), "complex(kind=%d)",
929 gfc_real_kinds
[index
].kind
);
930 PUSH_TYPE (name_buf
, type
);
932 if (gfc_real_kinds
[index
].c_float128
)
933 gfc_complex_float128_type_node
= type
;
936 for (index
= 0; gfc_character_kinds
[index
].kind
!= 0; ++index
)
938 type
= gfc_build_uint_type (gfc_character_kinds
[index
].bit_size
);
939 type
= build_qualified_type (type
, TYPE_UNQUALIFIED
);
940 snprintf (name_buf
, sizeof(name_buf
), "character(kind=%d)",
941 gfc_character_kinds
[index
].kind
);
942 PUSH_TYPE (name_buf
, type
);
943 gfc_character_types
[index
] = type
;
944 gfc_pcharacter_types
[index
] = build_pointer_type (type
);
946 gfc_character1_type_node
= gfc_character_types
[0];
948 PUSH_TYPE ("byte", unsigned_char_type_node
);
949 PUSH_TYPE ("void", void_type_node
);
951 /* DBX debugging output gets upset if these aren't set. */
952 if (!TYPE_NAME (integer_type_node
))
953 PUSH_TYPE ("c_integer", integer_type_node
);
954 if (!TYPE_NAME (char_type_node
))
955 PUSH_TYPE ("c_char", char_type_node
);
959 pvoid_type_node
= build_pointer_type (void_type_node
);
960 prvoid_type_node
= build_qualified_type (pvoid_type_node
, TYPE_QUAL_RESTRICT
);
961 ppvoid_type_node
= build_pointer_type (pvoid_type_node
);
962 pchar_type_node
= build_pointer_type (gfc_character1_type_node
);
964 = build_pointer_type (build_function_type_list (void_type_node
, NULL_TREE
));
966 gfc_array_index_type
= gfc_get_int_type (gfc_index_integer_kind
);
967 /* We cannot use gfc_index_zero_node in definition of gfc_array_range_type,
968 since this function is called before gfc_init_constants. */
970 = build_range_type (gfc_array_index_type
,
971 build_int_cst (gfc_array_index_type
, 0),
974 /* The maximum array element size that can be handled is determined
975 by the number of bits available to store this field in the array
978 n
= TYPE_PRECISION (gfc_array_index_type
) - GFC_DTYPE_SIZE_SHIFT
;
979 gfc_max_array_element_size
980 = wide_int_to_tree (size_type_node
,
981 wi::mask (n
, UNSIGNED
,
982 TYPE_PRECISION (size_type_node
)));
984 /* ??? Shouldn't this be based on gfc_index_integer_kind or so? */
985 gfc_charlen_int_kind
= 4;
986 gfc_charlen_type_node
= gfc_get_int_type (gfc_charlen_int_kind
);
989 /* Get the type node for the given type and kind. */
992 gfc_get_int_type (int kind
)
994 int index
= gfc_validate_kind (BT_INTEGER
, kind
, true);
995 return index
< 0 ? 0 : gfc_integer_types
[index
];
999 gfc_get_real_type (int kind
)
1001 int index
= gfc_validate_kind (BT_REAL
, kind
, true);
1002 return index
< 0 ? 0 : gfc_real_types
[index
];
1006 gfc_get_complex_type (int kind
)
1008 int index
= gfc_validate_kind (BT_COMPLEX
, kind
, true);
1009 return index
< 0 ? 0 : gfc_complex_types
[index
];
1013 gfc_get_logical_type (int kind
)
1015 int index
= gfc_validate_kind (BT_LOGICAL
, kind
, true);
1016 return index
< 0 ? 0 : gfc_logical_types
[index
];
1020 gfc_get_char_type (int kind
)
1022 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1023 return index
< 0 ? 0 : gfc_character_types
[index
];
1027 gfc_get_pchar_type (int kind
)
1029 int index
= gfc_validate_kind (BT_CHARACTER
, kind
, true);
1030 return index
< 0 ? 0 : gfc_pcharacter_types
[index
];
1034 /* Create a character type with the given kind and length. */
1037 gfc_get_character_type_len_for_eltype (tree eltype
, tree len
)
1041 bounds
= build_range_type (gfc_charlen_type_node
, gfc_index_one_node
, len
);
1042 type
= build_array_type (eltype
, bounds
);
1043 TYPE_STRING_FLAG (type
) = 1;
1049 gfc_get_character_type_len (int kind
, tree len
)
1051 gfc_validate_kind (BT_CHARACTER
, kind
, false);
1052 return gfc_get_character_type_len_for_eltype (gfc_get_char_type (kind
), len
);
1056 /* Get a type node for a character kind. */
1059 gfc_get_character_type (int kind
, gfc_charlen
* cl
)
1063 len
= (cl
== NULL
) ? NULL_TREE
: cl
->backend_decl
;
1064 if (len
&& POINTER_TYPE_P (TREE_TYPE (len
)))
1065 len
= build_fold_indirect_ref (len
);
1067 return gfc_get_character_type_len (kind
, len
);
1070 /* Convert a basic type. This will be an array for character types. */
1073 gfc_typenode_for_spec (gfc_typespec
* spec
, int codim
)
1083 /* We use INTEGER(c_intptr_t) for C_PTR and C_FUNPTR once the symbol
1084 has been resolved. This is done so we can convert C_PTR and
1085 C_FUNPTR to simple variables that get translated to (void *). */
1086 if (spec
->f90_type
== BT_VOID
)
1089 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1090 basetype
= ptr_type_node
;
1092 basetype
= pfunc_type_node
;
1095 basetype
= gfc_get_int_type (spec
->kind
);
1099 basetype
= gfc_get_real_type (spec
->kind
);
1103 basetype
= gfc_get_complex_type (spec
->kind
);
1107 basetype
= gfc_get_logical_type (spec
->kind
);
1111 basetype
= gfc_get_character_type (spec
->kind
, spec
->u
.cl
);
1115 /* Since this cannot be used, return a length one character. */
1116 basetype
= gfc_get_character_type_len (gfc_default_character_kind
,
1117 gfc_index_one_node
);
1121 basetype
= gfc_get_union_type (spec
->u
.derived
);
1126 basetype
= gfc_get_derived_type (spec
->u
.derived
, codim
);
1128 if (spec
->type
== BT_CLASS
)
1129 GFC_CLASS_TYPE_P (basetype
) = 1;
1131 /* If we're dealing with either C_PTR or C_FUNPTR, we modified the
1132 type and kind to fit a (void *) and the basetype returned was a
1133 ptr_type_node. We need to pass up this new information to the
1134 symbol that was declared of type C_PTR or C_FUNPTR. */
1135 if (spec
->u
.derived
->ts
.f90_type
== BT_VOID
)
1137 spec
->type
= BT_INTEGER
;
1138 spec
->kind
= gfc_index_integer_kind
;
1139 spec
->f90_type
= BT_VOID
;
1144 /* This is for the second arg to c_f_pointer and c_f_procpointer
1145 of the iso_c_binding module, to accept any ptr type. */
1146 basetype
= ptr_type_node
;
1147 if (spec
->f90_type
== BT_VOID
)
1150 && spec
->u
.derived
->intmod_sym_id
== ISOCBINDING_PTR
)
1151 basetype
= ptr_type_node
;
1153 basetype
= pfunc_type_node
;
1162 /* Build an INT_CST for constant expressions, otherwise return NULL_TREE. */
1165 gfc_conv_array_bound (gfc_expr
* expr
)
1167 /* If expr is an integer constant, return that. */
1168 if (expr
!= NULL
&& expr
->expr_type
== EXPR_CONSTANT
)
1169 return gfc_conv_mpz_to_tree (expr
->value
.integer
, gfc_index_integer_kind
);
1171 /* Otherwise return NULL. */
1175 /* Return the type of an element of the array. Note that scalar coarrays
1176 are special. In particular, for GFC_ARRAY_TYPE_P, the original argument
1177 (with POINTER_TYPE stripped) is returned. */
1180 gfc_get_element_type (tree type
)
1184 if (GFC_ARRAY_TYPE_P (type
))
1186 if (TREE_CODE (type
) == POINTER_TYPE
)
1187 type
= TREE_TYPE (type
);
1188 if (GFC_TYPE_ARRAY_RANK (type
) == 0)
1190 gcc_assert (GFC_TYPE_ARRAY_CORANK (type
) > 0);
1195 gcc_assert (TREE_CODE (type
) == ARRAY_TYPE
);
1196 element
= TREE_TYPE (type
);
1201 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
));
1202 element
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
1204 gcc_assert (TREE_CODE (element
) == POINTER_TYPE
);
1205 element
= TREE_TYPE (element
);
1207 /* For arrays, which are not scalar coarrays. */
1208 if (TREE_CODE (element
) == ARRAY_TYPE
&& !TYPE_STRING_FLAG (element
))
1209 element
= TREE_TYPE (element
);
1215 /* Build an array. This function is called from gfc_sym_type().
1216 Actually returns array descriptor type.
1218 Format of array descriptors is as follows:
1220 struct gfc_array_descriptor
1225 struct descriptor_dimension dimension[N_DIM];
1228 struct descriptor_dimension
1235 Translation code should use gfc_conv_descriptor_* rather than
1236 accessing the descriptor directly. Any changes to the array
1237 descriptor type will require changes in gfc_conv_descriptor_* and
1238 gfc_build_array_initializer.
1240 This is represented internally as a RECORD_TYPE. The index nodes
1241 are gfc_array_index_type and the data node is a pointer to the
1242 data. See below for the handling of character types.
1244 The dtype member is formatted as follows:
1245 rank = dtype & GFC_DTYPE_RANK_MASK // 3 bits
1246 type = (dtype & GFC_DTYPE_TYPE_MASK) >> GFC_DTYPE_TYPE_SHIFT // 3 bits
1247 size = dtype >> GFC_DTYPE_SIZE_SHIFT
1249 I originally used nested ARRAY_TYPE nodes to represent arrays, but
1250 this generated poor code for assumed/deferred size arrays. These
1251 require use of PLACEHOLDER_EXPR/WITH_RECORD_EXPR, which isn't part
1252 of the GENERIC grammar. Also, there is no way to explicitly set
1253 the array stride, so all data must be packed(1). I've tried to
1254 mark all the functions which would require modification with a GCC
1257 The data component points to the first element in the array. The
1258 offset field is the position of the origin of the array (i.e. element
1259 (0, 0 ...)). This may be outside the bounds of the array.
1261 An element is accessed by
1262 data[offset + index0*stride0 + index1*stride1 + index2*stride2]
1263 This gives good performance as the computation does not involve the
1264 bounds of the array. For packed arrays, this is optimized further
1265 by substituting the known strides.
1267 This system has one problem: all array bounds must be within 2^31
1268 elements of the origin (2^63 on 64-bit machines). For example
1269 integer, dimension (80000:90000, 80000:90000, 2) :: array
1270 may not work properly on 32-bit machines because 80000*80000 >
1271 2^31, so the calculation for stride2 would overflow. This may
1272 still work, but I haven't checked, and it relies on the overflow
1273 doing the right thing.
1275 The way to fix this problem is to access elements as follows:
1276 data[(index0-lbound0)*stride0 + (index1-lbound1)*stride1]
1277 Obviously this is much slower. I will make this a compile time
1278 option, something like -fsmall-array-offsets. Mixing code compiled
1279 with and without this switch will work.
1281 (1) This can be worked around by modifying the upper bound of the
1282 previous dimension. This requires extra fields in the descriptor
1283 (both real_ubound and fake_ubound). */
1286 /* Returns true if the array sym does not require a descriptor. */
1289 gfc_is_nodesc_array (gfc_symbol
* sym
)
1291 symbol_attribute
*array_attr
;
1293 bool is_classarray
= IS_CLASS_ARRAY (sym
);
1295 array_attr
= is_classarray
? &CLASS_DATA (sym
)->attr
: &sym
->attr
;
1296 as
= is_classarray
? CLASS_DATA (sym
)->as
: sym
->as
;
1298 gcc_assert (array_attr
->dimension
|| array_attr
->codimension
);
1300 /* We only want local arrays. */
1301 if ((sym
->ts
.type
!= BT_CLASS
&& sym
->attr
.pointer
)
1302 || (sym
->ts
.type
== BT_CLASS
&& CLASS_DATA (sym
)->attr
.class_pointer
)
1303 || array_attr
->allocatable
)
1306 /* We want a descriptor for associate-name arrays that do not have an
1307 explicitly known shape already. */
1308 if (sym
->assoc
&& as
->type
!= AS_EXPLICIT
)
1311 /* The dummy is stored in sym and not in the component. */
1312 if (sym
->attr
.dummy
)
1313 return as
->type
!= AS_ASSUMED_SHAPE
1314 && as
->type
!= AS_ASSUMED_RANK
;
1316 if (sym
->attr
.result
|| sym
->attr
.function
)
1319 gcc_assert (as
->type
== AS_EXPLICIT
|| as
->cp_was_assumed
);
1325 /* Create an array descriptor type. */
1328 gfc_build_array_type (tree type
, gfc_array_spec
* as
,
1329 enum gfc_array_kind akind
, bool restricted
,
1330 bool contiguous
, int codim
)
1332 tree lbound
[GFC_MAX_DIMENSIONS
];
1333 tree ubound
[GFC_MAX_DIMENSIONS
];
1336 /* Assumed-shape arrays do not have codimension information stored in the
1338 corank
= MAX (as
->corank
, codim
);
1339 if (as
->type
== AS_ASSUMED_SHAPE
||
1340 (as
->type
== AS_ASSUMED_RANK
&& akind
== GFC_ARRAY_ALLOCATABLE
))
1343 if (as
->type
== AS_ASSUMED_RANK
)
1344 for (n
= 0; n
< GFC_MAX_DIMENSIONS
; n
++)
1346 lbound
[n
] = NULL_TREE
;
1347 ubound
[n
] = NULL_TREE
;
1350 for (n
= 0; n
< as
->rank
; n
++)
1352 /* Create expressions for the known bounds of the array. */
1353 if (as
->type
== AS_ASSUMED_SHAPE
&& as
->lower
[n
] == NULL
)
1354 lbound
[n
] = gfc_index_one_node
;
1356 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1357 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1360 for (n
= as
->rank
; n
< as
->rank
+ corank
; n
++)
1362 if (as
->type
!= AS_DEFERRED
&& as
->lower
[n
] == NULL
)
1363 lbound
[n
] = gfc_index_one_node
;
1365 lbound
[n
] = gfc_conv_array_bound (as
->lower
[n
]);
1367 if (n
< as
->rank
+ corank
- 1)
1368 ubound
[n
] = gfc_conv_array_bound (as
->upper
[n
]);
1371 if (as
->type
== AS_ASSUMED_SHAPE
)
1372 akind
= contiguous
? GFC_ARRAY_ASSUMED_SHAPE_CONT
1373 : GFC_ARRAY_ASSUMED_SHAPE
;
1374 else if (as
->type
== AS_ASSUMED_RANK
)
1375 akind
= contiguous
? GFC_ARRAY_ASSUMED_RANK_CONT
1376 : GFC_ARRAY_ASSUMED_RANK
;
1377 return gfc_get_array_type_bounds (type
, as
->rank
== -1
1378 ? GFC_MAX_DIMENSIONS
: as
->rank
,
1379 corank
, lbound
, ubound
, 0, akind
,
1383 /* Returns the struct descriptor_dimension type. */
1386 gfc_get_desc_dim_type (void)
1389 tree decl
, *chain
= NULL
;
1391 if (gfc_desc_dim_type
)
1392 return gfc_desc_dim_type
;
1394 /* Build the type node. */
1395 type
= make_node (RECORD_TYPE
);
1397 TYPE_NAME (type
) = get_identifier ("descriptor_dimension");
1398 TYPE_PACKED (type
) = 1;
1400 /* Consists of the stride, lbound and ubound members. */
1401 decl
= gfc_add_field_to_struct_1 (type
,
1402 get_identifier ("stride"),
1403 gfc_array_index_type
, &chain
);
1404 TREE_NO_WARNING (decl
) = 1;
1406 decl
= gfc_add_field_to_struct_1 (type
,
1407 get_identifier ("lbound"),
1408 gfc_array_index_type
, &chain
);
1409 TREE_NO_WARNING (decl
) = 1;
1411 decl
= gfc_add_field_to_struct_1 (type
,
1412 get_identifier ("ubound"),
1413 gfc_array_index_type
, &chain
);
1414 TREE_NO_WARNING (decl
) = 1;
1416 /* Finish off the type. */
1417 gfc_finish_type (type
);
1418 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
1420 gfc_desc_dim_type
= type
;
1425 /* Return the DTYPE for an array. This describes the type and type parameters
1427 /* TODO: Only call this when the value is actually used, and make all the
1428 unknown cases abort. */
1431 gfc_get_dtype_rank_type (int rank
, tree etype
)
1439 switch (TREE_CODE (etype
))
1457 /* We will never have arrays of arrays. */
1471 /* TODO: Don't do dtype for temporary descriptorless arrays. */
1472 /* We can strange array types for temporary arrays. */
1473 return gfc_index_zero_node
;
1476 gcc_assert (rank
<= GFC_DTYPE_RANK_MASK
);
1477 size
= TYPE_SIZE_UNIT (etype
);
1479 i
= rank
| (n
<< GFC_DTYPE_TYPE_SHIFT
);
1480 if (size
&& INTEGER_CST_P (size
))
1482 if (tree_int_cst_lt (gfc_max_array_element_size
, size
))
1483 gfc_fatal_error ("Array element size too big at %C");
1485 i
+= TREE_INT_CST_LOW (size
) << GFC_DTYPE_SIZE_SHIFT
;
1487 dtype
= build_int_cst (gfc_array_index_type
, i
);
1489 if (size
&& !INTEGER_CST_P (size
))
1491 tmp
= build_int_cst (gfc_array_index_type
, GFC_DTYPE_SIZE_SHIFT
);
1492 tmp
= fold_build2_loc (input_location
, LSHIFT_EXPR
,
1493 gfc_array_index_type
,
1494 fold_convert (gfc_array_index_type
, size
), tmp
);
1495 dtype
= fold_build2_loc (input_location
, PLUS_EXPR
, gfc_array_index_type
,
1498 /* If we don't know the size we leave it as zero. This should never happen
1499 for anything that is actually used. */
1500 /* TODO: Check this is actually true, particularly when repacking
1501 assumed size parameters. */
1508 gfc_get_dtype (tree type
)
1514 gcc_assert (GFC_DESCRIPTOR_TYPE_P (type
) || GFC_ARRAY_TYPE_P (type
));
1516 if (GFC_TYPE_ARRAY_DTYPE (type
))
1517 return GFC_TYPE_ARRAY_DTYPE (type
);
1519 rank
= GFC_TYPE_ARRAY_RANK (type
);
1520 etype
= gfc_get_element_type (type
);
1521 dtype
= gfc_get_dtype_rank_type (rank
, etype
);
1523 GFC_TYPE_ARRAY_DTYPE (type
) = dtype
;
1528 /* Build an array type for use without a descriptor, packed according
1529 to the value of PACKED. */
1532 gfc_get_nodesc_array_type (tree etype
, gfc_array_spec
* as
, gfc_packed packed
,
1546 mpz_init_set_ui (offset
, 0);
1547 mpz_init_set_ui (stride
, 1);
1550 /* We don't use build_array_type because this does not include include
1551 lang-specific information (i.e. the bounds of the array) when checking
1554 type
= make_node (ARRAY_TYPE
);
1556 type
= build_variant_type_copy (etype
);
1558 GFC_ARRAY_TYPE_P (type
) = 1;
1559 TYPE_LANG_SPECIFIC (type
) = ggc_cleared_alloc
<struct lang_type
> ();
1561 known_stride
= (packed
!= PACKED_NO
);
1563 for (n
= 0; n
< as
->rank
; n
++)
1565 /* Fill in the stride and bound components of the type. */
1567 tmp
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1570 GFC_TYPE_ARRAY_STRIDE (type
, n
) = tmp
;
1572 expr
= as
->lower
[n
];
1573 if (expr
->expr_type
== EXPR_CONSTANT
)
1575 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1576 gfc_index_integer_kind
);
1583 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1587 /* Calculate the offset. */
1588 mpz_mul (delta
, stride
, as
->lower
[n
]->value
.integer
);
1589 mpz_sub (offset
, offset
, delta
);
1594 expr
= as
->upper
[n
];
1595 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1597 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1598 gfc_index_integer_kind
);
1605 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1609 /* Calculate the stride. */
1610 mpz_sub (delta
, as
->upper
[n
]->value
.integer
,
1611 as
->lower
[n
]->value
.integer
);
1612 mpz_add_ui (delta
, delta
, 1);
1613 mpz_mul (stride
, stride
, delta
);
1616 /* Only the first stride is known for partial packed arrays. */
1617 if (packed
== PACKED_NO
|| packed
== PACKED_PARTIAL
)
1620 for (n
= as
->rank
; n
< as
->rank
+ as
->corank
; n
++)
1622 expr
= as
->lower
[n
];
1623 if (expr
->expr_type
== EXPR_CONSTANT
)
1624 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1625 gfc_index_integer_kind
);
1628 GFC_TYPE_ARRAY_LBOUND (type
, n
) = tmp
;
1630 expr
= as
->upper
[n
];
1631 if (expr
&& expr
->expr_type
== EXPR_CONSTANT
)
1632 tmp
= gfc_conv_mpz_to_tree (expr
->value
.integer
,
1633 gfc_index_integer_kind
);
1636 if (n
< as
->rank
+ as
->corank
- 1)
1637 GFC_TYPE_ARRAY_UBOUND (type
, n
) = tmp
;
1642 GFC_TYPE_ARRAY_OFFSET (type
) =
1643 gfc_conv_mpz_to_tree (offset
, gfc_index_integer_kind
);
1646 GFC_TYPE_ARRAY_OFFSET (type
) = NULL_TREE
;
1650 GFC_TYPE_ARRAY_SIZE (type
) =
1651 gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1654 GFC_TYPE_ARRAY_SIZE (type
) = NULL_TREE
;
1656 GFC_TYPE_ARRAY_RANK (type
) = as
->rank
;
1657 GFC_TYPE_ARRAY_CORANK (type
) = as
->corank
;
1658 GFC_TYPE_ARRAY_DTYPE (type
) = NULL_TREE
;
1659 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
1661 /* TODO: use main type if it is unbounded. */
1662 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1663 build_pointer_type (build_array_type (etype
, range
));
1665 GFC_TYPE_ARRAY_DATAPTR_TYPE (type
) =
1666 build_qualified_type (GFC_TYPE_ARRAY_DATAPTR_TYPE (type
),
1667 TYPE_QUAL_RESTRICT
);
1671 if (packed
!= PACKED_STATIC
|| flag_coarray
== GFC_FCOARRAY_LIB
)
1673 type
= build_pointer_type (type
);
1676 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
1678 GFC_ARRAY_TYPE_P (type
) = 1;
1679 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
1687 mpz_sub_ui (stride
, stride
, 1);
1688 range
= gfc_conv_mpz_to_tree (stride
, gfc_index_integer_kind
);
1693 range
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
, range
);
1694 TYPE_DOMAIN (type
) = range
;
1696 build_pointer_type (etype
);
1697 TREE_TYPE (type
) = etype
;
1705 /* Represent packed arrays as multi-dimensional if they have rank >
1706 1 and with proper bounds, instead of flat arrays. This makes for
1707 better debug info. */
1710 tree gtype
= etype
, rtype
, type_decl
;
1712 for (n
= as
->rank
- 1; n
>= 0; n
--)
1714 rtype
= build_range_type (gfc_array_index_type
,
1715 GFC_TYPE_ARRAY_LBOUND (type
, n
),
1716 GFC_TYPE_ARRAY_UBOUND (type
, n
));
1717 gtype
= build_array_type (gtype
, rtype
);
1719 TYPE_NAME (type
) = type_decl
= build_decl (input_location
,
1720 TYPE_DECL
, NULL
, gtype
);
1721 DECL_ORIGINAL_TYPE (type_decl
) = gtype
;
1724 if (packed
!= PACKED_STATIC
|| !known_stride
1725 || (as
->corank
&& flag_coarray
== GFC_FCOARRAY_LIB
))
1727 /* For dummy arrays and automatic (heap allocated) arrays we
1728 want a pointer to the array. */
1729 type
= build_pointer_type (type
);
1731 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
1732 GFC_ARRAY_TYPE_P (type
) = 1;
1733 TYPE_LANG_SPECIFIC (type
) = TYPE_LANG_SPECIFIC (TREE_TYPE (type
));
1739 /* Return or create the base type for an array descriptor. */
1742 gfc_get_array_descriptor_base (int dimen
, int codimen
, bool restricted
)
1744 tree fat_type
, decl
, arraytype
, *chain
= NULL
;
1745 char name
[16 + 2*GFC_RANK_DIGITS
+ 1 + 1];
1748 /* Assumed-rank array. */
1750 dimen
= GFC_MAX_DIMENSIONS
;
1752 idx
= 2 * (codimen
+ dimen
) + restricted
;
1754 gcc_assert (codimen
+ dimen
>= 0 && codimen
+ dimen
<= GFC_MAX_DIMENSIONS
);
1756 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1758 if (gfc_array_descriptor_base_caf
[idx
])
1759 return gfc_array_descriptor_base_caf
[idx
];
1761 else if (gfc_array_descriptor_base
[idx
])
1762 return gfc_array_descriptor_base
[idx
];
1764 /* Build the type node. */
1765 fat_type
= make_node (RECORD_TYPE
);
1767 sprintf (name
, "array_descriptor" GFC_RANK_PRINTF_FORMAT
, dimen
+ codimen
);
1768 TYPE_NAME (fat_type
) = get_identifier (name
);
1769 TYPE_NAMELESS (fat_type
) = 1;
1771 /* Add the data member as the first element of the descriptor. */
1772 decl
= gfc_add_field_to_struct_1 (fat_type
,
1773 get_identifier ("data"),
1776 : ptr_type_node
), &chain
);
1778 /* Add the base component. */
1779 decl
= gfc_add_field_to_struct_1 (fat_type
,
1780 get_identifier ("offset"),
1781 gfc_array_index_type
, &chain
);
1782 TREE_NO_WARNING (decl
) = 1;
1784 /* Add the dtype component. */
1785 decl
= gfc_add_field_to_struct_1 (fat_type
,
1786 get_identifier ("dtype"),
1787 gfc_array_index_type
, &chain
);
1788 TREE_NO_WARNING (decl
) = 1;
1790 /* Add the span component. */
1791 decl
= gfc_add_field_to_struct_1 (fat_type
,
1792 get_identifier ("span"),
1793 gfc_array_index_type
, &chain
);
1794 TREE_NO_WARNING (decl
) = 1;
1796 /* Build the array type for the stride and bound components. */
1797 if (dimen
+ codimen
> 0)
1800 build_array_type (gfc_get_desc_dim_type (),
1801 build_range_type (gfc_array_index_type
,
1802 gfc_index_zero_node
,
1803 gfc_rank_cst
[codimen
+ dimen
- 1]));
1805 decl
= gfc_add_field_to_struct_1 (fat_type
, get_identifier ("dim"),
1807 TREE_NO_WARNING (decl
) = 1;
1810 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1812 decl
= gfc_add_field_to_struct_1 (fat_type
,
1813 get_identifier ("token"),
1814 prvoid_type_node
, &chain
);
1815 TREE_NO_WARNING (decl
) = 1;
1818 /* Finish off the type. */
1819 gfc_finish_type (fat_type
);
1820 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (fat_type
)) = 1;
1822 if (flag_coarray
== GFC_FCOARRAY_LIB
&& codimen
)
1823 gfc_array_descriptor_base_caf
[idx
] = fat_type
;
1825 gfc_array_descriptor_base
[idx
] = fat_type
;
1831 /* Build an array (descriptor) type with given bounds. */
1834 gfc_get_array_type_bounds (tree etype
, int dimen
, int codimen
, tree
* lbound
,
1835 tree
* ubound
, int packed
,
1836 enum gfc_array_kind akind
, bool restricted
)
1838 char name
[8 + 2*GFC_RANK_DIGITS
+ 1 + GFC_MAX_SYMBOL_LEN
];
1839 tree fat_type
, base_type
, arraytype
, lower
, upper
, stride
, tmp
, rtype
;
1840 const char *type_name
;
1843 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, restricted
);
1844 fat_type
= build_distinct_type_copy (base_type
);
1845 /* Make sure that nontarget and target array type have the same canonical
1846 type (and same stub decl for debug info). */
1847 base_type
= gfc_get_array_descriptor_base (dimen
, codimen
, false);
1848 TYPE_CANONICAL (fat_type
) = base_type
;
1849 TYPE_STUB_DECL (fat_type
) = TYPE_STUB_DECL (base_type
);
1851 tmp
= TYPE_NAME (etype
);
1852 if (tmp
&& TREE_CODE (tmp
) == TYPE_DECL
)
1853 tmp
= DECL_NAME (tmp
);
1855 type_name
= IDENTIFIER_POINTER (tmp
);
1857 type_name
= "unknown";
1858 sprintf (name
, "array" GFC_RANK_PRINTF_FORMAT
"_%.*s", dimen
+ codimen
,
1859 GFC_MAX_SYMBOL_LEN
, type_name
);
1860 TYPE_NAME (fat_type
) = get_identifier (name
);
1861 TYPE_NAMELESS (fat_type
) = 1;
1863 GFC_DESCRIPTOR_TYPE_P (fat_type
) = 1;
1864 TYPE_LANG_SPECIFIC (fat_type
) = ggc_cleared_alloc
<struct lang_type
> ();
1866 GFC_TYPE_ARRAY_RANK (fat_type
) = dimen
;
1867 GFC_TYPE_ARRAY_CORANK (fat_type
) = codimen
;
1868 GFC_TYPE_ARRAY_DTYPE (fat_type
) = NULL_TREE
;
1869 GFC_TYPE_ARRAY_AKIND (fat_type
) = akind
;
1871 /* Build an array descriptor record type. */
1873 stride
= gfc_index_one_node
;
1876 for (n
= 0; n
< dimen
+ codimen
; n
++)
1879 GFC_TYPE_ARRAY_STRIDE (fat_type
, n
) = stride
;
1886 if (lower
!= NULL_TREE
)
1888 if (INTEGER_CST_P (lower
))
1889 GFC_TYPE_ARRAY_LBOUND (fat_type
, n
) = lower
;
1894 if (codimen
&& n
== dimen
+ codimen
- 1)
1898 if (upper
!= NULL_TREE
)
1900 if (INTEGER_CST_P (upper
))
1901 GFC_TYPE_ARRAY_UBOUND (fat_type
, n
) = upper
;
1909 if (upper
!= NULL_TREE
&& lower
!= NULL_TREE
&& stride
!= NULL_TREE
)
1911 tmp
= fold_build2_loc (input_location
, MINUS_EXPR
,
1912 gfc_array_index_type
, upper
, lower
);
1913 tmp
= fold_build2_loc (input_location
, PLUS_EXPR
,
1914 gfc_array_index_type
, tmp
,
1915 gfc_index_one_node
);
1916 stride
= fold_build2_loc (input_location
, MULT_EXPR
,
1917 gfc_array_index_type
, tmp
, stride
);
1918 /* Check the folding worked. */
1919 gcc_assert (INTEGER_CST_P (stride
));
1924 GFC_TYPE_ARRAY_SIZE (fat_type
) = stride
;
1926 /* TODO: known offsets for descriptors. */
1927 GFC_TYPE_ARRAY_OFFSET (fat_type
) = NULL_TREE
;
1931 arraytype
= build_pointer_type (etype
);
1933 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
1935 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
1939 /* We define data as an array with the correct size if possible.
1940 Much better than doing pointer arithmetic. */
1942 rtype
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
1943 int_const_binop (MINUS_EXPR
, stride
,
1944 build_int_cst (TREE_TYPE (stride
), 1)));
1946 rtype
= gfc_array_range_type
;
1947 arraytype
= build_array_type (etype
, rtype
);
1948 arraytype
= build_pointer_type (arraytype
);
1950 arraytype
= build_qualified_type (arraytype
, TYPE_QUAL_RESTRICT
);
1951 GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type
) = arraytype
;
1953 /* This will generate the base declarations we need to emit debug
1954 information for this type. FIXME: there must be a better way to
1955 avoid divergence between compilations with and without debug
1958 struct array_descr_info info
;
1959 gfc_get_array_descr_info (fat_type
, &info
);
1960 gfc_get_array_descr_info (build_pointer_type (fat_type
), &info
);
1966 /* Build a pointer type. This function is called from gfc_sym_type(). */
1969 gfc_build_pointer_type (gfc_symbol
* sym
, tree type
)
1971 /* Array pointer types aren't actually pointers. */
1972 if (sym
->attr
.dimension
)
1975 return build_pointer_type (type
);
1978 static tree
gfc_nonrestricted_type (tree t
);
1979 /* Given two record or union type nodes TO and FROM, ensure
1980 that all fields in FROM have a corresponding field in TO,
1981 their type being nonrestrict variants. This accepts a TO
1982 node that already has a prefix of the fields in FROM. */
1984 mirror_fields (tree to
, tree from
)
1989 /* Forward to the end of TOs fields. */
1990 fto
= TYPE_FIELDS (to
);
1991 ffrom
= TYPE_FIELDS (from
);
1992 chain
= &TYPE_FIELDS (to
);
1995 gcc_assert (ffrom
&& DECL_NAME (fto
) == DECL_NAME (ffrom
));
1996 chain
= &DECL_CHAIN (fto
);
1997 fto
= DECL_CHAIN (fto
);
1998 ffrom
= DECL_CHAIN (ffrom
);
2001 /* Now add all fields remaining in FROM (starting with ffrom). */
2002 for (; ffrom
; ffrom
= DECL_CHAIN (ffrom
))
2004 tree newfield
= copy_node (ffrom
);
2005 DECL_CONTEXT (newfield
) = to
;
2006 /* The store to DECL_CHAIN might seem redundant with the
2007 stores to *chain, but not clearing it here would mean
2008 leaving a chain into the old fields. If ever
2009 our called functions would look at them confusion
2011 DECL_CHAIN (newfield
) = NULL_TREE
;
2013 chain
= &DECL_CHAIN (newfield
);
2015 if (TREE_CODE (ffrom
) == FIELD_DECL
)
2017 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (ffrom
));
2018 TREE_TYPE (newfield
) = elemtype
;
2024 /* Given a type T, returns a different type of the same structure,
2025 except that all types it refers to (recursively) are always
2026 non-restrict qualified types. */
2028 gfc_nonrestricted_type (tree t
)
2032 /* If the type isn't laid out yet, don't copy it. If something
2033 needs it for real it should wait until the type got finished. */
2037 if (!TYPE_LANG_SPECIFIC (t
))
2038 TYPE_LANG_SPECIFIC (t
) = ggc_cleared_alloc
<struct lang_type
> ();
2039 /* If we're dealing with this very node already further up
2040 the call chain (recursion via pointers and struct members)
2041 we haven't yet determined if we really need a new type node.
2042 Assume we don't, return T itself. */
2043 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
== error_mark_node
)
2046 /* If we have calculated this all already, just return it. */
2047 if (TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
)
2048 return TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
;
2050 /* Mark this type. */
2051 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= error_mark_node
;
2053 switch (TREE_CODE (t
))
2059 case REFERENCE_TYPE
:
2061 tree totype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2062 if (totype
== TREE_TYPE (t
))
2064 else if (TREE_CODE (t
) == POINTER_TYPE
)
2065 ret
= build_pointer_type (totype
);
2067 ret
= build_reference_type (totype
);
2068 ret
= build_qualified_type (ret
,
2069 TYPE_QUALS (t
) & ~TYPE_QUAL_RESTRICT
);
2075 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (t
));
2076 if (elemtype
== TREE_TYPE (t
))
2080 ret
= build_variant_type_copy (t
);
2081 TREE_TYPE (ret
) = elemtype
;
2082 if (TYPE_LANG_SPECIFIC (t
)
2083 && GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2085 tree dataptr_type
= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
);
2086 dataptr_type
= gfc_nonrestricted_type (dataptr_type
);
2087 if (dataptr_type
!= GFC_TYPE_ARRAY_DATAPTR_TYPE (t
))
2089 TYPE_LANG_SPECIFIC (ret
)
2090 = ggc_cleared_alloc
<struct lang_type
> ();
2091 *TYPE_LANG_SPECIFIC (ret
) = *TYPE_LANG_SPECIFIC (t
);
2092 GFC_TYPE_ARRAY_DATAPTR_TYPE (ret
) = dataptr_type
;
2101 case QUAL_UNION_TYPE
:
2104 /* First determine if we need a new type at all.
2105 Careful, the two calls to gfc_nonrestricted_type per field
2106 might return different values. That happens exactly when
2107 one of the fields reaches back to this very record type
2108 (via pointers). The first calls will assume that we don't
2109 need to copy T (see the error_mark_node marking). If there
2110 are any reasons for copying T apart from having to copy T,
2111 we'll indeed copy it, and the second calls to
2112 gfc_nonrestricted_type will use that new node if they
2114 for (field
= TYPE_FIELDS (t
); field
; field
= DECL_CHAIN (field
))
2115 if (TREE_CODE (field
) == FIELD_DECL
)
2117 tree elemtype
= gfc_nonrestricted_type (TREE_TYPE (field
));
2118 if (elemtype
!= TREE_TYPE (field
))
2123 ret
= build_variant_type_copy (t
);
2124 TYPE_FIELDS (ret
) = NULL_TREE
;
2126 /* Here we make sure that as soon as we know we have to copy
2127 T, that also fields reaching back to us will use the new
2128 copy. It's okay if that copy still contains the old fields,
2129 we won't look at them. */
2130 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2131 mirror_fields (ret
, t
);
2136 TYPE_LANG_SPECIFIC (t
)->nonrestricted_type
= ret
;
2141 /* Return the type for a symbol. Special handling is required for character
2142 types to get the correct level of indirection.
2143 For functions return the return type.
2144 For subroutines return void_type_node.
2145 Calling this multiple times for the same symbol should be avoided,
2146 especially for character and array types. */
2149 gfc_sym_type (gfc_symbol
* sym
)
2155 /* Procedure Pointers inside COMMON blocks. */
2156 if (sym
->attr
.proc_pointer
&& sym
->attr
.in_common
)
2158 /* Unset proc_pointer as gfc_get_function_type calls gfc_sym_type. */
2159 sym
->attr
.proc_pointer
= 0;
2160 type
= build_pointer_type (gfc_get_function_type (sym
));
2161 sym
->attr
.proc_pointer
= 1;
2165 if (sym
->attr
.flavor
== FL_PROCEDURE
&& !sym
->attr
.function
)
2166 return void_type_node
;
2168 /* In the case of a function the fake result variable may have a
2169 type different from the function type, so don't return early in
2171 if (sym
->backend_decl
&& !sym
->attr
.function
)
2172 return TREE_TYPE (sym
->backend_decl
);
2174 if (sym
->ts
.type
== BT_CHARACTER
2175 && ((sym
->attr
.function
&& sym
->attr
.is_bind_c
)
2176 || (sym
->attr
.result
2177 && sym
->ns
->proc_name
2178 && sym
->ns
->proc_name
->attr
.is_bind_c
)
2179 || (sym
->ts
.deferred
&& (!sym
->ts
.u
.cl
2180 || !sym
->ts
.u
.cl
->backend_decl
))))
2181 type
= gfc_character1_type_node
;
2183 type
= gfc_typenode_for_spec (&sym
->ts
, sym
->attr
.codimension
);
2185 if (sym
->attr
.dummy
&& !sym
->attr
.function
&& !sym
->attr
.value
)
2190 restricted
= !sym
->attr
.target
&& !sym
->attr
.pointer
2191 && !sym
->attr
.proc_pointer
&& !sym
->attr
.cray_pointee
;
2193 type
= gfc_nonrestricted_type (type
);
2195 if (sym
->attr
.dimension
|| sym
->attr
.codimension
)
2197 if (gfc_is_nodesc_array (sym
))
2199 /* If this is a character argument of unknown length, just use the
2201 if (sym
->ts
.type
!= BT_CHARACTER
2202 || !(sym
->attr
.dummy
|| sym
->attr
.function
)
2203 || sym
->ts
.u
.cl
->backend_decl
)
2205 type
= gfc_get_nodesc_array_type (type
, sym
->as
,
2214 enum gfc_array_kind akind
= GFC_ARRAY_UNKNOWN
;
2215 if (sym
->attr
.pointer
)
2216 akind
= sym
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2217 : GFC_ARRAY_POINTER
;
2218 else if (sym
->attr
.allocatable
)
2219 akind
= GFC_ARRAY_ALLOCATABLE
;
2220 type
= gfc_build_array_type (type
, sym
->as
, akind
, restricted
,
2221 sym
->attr
.contiguous
, false);
2226 if (sym
->attr
.allocatable
|| sym
->attr
.pointer
2227 || gfc_is_associate_pointer (sym
))
2228 type
= gfc_build_pointer_type (sym
, type
);
2231 /* We currently pass all parameters by reference.
2232 See f95_get_function_decl. For dummy function parameters return the
2236 /* We must use pointer types for potentially absent variables. The
2237 optimizers assume a reference type argument is never NULL. */
2238 if (sym
->attr
.optional
2239 || (sym
->ns
->proc_name
&& sym
->ns
->proc_name
->attr
.entry_master
))
2240 type
= build_pointer_type (type
);
2243 type
= build_reference_type (type
);
2245 type
= build_qualified_type (type
, TYPE_QUAL_RESTRICT
);
2252 /* Layout and output debug info for a record type. */
2255 gfc_finish_type (tree type
)
2259 decl
= build_decl (input_location
,
2260 TYPE_DECL
, NULL_TREE
, type
);
2261 TYPE_STUB_DECL (type
) = decl
;
2263 rest_of_type_compilation (type
, 1);
2264 rest_of_decl_compilation (decl
, 1, 0);
2267 /* Add a field of given NAME and TYPE to the context of a UNION_TYPE
2268 or RECORD_TYPE pointed to by CONTEXT. The new field is chained
2269 to the end of the field list pointed to by *CHAIN.
2271 Returns a pointer to the new field. */
2274 gfc_add_field_to_struct_1 (tree context
, tree name
, tree type
, tree
**chain
)
2276 tree decl
= build_decl (input_location
, FIELD_DECL
, name
, type
);
2278 DECL_CONTEXT (decl
) = context
;
2279 DECL_CHAIN (decl
) = NULL_TREE
;
2280 if (TYPE_FIELDS (context
) == NULL_TREE
)
2281 TYPE_FIELDS (context
) = decl
;
2286 *chain
= &DECL_CHAIN (decl
);
2292 /* Like `gfc_add_field_to_struct_1', but adds alignment
2296 gfc_add_field_to_struct (tree context
, tree name
, tree type
, tree
**chain
)
2298 tree decl
= gfc_add_field_to_struct_1 (context
, name
, type
, chain
);
2300 DECL_INITIAL (decl
) = 0;
2301 SET_DECL_ALIGN (decl
, 0);
2302 DECL_USER_ALIGN (decl
) = 0;
2308 /* Copy the backend_decl and component backend_decls if
2309 the two derived type symbols are "equal", as described
2310 in 4.4.2 and resolved by gfc_compare_derived_types. */
2313 gfc_copy_dt_decls_ifequal (gfc_symbol
*from
, gfc_symbol
*to
,
2316 gfc_component
*to_cm
;
2317 gfc_component
*from_cm
;
2322 if (from
->backend_decl
== NULL
2323 || !gfc_compare_derived_types (from
, to
))
2326 to
->backend_decl
= from
->backend_decl
;
2328 to_cm
= to
->components
;
2329 from_cm
= from
->components
;
2331 /* Copy the component declarations. If a component is itself
2332 a derived type, we need a copy of its component declarations.
2333 This is done by recursing into gfc_get_derived_type and
2334 ensures that the component's component declarations have
2335 been built. If it is a character, we need the character
2337 for (; to_cm
; to_cm
= to_cm
->next
, from_cm
= from_cm
->next
)
2339 to_cm
->backend_decl
= from_cm
->backend_decl
;
2340 if (from_cm
->ts
.type
== BT_UNION
)
2341 gfc_get_union_type (to_cm
->ts
.u
.derived
);
2342 else if (from_cm
->ts
.type
== BT_DERIVED
2343 && (!from_cm
->attr
.pointer
|| from_gsym
))
2344 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2345 else if (from_cm
->ts
.type
== BT_CLASS
2346 && (!CLASS_DATA (from_cm
)->attr
.class_pointer
|| from_gsym
))
2347 gfc_get_derived_type (to_cm
->ts
.u
.derived
);
2348 else if (from_cm
->ts
.type
== BT_CHARACTER
)
2349 to_cm
->ts
.u
.cl
->backend_decl
= from_cm
->ts
.u
.cl
->backend_decl
;
2356 /* Build a tree node for a procedure pointer component. */
2359 gfc_get_ppc_type (gfc_component
* c
)
2363 /* Explicit interface. */
2364 if (c
->attr
.if_source
!= IFSRC_UNKNOWN
&& c
->ts
.interface
)
2365 return build_pointer_type (gfc_get_function_type (c
->ts
.interface
));
2367 /* Implicit interface (only return value may be known). */
2368 if (c
->attr
.function
&& !c
->attr
.dimension
&& c
->ts
.type
!= BT_CHARACTER
)
2369 t
= gfc_typenode_for_spec (&c
->ts
);
2373 return build_pointer_type (build_function_type_list (t
, NULL_TREE
));
2377 /* Build a tree node for a union type. Requires building each map
2378 structure which is an element of the union. */
2381 gfc_get_union_type (gfc_symbol
*un
)
2383 gfc_component
*map
= NULL
;
2384 tree typenode
= NULL
, map_type
= NULL
, map_field
= NULL
;
2387 if (un
->backend_decl
)
2389 if (TYPE_FIELDS (un
->backend_decl
) || un
->attr
.proc_pointer_comp
)
2390 return un
->backend_decl
;
2392 typenode
= un
->backend_decl
;
2396 typenode
= make_node (UNION_TYPE
);
2397 TYPE_NAME (typenode
) = get_identifier (un
->name
);
2400 /* Add each contained MAP as a field. */
2401 for (map
= un
->components
; map
; map
= map
->next
)
2403 gcc_assert (map
->ts
.type
== BT_DERIVED
);
2405 /* The map's type node, which is defined within this union's context. */
2406 map_type
= gfc_get_derived_type (map
->ts
.u
.derived
);
2407 TYPE_CONTEXT (map_type
) = typenode
;
2409 /* The map field's declaration. */
2410 map_field
= gfc_add_field_to_struct(typenode
, get_identifier(map
->name
),
2413 gfc_set_decl_location (map_field
, &map
->loc
);
2414 else if (un
->declared_at
.lb
)
2415 gfc_set_decl_location (map_field
, &un
->declared_at
);
2417 DECL_PACKED (map_field
) |= TYPE_PACKED (typenode
);
2418 DECL_NAMELESS(map_field
) = true;
2420 /* We should never clobber another backend declaration for this map,
2421 because each map component is unique. */
2422 if (!map
->backend_decl
)
2423 map
->backend_decl
= map_field
;
2426 un
->backend_decl
= typenode
;
2427 gfc_finish_type (typenode
);
2433 /* Build a tree node for a derived type. If there are equal
2434 derived types, with different local names, these are built
2435 at the same time. If an equal derived type has been built
2436 in a parent namespace, this is used. */
2439 gfc_get_derived_type (gfc_symbol
* derived
, int codimen
)
2441 tree typenode
= NULL
, field
= NULL
, field_type
= NULL
;
2442 tree canonical
= NULL_TREE
;
2444 bool got_canonical
= false;
2445 bool unlimited_entity
= false;
2451 gcc_assert (!derived
->attr
.pdt_template
);
2453 if (derived
->attr
.unlimited_polymorphic
2454 || (flag_coarray
== GFC_FCOARRAY_LIB
2455 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2456 && (derived
->intmod_sym_id
== ISOFORTRAN_LOCK_TYPE
2457 || derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)))
2458 return ptr_type_node
;
2460 if (flag_coarray
!= GFC_FCOARRAY_LIB
2461 && derived
->from_intmod
== INTMOD_ISO_FORTRAN_ENV
2462 && derived
->intmod_sym_id
== ISOFORTRAN_EVENT_TYPE
)
2463 return gfc_get_int_type (gfc_default_integer_kind
);
2465 if (derived
&& derived
->attr
.flavor
== FL_PROCEDURE
2466 && derived
->attr
.generic
)
2467 derived
= gfc_find_dt_in_generic (derived
);
2469 /* See if it's one of the iso_c_binding derived types. */
2470 if (derived
->attr
.is_iso_c
== 1 || derived
->ts
.f90_type
== BT_VOID
)
2472 if (derived
->backend_decl
)
2473 return derived
->backend_decl
;
2475 if (derived
->intmod_sym_id
== ISOCBINDING_PTR
)
2476 derived
->backend_decl
= ptr_type_node
;
2478 derived
->backend_decl
= pfunc_type_node
;
2480 derived
->ts
.kind
= gfc_index_integer_kind
;
2481 derived
->ts
.type
= BT_INTEGER
;
2482 /* Set the f90_type to BT_VOID as a way to recognize something of type
2483 BT_INTEGER that needs to fit a void * for the purpose of the
2484 iso_c_binding derived types. */
2485 derived
->ts
.f90_type
= BT_VOID
;
2487 return derived
->backend_decl
;
2490 /* If use associated, use the module type for this one. */
2491 if (derived
->backend_decl
== NULL
2492 && derived
->attr
.use_assoc
2494 && gfc_get_module_backend_decl (derived
))
2495 goto copy_derived_types
;
2497 /* The derived types from an earlier namespace can be used as the
2499 if (derived
->backend_decl
== NULL
&& !derived
->attr
.use_assoc
2500 && gfc_global_ns_list
)
2502 for (ns
= gfc_global_ns_list
;
2503 ns
->translated
&& !got_canonical
;
2506 dt
= ns
->derived_types
;
2507 for (; dt
&& !canonical
; dt
= dt
->next
)
2509 gfc_copy_dt_decls_ifequal (dt
->derived
, derived
, true);
2510 if (derived
->backend_decl
)
2511 got_canonical
= true;
2516 /* Store up the canonical type to be added to this one. */
2519 if (TYPE_CANONICAL (derived
->backend_decl
))
2520 canonical
= TYPE_CANONICAL (derived
->backend_decl
);
2522 canonical
= derived
->backend_decl
;
2524 derived
->backend_decl
= NULL_TREE
;
2527 /* derived->backend_decl != 0 means we saw it before, but its
2528 components' backend_decl may have not been built. */
2529 if (derived
->backend_decl
)
2531 /* Its components' backend_decl have been built or we are
2532 seeing recursion through the formal arglist of a procedure
2533 pointer component. */
2534 if (TYPE_FIELDS (derived
->backend_decl
))
2535 return derived
->backend_decl
;
2536 else if (derived
->attr
.abstract
2537 && derived
->attr
.proc_pointer_comp
)
2539 /* If an abstract derived type with procedure pointer
2540 components has no other type of component, return the
2541 backend_decl. Otherwise build the components if any of the
2542 non-procedure pointer components have no backend_decl. */
2543 for (c
= derived
->components
; c
; c
= c
->next
)
2545 bool same_alloc_type
= c
->attr
.allocatable
2546 && derived
== c
->ts
.u
.derived
;
2547 if (!c
->attr
.proc_pointer
2549 && c
->backend_decl
== NULL
)
2551 else if (c
->next
== NULL
)
2552 return derived
->backend_decl
;
2554 typenode
= derived
->backend_decl
;
2557 typenode
= derived
->backend_decl
;
2561 /* We see this derived type first time, so build the type node. */
2562 typenode
= make_node (RECORD_TYPE
);
2563 TYPE_NAME (typenode
) = get_identifier (derived
->name
);
2564 TYPE_PACKED (typenode
) = flag_pack_derived
;
2565 derived
->backend_decl
= typenode
;
2568 if (derived
->components
2569 && derived
->components
->ts
.type
== BT_DERIVED
2570 && strcmp (derived
->components
->name
, "_data") == 0
2571 && derived
->components
->ts
.u
.derived
->attr
.unlimited_polymorphic
)
2572 unlimited_entity
= true;
2574 /* Go through the derived type components, building them as
2575 necessary. The reason for doing this now is that it is
2576 possible to recurse back to this derived type through a
2577 pointer component (PR24092). If this happens, the fields
2578 will be built and so we can return the type. */
2579 for (c
= derived
->components
; c
; c
= c
->next
)
2581 bool same_alloc_type
= c
->attr
.allocatable
2582 && derived
== c
->ts
.u
.derived
;
2584 if (c
->ts
.type
== BT_UNION
&& c
->ts
.u
.derived
->backend_decl
== NULL
)
2585 c
->ts
.u
.derived
->backend_decl
= gfc_get_union_type (c
->ts
.u
.derived
);
2587 if (c
->ts
.type
!= BT_DERIVED
&& c
->ts
.type
!= BT_CLASS
)
2590 if ((!c
->attr
.pointer
&& !c
->attr
.proc_pointer
2591 && !same_alloc_type
)
2592 || c
->ts
.u
.derived
->backend_decl
== NULL
)
2594 int local_codim
= c
->attr
.codimension
? c
->as
->corank
: codimen
;
2595 c
->ts
.u
.derived
->backend_decl
= gfc_get_derived_type (c
->ts
.u
.derived
,
2599 if (c
->ts
.u
.derived
->attr
.is_iso_c
)
2601 /* Need to copy the modified ts from the derived type. The
2602 typespec was modified because C_PTR/C_FUNPTR are translated
2603 into (void *) from derived types. */
2604 c
->ts
.type
= c
->ts
.u
.derived
->ts
.type
;
2605 c
->ts
.kind
= c
->ts
.u
.derived
->ts
.kind
;
2606 c
->ts
.f90_type
= c
->ts
.u
.derived
->ts
.f90_type
;
2609 c
->initializer
->ts
.type
= c
->ts
.type
;
2610 c
->initializer
->ts
.kind
= c
->ts
.kind
;
2611 c
->initializer
->ts
.f90_type
= c
->ts
.f90_type
;
2612 c
->initializer
->expr_type
= EXPR_NULL
;
2617 if (TYPE_FIELDS (derived
->backend_decl
))
2618 return derived
->backend_decl
;
2620 /* Build the type member list. Install the newly created RECORD_TYPE
2621 node as DECL_CONTEXT of each FIELD_DECL. In this case we must go
2622 through only the top-level linked list of components so we correctly
2623 build UNION_TYPE nodes for BT_UNION components. MAPs and other nested
2624 types are built as part of gfc_get_union_type. */
2625 for (c
= derived
->components
; c
; c
= c
->next
)
2627 bool same_alloc_type
= c
->attr
.allocatable
2628 && derived
== c
->ts
.u
.derived
;
2629 /* Prevent infinite recursion, when the procedure pointer type is
2630 the same as derived, by forcing the procedure pointer component to
2631 be built as if the explicit interface does not exist. */
2632 if (c
->attr
.proc_pointer
2633 && (c
->ts
.type
!= BT_DERIVED
|| (c
->ts
.u
.derived
2634 && !gfc_compare_derived_types (derived
, c
->ts
.u
.derived
)))
2635 && (c
->ts
.type
!= BT_CLASS
|| (CLASS_DATA (c
)->ts
.u
.derived
2636 && !gfc_compare_derived_types (derived
, CLASS_DATA (c
)->ts
.u
.derived
))))
2637 field_type
= gfc_get_ppc_type (c
);
2638 else if (c
->attr
.proc_pointer
&& derived
->backend_decl
)
2640 tmp
= build_function_type_list (derived
->backend_decl
, NULL_TREE
);
2641 field_type
= build_pointer_type (tmp
);
2643 else if (c
->ts
.type
== BT_DERIVED
|| c
->ts
.type
== BT_CLASS
)
2644 field_type
= c
->ts
.u
.derived
->backend_decl
;
2647 if (c
->ts
.type
== BT_CHARACTER
2648 && !c
->ts
.deferred
&& !c
->attr
.pdt_string
)
2650 /* Evaluate the string length. */
2651 gfc_conv_const_charlen (c
->ts
.u
.cl
);
2652 gcc_assert (c
->ts
.u
.cl
->backend_decl
);
2654 else if (c
->ts
.type
== BT_CHARACTER
)
2655 c
->ts
.u
.cl
->backend_decl
2656 = build_int_cst (gfc_charlen_type_node
, 0);
2658 field_type
= gfc_typenode_for_spec (&c
->ts
, codimen
);
2661 /* This returns an array descriptor type. Initialization may be
2663 if ((c
->attr
.dimension
|| c
->attr
.codimension
) && !c
->attr
.proc_pointer
)
2665 if (c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_array
)
2667 enum gfc_array_kind akind
;
2668 if (c
->attr
.pointer
)
2669 akind
= c
->attr
.contiguous
? GFC_ARRAY_POINTER_CONT
2670 : GFC_ARRAY_POINTER
;
2672 akind
= GFC_ARRAY_ALLOCATABLE
;
2673 /* Pointers to arrays aren't actually pointer types. The
2674 descriptors are separate, but the data is common. */
2675 field_type
= gfc_build_array_type (field_type
, c
->as
, akind
,
2677 && !c
->attr
.pointer
,
2682 field_type
= gfc_get_nodesc_array_type (field_type
, c
->as
,
2686 else if ((c
->attr
.pointer
|| c
->attr
.allocatable
|| c
->attr
.pdt_string
)
2687 && !c
->attr
.proc_pointer
2688 && !(unlimited_entity
&& c
== derived
->components
))
2689 field_type
= build_pointer_type (field_type
);
2691 if (c
->attr
.pointer
|| same_alloc_type
)
2692 field_type
= gfc_nonrestricted_type (field_type
);
2694 /* vtype fields can point to different types to the base type. */
2695 if (c
->ts
.type
== BT_DERIVED
2696 && c
->ts
.u
.derived
&& c
->ts
.u
.derived
->attr
.vtype
)
2697 field_type
= build_pointer_type_for_mode (TREE_TYPE (field_type
),
2700 /* Ensure that the CLASS language specific flag is set. */
2701 if (c
->ts
.type
== BT_CLASS
)
2703 if (POINTER_TYPE_P (field_type
))
2704 GFC_CLASS_TYPE_P (TREE_TYPE (field_type
)) = 1;
2706 GFC_CLASS_TYPE_P (field_type
) = 1;
2709 field
= gfc_add_field_to_struct (typenode
,
2710 get_identifier (c
->name
),
2711 field_type
, &chain
);
2713 gfc_set_decl_location (field
, &c
->loc
);
2714 else if (derived
->declared_at
.lb
)
2715 gfc_set_decl_location (field
, &derived
->declared_at
);
2717 gfc_finish_decl_attrs (field
, &c
->attr
);
2719 DECL_PACKED (field
) |= TYPE_PACKED (typenode
);
2722 if (!c
->backend_decl
)
2723 c
->backend_decl
= field
;
2725 if (c
->attr
.pointer
&& c
->attr
.dimension
2726 && !(c
->ts
.type
== BT_DERIVED
2727 && strcmp (c
->name
, "_data") == 0))
2728 GFC_DECL_PTR_ARRAY_P (c
->backend_decl
) = 1;
2730 /* Do not add a caf_token field for classes' data components. */
2731 if (codimen
&& !c
->attr
.dimension
&& !c
->attr
.codimension
2732 && (c
->attr
.allocatable
|| c
->attr
.pointer
)
2733 && c
->caf_token
== NULL_TREE
&& strcmp ("_data", c
->name
) != 0)
2735 char caf_name
[GFC_MAX_SYMBOL_LEN
];
2736 snprintf (caf_name
, GFC_MAX_SYMBOL_LEN
, "_caf_%s", c
->name
);
2737 c
->caf_token
= gfc_add_field_to_struct (typenode
,
2738 get_identifier (caf_name
),
2739 pvoid_type_node
, &chain
);
2740 TREE_NO_WARNING (c
->caf_token
) = 1;
2744 /* Now lay out the derived type, including the fields. */
2746 TYPE_CANONICAL (typenode
) = canonical
;
2748 gfc_finish_type (typenode
);
2749 gfc_set_decl_location (TYPE_STUB_DECL (typenode
), &derived
->declared_at
);
2750 if (derived
->module
&& derived
->ns
->proc_name
2751 && derived
->ns
->proc_name
->attr
.flavor
== FL_MODULE
)
2753 if (derived
->ns
->proc_name
->backend_decl
2754 && TREE_CODE (derived
->ns
->proc_name
->backend_decl
)
2757 TYPE_CONTEXT (typenode
) = derived
->ns
->proc_name
->backend_decl
;
2758 DECL_CONTEXT (TYPE_STUB_DECL (typenode
))
2759 = derived
->ns
->proc_name
->backend_decl
;
2763 derived
->backend_decl
= typenode
;
2767 for (dt
= gfc_derived_types
; dt
; dt
= dt
->next
)
2768 gfc_copy_dt_decls_ifequal (derived
, dt
->derived
, false);
2770 return derived
->backend_decl
;
2775 gfc_return_by_reference (gfc_symbol
* sym
)
2777 if (!sym
->attr
.function
)
2780 if (sym
->attr
.dimension
)
2783 if (sym
->ts
.type
== BT_CHARACTER
2784 && !sym
->attr
.is_bind_c
2785 && (!sym
->attr
.result
2786 || !sym
->ns
->proc_name
2787 || !sym
->ns
->proc_name
->attr
.is_bind_c
))
2790 /* Possibly return complex numbers by reference for g77 compatibility.
2791 We don't do this for calls to intrinsics (as the library uses the
2792 -fno-f2c calling convention), nor for calls to functions which always
2793 require an explicit interface, as no compatibility problems can
2795 if (flag_f2c
&& sym
->ts
.type
== BT_COMPLEX
2796 && !sym
->attr
.intrinsic
&& !sym
->attr
.always_explicit
)
2803 gfc_get_mixed_entry_union (gfc_namespace
*ns
)
2807 char name
[GFC_MAX_SYMBOL_LEN
+ 1];
2808 gfc_entry_list
*el
, *el2
;
2810 gcc_assert (ns
->proc_name
->attr
.mixed_entry_master
);
2811 gcc_assert (memcmp (ns
->proc_name
->name
, "master.", 7) == 0);
2813 snprintf (name
, GFC_MAX_SYMBOL_LEN
, "munion.%s", ns
->proc_name
->name
+ 7);
2815 /* Build the type node. */
2816 type
= make_node (UNION_TYPE
);
2818 TYPE_NAME (type
) = get_identifier (name
);
2820 for (el
= ns
->entries
; el
; el
= el
->next
)
2822 /* Search for duplicates. */
2823 for (el2
= ns
->entries
; el2
!= el
; el2
= el2
->next
)
2824 if (el2
->sym
->result
== el
->sym
->result
)
2828 gfc_add_field_to_struct_1 (type
,
2829 get_identifier (el
->sym
->result
->name
),
2830 gfc_sym_type (el
->sym
->result
), &chain
);
2833 /* Finish off the type. */
2834 gfc_finish_type (type
);
2835 TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
)) = 1;
2839 /* Create a "fn spec" based on the formal arguments;
2840 cf. create_function_arglist. */
2843 create_fn_spec (gfc_symbol
*sym
, tree fntype
)
2847 gfc_formal_arglist
*f
;
2850 memset (&spec
, 0, sizeof (spec
));
2854 if (sym
->attr
.entry_master
)
2855 spec
[spec_len
++] = 'R';
2856 if (gfc_return_by_reference (sym
))
2858 gfc_symbol
*result
= sym
->result
? sym
->result
: sym
;
2860 if (result
->attr
.pointer
|| sym
->attr
.proc_pointer
)
2861 spec
[spec_len
++] = '.';
2863 spec
[spec_len
++] = 'w';
2864 if (sym
->ts
.type
== BT_CHARACTER
)
2865 spec
[spec_len
++] = 'R';
2868 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2869 if (spec_len
< sizeof (spec
))
2871 if (!f
->sym
|| f
->sym
->attr
.pointer
|| f
->sym
->attr
.target
2872 || f
->sym
->attr
.external
|| f
->sym
->attr
.cray_pointer
2873 || (f
->sym
->ts
.type
== BT_DERIVED
2874 && (f
->sym
->ts
.u
.derived
->attr
.proc_pointer_comp
2875 || f
->sym
->ts
.u
.derived
->attr
.pointer_comp
))
2876 || (f
->sym
->ts
.type
== BT_CLASS
2877 && (CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.proc_pointer_comp
2878 || CLASS_DATA (f
->sym
)->ts
.u
.derived
->attr
.pointer_comp
)))
2879 spec
[spec_len
++] = '.';
2880 else if (f
->sym
->attr
.intent
== INTENT_IN
)
2881 spec
[spec_len
++] = 'r';
2883 spec
[spec_len
++] = 'w';
2886 tmp
= build_tree_list (NULL_TREE
, build_string (spec_len
, spec
));
2887 tmp
= tree_cons (get_identifier ("fn spec"), tmp
, TYPE_ATTRIBUTES (fntype
));
2888 return build_type_attribute_variant (fntype
, tmp
);
2893 gfc_get_function_type (gfc_symbol
* sym
)
2896 vec
<tree
, va_gc
> *typelist
= NULL
;
2897 gfc_formal_arglist
*f
;
2899 int alternate_return
= 0;
2900 bool is_varargs
= true;
2902 /* Make sure this symbol is a function, a subroutine or the main
2904 gcc_assert (sym
->attr
.flavor
== FL_PROCEDURE
2905 || sym
->attr
.flavor
== FL_PROGRAM
);
2907 /* To avoid recursing infinitely on recursive types, we use error_mark_node
2908 so that they can be detected here and handled further down. */
2909 if (sym
->backend_decl
== NULL
)
2910 sym
->backend_decl
= error_mark_node
;
2911 else if (sym
->backend_decl
== error_mark_node
)
2912 goto arg_type_list_done
;
2913 else if (sym
->attr
.proc_pointer
)
2914 return TREE_TYPE (TREE_TYPE (sym
->backend_decl
));
2916 return TREE_TYPE (sym
->backend_decl
);
2918 if (sym
->attr
.entry_master
)
2919 /* Additional parameter for selecting an entry point. */
2920 vec_safe_push (typelist
, gfc_array_index_type
);
2927 if (arg
->ts
.type
== BT_CHARACTER
)
2928 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
2930 /* Some functions we use an extra parameter for the return value. */
2931 if (gfc_return_by_reference (sym
))
2933 type
= gfc_sym_type (arg
);
2934 if (arg
->ts
.type
== BT_COMPLEX
2935 || arg
->attr
.dimension
2936 || arg
->ts
.type
== BT_CHARACTER
)
2937 type
= build_reference_type (type
);
2939 vec_safe_push (typelist
, type
);
2940 if (arg
->ts
.type
== BT_CHARACTER
)
2942 if (!arg
->ts
.deferred
)
2943 /* Transfer by value. */
2944 vec_safe_push (typelist
, gfc_charlen_type_node
);
2946 /* Deferred character lengths are transferred by reference
2947 so that the value can be returned. */
2948 vec_safe_push (typelist
, build_pointer_type(gfc_charlen_type_node
));
2952 /* Build the argument types for the function. */
2953 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2958 /* Evaluate constant character lengths here so that they can be
2959 included in the type. */
2960 if (arg
->ts
.type
== BT_CHARACTER
)
2961 gfc_conv_const_charlen (arg
->ts
.u
.cl
);
2963 if (arg
->attr
.flavor
== FL_PROCEDURE
)
2965 type
= gfc_get_function_type (arg
);
2966 type
= build_pointer_type (type
);
2969 type
= gfc_sym_type (arg
);
2971 /* Parameter Passing Convention
2973 We currently pass all parameters by reference.
2974 Parameters with INTENT(IN) could be passed by value.
2975 The problem arises if a function is called via an implicit
2976 prototype. In this situation the INTENT is not known.
2977 For this reason all parameters to global functions must be
2978 passed by reference. Passing by value would potentially
2979 generate bad code. Worse there would be no way of telling that
2980 this code was bad, except that it would give incorrect results.
2982 Contained procedures could pass by value as these are never
2983 used without an explicit interface, and cannot be passed as
2984 actual parameters for a dummy procedure. */
2986 vec_safe_push (typelist
, type
);
2990 if (sym
->attr
.subroutine
)
2991 alternate_return
= 1;
2995 /* Add hidden string length parameters. */
2996 for (f
= gfc_sym_get_dummy_args (sym
); f
; f
= f
->next
)
2999 if (arg
&& arg
->ts
.type
== BT_CHARACTER
&& !sym
->attr
.is_bind_c
)
3001 if (!arg
->ts
.deferred
)
3002 /* Transfer by value. */
3003 type
= gfc_charlen_type_node
;
3005 /* Deferred character lengths are transferred by reference
3006 so that the value can be returned. */
3007 type
= build_pointer_type (gfc_charlen_type_node
);
3009 vec_safe_push (typelist
, type
);
3013 if (!vec_safe_is_empty (typelist
)
3014 || sym
->attr
.is_main_program
3015 || sym
->attr
.if_source
!= IFSRC_UNKNOWN
)
3018 if (sym
->backend_decl
== error_mark_node
)
3019 sym
->backend_decl
= NULL_TREE
;
3023 if (alternate_return
)
3024 type
= integer_type_node
;
3025 else if (!sym
->attr
.function
|| gfc_return_by_reference (sym
))
3026 type
= void_type_node
;
3027 else if (sym
->attr
.mixed_entry_master
)
3028 type
= gfc_get_mixed_entry_union (sym
->ns
);
3029 else if (flag_f2c
&& sym
->ts
.type
== BT_REAL
3030 && sym
->ts
.kind
== gfc_default_real_kind
3031 && !sym
->attr
.always_explicit
)
3033 /* Special case: f2c calling conventions require that (scalar)
3034 default REAL functions return the C type double instead. f2c
3035 compatibility is only an issue with functions that don't
3036 require an explicit interface, as only these could be
3037 implemented in Fortran 77. */
3038 sym
->ts
.kind
= gfc_default_double_kind
;
3039 type
= gfc_typenode_for_spec (&sym
->ts
);
3040 sym
->ts
.kind
= gfc_default_real_kind
;
3042 else if (sym
->result
&& sym
->result
->attr
.proc_pointer
)
3043 /* Procedure pointer return values. */
3045 if (sym
->result
->attr
.result
&& strcmp (sym
->name
,"ppr@") != 0)
3047 /* Unset proc_pointer as gfc_get_function_type
3048 is called recursively. */
3049 sym
->result
->attr
.proc_pointer
= 0;
3050 type
= build_pointer_type (gfc_get_function_type (sym
->result
));
3051 sym
->result
->attr
.proc_pointer
= 1;
3054 type
= gfc_sym_type (sym
->result
);
3057 type
= gfc_sym_type (sym
);
3060 type
= build_varargs_function_type_vec (type
, typelist
);
3062 type
= build_function_type_vec (type
, typelist
);
3063 type
= create_fn_spec (sym
, type
);
3068 /* Language hooks for middle-end access to type nodes. */
3070 /* Return an integer type with BITS bits of precision,
3071 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
3074 gfc_type_for_size (unsigned bits
, int unsignedp
)
3079 for (i
= 0; i
<= MAX_INT_KINDS
; ++i
)
3081 tree type
= gfc_integer_types
[i
];
3082 if (type
&& bits
== TYPE_PRECISION (type
))
3086 /* Handle TImode as a special case because it is used by some backends
3087 (e.g. ARM) even though it is not available for normal use. */
3088 #if HOST_BITS_PER_WIDE_INT >= 64
3089 if (bits
== TYPE_PRECISION (intTI_type_node
))
3090 return intTI_type_node
;
3093 if (bits
<= TYPE_PRECISION (intQI_type_node
))
3094 return intQI_type_node
;
3095 if (bits
<= TYPE_PRECISION (intHI_type_node
))
3096 return intHI_type_node
;
3097 if (bits
<= TYPE_PRECISION (intSI_type_node
))
3098 return intSI_type_node
;
3099 if (bits
<= TYPE_PRECISION (intDI_type_node
))
3100 return intDI_type_node
;
3101 if (bits
<= TYPE_PRECISION (intTI_type_node
))
3102 return intTI_type_node
;
3106 if (bits
<= TYPE_PRECISION (unsigned_intQI_type_node
))
3107 return unsigned_intQI_type_node
;
3108 if (bits
<= TYPE_PRECISION (unsigned_intHI_type_node
))
3109 return unsigned_intHI_type_node
;
3110 if (bits
<= TYPE_PRECISION (unsigned_intSI_type_node
))
3111 return unsigned_intSI_type_node
;
3112 if (bits
<= TYPE_PRECISION (unsigned_intDI_type_node
))
3113 return unsigned_intDI_type_node
;
3114 if (bits
<= TYPE_PRECISION (unsigned_intTI_type_node
))
3115 return unsigned_intTI_type_node
;
3121 /* Return a data type that has machine mode MODE. If the mode is an
3122 integer, then UNSIGNEDP selects between signed and unsigned types. */
3125 gfc_type_for_mode (machine_mode mode
, int unsignedp
)
3129 scalar_int_mode int_mode
;
3131 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
3132 base
= gfc_real_types
;
3133 else if (GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
3134 base
= gfc_complex_types
;
3135 else if (is_a
<scalar_int_mode
> (mode
, &int_mode
))
3137 tree type
= gfc_type_for_size (GET_MODE_PRECISION (int_mode
), unsignedp
);
3138 return type
!= NULL_TREE
&& mode
== TYPE_MODE (type
) ? type
: NULL_TREE
;
3140 else if (VECTOR_MODE_P (mode
))
3142 machine_mode inner_mode
= GET_MODE_INNER (mode
);
3143 tree inner_type
= gfc_type_for_mode (inner_mode
, unsignedp
);
3144 if (inner_type
!= NULL_TREE
)
3145 return build_vector_type_for_mode (inner_type
, mode
);
3151 for (i
= 0; i
<= MAX_REAL_KINDS
; ++i
)
3153 tree type
= base
[i
];
3154 if (type
&& mode
== TYPE_MODE (type
))
3161 /* Return TRUE if TYPE is a type with a hidden descriptor, fill in INFO
3165 gfc_get_array_descr_info (const_tree type
, struct array_descr_info
*info
)
3168 bool indirect
= false;
3169 tree etype
, ptype
, t
, base_decl
;
3170 tree data_off
, dim_off
, dtype_off
, dim_size
, elem_size
;
3171 tree lower_suboff
, upper_suboff
, stride_suboff
;
3173 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3175 if (! POINTER_TYPE_P (type
))
3177 type
= TREE_TYPE (type
);
3178 if (! GFC_DESCRIPTOR_TYPE_P (type
))
3183 rank
= GFC_TYPE_ARRAY_RANK (type
);
3184 if (rank
>= (int) (sizeof (info
->dimen
) / sizeof (info
->dimen
[0])))
3187 etype
= GFC_TYPE_ARRAY_DATAPTR_TYPE (type
);
3188 gcc_assert (POINTER_TYPE_P (etype
));
3189 etype
= TREE_TYPE (etype
);
3191 /* If the type is not a scalar coarray. */
3192 if (TREE_CODE (etype
) == ARRAY_TYPE
)
3193 etype
= TREE_TYPE (etype
);
3195 /* Can't handle variable sized elements yet. */
3196 if (int_size_in_bytes (etype
) <= 0)
3198 /* Nor non-constant lower bounds in assumed shape arrays. */
3199 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3200 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3202 for (dim
= 0; dim
< rank
; dim
++)
3203 if (GFC_TYPE_ARRAY_LBOUND (type
, dim
) == NULL_TREE
3204 || TREE_CODE (GFC_TYPE_ARRAY_LBOUND (type
, dim
)) != INTEGER_CST
)
3208 memset (info
, '\0', sizeof (*info
));
3209 info
->ndimensions
= rank
;
3210 info
->ordering
= array_descr_ordering_column_major
;
3211 info
->element_type
= etype
;
3212 ptype
= build_pointer_type (gfc_array_index_type
);
3213 base_decl
= GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
);
3216 base_decl
= make_node (DEBUG_EXPR_DECL
);
3217 DECL_ARTIFICIAL (base_decl
) = 1;
3218 TREE_TYPE (base_decl
) = indirect
? build_pointer_type (ptype
) : ptype
;
3219 SET_DECL_MODE (base_decl
, TYPE_MODE (TREE_TYPE (base_decl
)));
3220 GFC_TYPE_ARRAY_BASE_DECL (type
, indirect
) = base_decl
;
3222 info
->base_decl
= base_decl
;
3224 base_decl
= build1 (INDIRECT_REF
, ptype
, base_decl
);
3226 elem_size
= fold_convert (gfc_array_index_type
, TYPE_SIZE_UNIT (etype
));
3228 gfc_get_descriptor_offsets_for_info (type
, &data_off
, &dtype_off
, &dim_off
,
3229 &dim_size
, &stride_suboff
,
3230 &lower_suboff
, &upper_suboff
);
3233 if (!integer_zerop (data_off
))
3234 t
= fold_build_pointer_plus (t
, data_off
);
3235 t
= build1 (NOP_EXPR
, build_pointer_type (ptr_type_node
), t
);
3236 info
->data_location
= build1 (INDIRECT_REF
, ptr_type_node
, t
);
3237 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ALLOCATABLE
)
3238 info
->allocated
= build2 (NE_EXPR
, boolean_type_node
,
3239 info
->data_location
, null_pointer_node
);
3240 else if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER
3241 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_POINTER_CONT
)
3242 info
->associated
= build2 (NE_EXPR
, boolean_type_node
,
3243 info
->data_location
, null_pointer_node
);
3244 if ((GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK
3245 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_RANK_CONT
)
3246 && dwarf_version
>= 5)
3249 info
->ndimensions
= 1;
3251 if (!integer_zerop (dtype_off
))
3252 t
= fold_build_pointer_plus (t
, dtype_off
);
3253 t
= build1 (NOP_EXPR
, build_pointer_type (gfc_array_index_type
), t
);
3254 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3255 info
->rank
= build2 (BIT_AND_EXPR
, gfc_array_index_type
, t
,
3256 build_int_cst (gfc_array_index_type
,
3257 GFC_DTYPE_RANK_MASK
));
3258 t
= build0 (PLACEHOLDER_EXPR
, TREE_TYPE (dim_off
));
3259 t
= size_binop (MULT_EXPR
, t
, dim_size
);
3260 dim_off
= build2 (PLUS_EXPR
, TREE_TYPE (dim_off
), t
, dim_off
);
3263 for (dim
= 0; dim
< rank
; dim
++)
3265 t
= fold_build_pointer_plus (base_decl
,
3266 size_binop (PLUS_EXPR
,
3267 dim_off
, lower_suboff
));
3268 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3269 info
->dimen
[dim
].lower_bound
= t
;
3270 t
= fold_build_pointer_plus (base_decl
,
3271 size_binop (PLUS_EXPR
,
3272 dim_off
, upper_suboff
));
3273 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3274 info
->dimen
[dim
].upper_bound
= t
;
3275 if (GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE
3276 || GFC_TYPE_ARRAY_AKIND (type
) == GFC_ARRAY_ASSUMED_SHAPE_CONT
)
3278 /* Assumed shape arrays have known lower bounds. */
3279 info
->dimen
[dim
].upper_bound
3280 = build2 (MINUS_EXPR
, gfc_array_index_type
,
3281 info
->dimen
[dim
].upper_bound
,
3282 info
->dimen
[dim
].lower_bound
);
3283 info
->dimen
[dim
].lower_bound
3284 = fold_convert (gfc_array_index_type
,
3285 GFC_TYPE_ARRAY_LBOUND (type
, dim
));
3286 info
->dimen
[dim
].upper_bound
3287 = build2 (PLUS_EXPR
, gfc_array_index_type
,
3288 info
->dimen
[dim
].lower_bound
,
3289 info
->dimen
[dim
].upper_bound
);
3291 t
= fold_build_pointer_plus (base_decl
,
3292 size_binop (PLUS_EXPR
,
3293 dim_off
, stride_suboff
));
3294 t
= build1 (INDIRECT_REF
, gfc_array_index_type
, t
);
3295 t
= build2 (MULT_EXPR
, gfc_array_index_type
, t
, elem_size
);
3296 info
->dimen
[dim
].stride
= t
;
3298 dim_off
= size_binop (PLUS_EXPR
, dim_off
, dim_size
);
3305 /* Create a type to handle vector subscripts for coarray library calls. It
3307 struct caf_vector_t {
3308 size_t nvec; // size of the vector
3315 ptrdiff_t lower_bound;
3316 ptrdiff_t upper_bound;
3321 where nvec == 0 for DIMEN_ELEMENT or DIMEN_RANGE and nvec being the vector
3322 size in case of DIMEN_VECTOR, where kind is the integer type of the vector. */
3325 gfc_get_caf_vector_type (int dim
)
3327 static tree vector_types
[GFC_MAX_DIMENSIONS
];
3328 static tree vec_type
= NULL_TREE
;
3329 tree triplet_struct_type
, vect_struct_type
, union_type
, tmp
, *chain
;
3331 if (vector_types
[dim
-1] != NULL_TREE
)
3332 return vector_types
[dim
-1];
3334 if (vec_type
== NULL_TREE
)
3337 vect_struct_type
= make_node (RECORD_TYPE
);
3338 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3339 get_identifier ("vector"),
3340 pvoid_type_node
, &chain
);
3341 TREE_NO_WARNING (tmp
) = 1;
3342 tmp
= gfc_add_field_to_struct_1 (vect_struct_type
,
3343 get_identifier ("kind"),
3344 integer_type_node
, &chain
);
3345 TREE_NO_WARNING (tmp
) = 1;
3346 gfc_finish_type (vect_struct_type
);
3349 triplet_struct_type
= make_node (RECORD_TYPE
);
3350 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3351 get_identifier ("lower_bound"),
3352 gfc_array_index_type
, &chain
);
3353 TREE_NO_WARNING (tmp
) = 1;
3354 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
,
3355 get_identifier ("upper_bound"),
3356 gfc_array_index_type
, &chain
);
3357 TREE_NO_WARNING (tmp
) = 1;
3358 tmp
= gfc_add_field_to_struct_1 (triplet_struct_type
, get_identifier ("stride"),
3359 gfc_array_index_type
, &chain
);
3360 TREE_NO_WARNING (tmp
) = 1;
3361 gfc_finish_type (triplet_struct_type
);
3364 union_type
= make_node (UNION_TYPE
);
3365 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3366 vect_struct_type
, &chain
);
3367 TREE_NO_WARNING (tmp
) = 1;
3368 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("triplet"),
3369 triplet_struct_type
, &chain
);
3370 TREE_NO_WARNING (tmp
) = 1;
3371 gfc_finish_type (union_type
);
3374 vec_type
= make_node (RECORD_TYPE
);
3375 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("nvec"),
3376 size_type_node
, &chain
);
3377 TREE_NO_WARNING (tmp
) = 1;
3378 tmp
= gfc_add_field_to_struct_1 (vec_type
, get_identifier ("u"),
3379 union_type
, &chain
);
3380 TREE_NO_WARNING (tmp
) = 1;
3381 gfc_finish_type (vec_type
);
3382 TYPE_NAME (vec_type
) = get_identifier ("caf_vector_t");
3385 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3386 gfc_rank_cst
[dim
-1]);
3387 vector_types
[dim
-1] = build_array_type (vec_type
, tmp
);
3388 return vector_types
[dim
-1];
3393 gfc_get_caf_reference_type ()
3395 static tree reference_type
= NULL_TREE
;
3396 tree c_struct_type
, s_struct_type
, v_struct_type
, union_type
, dim_union_type
,
3397 a_struct_type
, u_union_type
, tmp
, *chain
;
3399 if (reference_type
!= NULL_TREE
)
3400 return reference_type
;
3403 c_struct_type
= make_node (RECORD_TYPE
);
3404 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3405 get_identifier ("offset"),
3406 gfc_array_index_type
, &chain
);
3407 TREE_NO_WARNING (tmp
) = 1;
3408 tmp
= gfc_add_field_to_struct_1 (c_struct_type
,
3409 get_identifier ("caf_token_offset"),
3410 gfc_array_index_type
, &chain
);
3411 TREE_NO_WARNING (tmp
) = 1;
3412 gfc_finish_type (c_struct_type
);
3415 s_struct_type
= make_node (RECORD_TYPE
);
3416 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3417 get_identifier ("start"),
3418 gfc_array_index_type
, &chain
);
3419 TREE_NO_WARNING (tmp
) = 1;
3420 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3421 get_identifier ("end"),
3422 gfc_array_index_type
, &chain
);
3423 TREE_NO_WARNING (tmp
) = 1;
3424 tmp
= gfc_add_field_to_struct_1 (s_struct_type
,
3425 get_identifier ("stride"),
3426 gfc_array_index_type
, &chain
);
3427 TREE_NO_WARNING (tmp
) = 1;
3428 gfc_finish_type (s_struct_type
);
3431 v_struct_type
= make_node (RECORD_TYPE
);
3432 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3433 get_identifier ("vector"),
3434 pvoid_type_node
, &chain
);
3435 TREE_NO_WARNING (tmp
) = 1;
3436 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3437 get_identifier ("nvec"),
3438 size_type_node
, &chain
);
3439 TREE_NO_WARNING (tmp
) = 1;
3440 tmp
= gfc_add_field_to_struct_1 (v_struct_type
,
3441 get_identifier ("kind"),
3442 integer_type_node
, &chain
);
3443 TREE_NO_WARNING (tmp
) = 1;
3444 gfc_finish_type (v_struct_type
);
3447 union_type
= make_node (UNION_TYPE
);
3448 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("s"),
3449 s_struct_type
, &chain
);
3450 TREE_NO_WARNING (tmp
) = 1;
3451 tmp
= gfc_add_field_to_struct_1 (union_type
, get_identifier ("v"),
3452 v_struct_type
, &chain
);
3453 TREE_NO_WARNING (tmp
) = 1;
3454 gfc_finish_type (union_type
);
3456 tmp
= build_range_type (gfc_array_index_type
, gfc_index_zero_node
,
3457 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1]);
3458 dim_union_type
= build_array_type (union_type
, tmp
);
3461 a_struct_type
= make_node (RECORD_TYPE
);
3462 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("mode"),
3463 build_array_type (unsigned_char_type_node
,
3464 build_range_type (gfc_array_index_type
,
3465 gfc_index_zero_node
,
3466 gfc_rank_cst
[GFC_MAX_DIMENSIONS
- 1])),
3468 TREE_NO_WARNING (tmp
) = 1;
3469 tmp
= gfc_add_field_to_struct_1 (a_struct_type
,
3470 get_identifier ("static_array_type"),
3471 integer_type_node
, &chain
);
3472 TREE_NO_WARNING (tmp
) = 1;
3473 tmp
= gfc_add_field_to_struct_1 (a_struct_type
, get_identifier ("dim"),
3474 dim_union_type
, &chain
);
3475 TREE_NO_WARNING (tmp
) = 1;
3476 gfc_finish_type (a_struct_type
);
3479 u_union_type
= make_node (UNION_TYPE
);
3480 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("c"),
3481 c_struct_type
, &chain
);
3482 TREE_NO_WARNING (tmp
) = 1;
3483 tmp
= gfc_add_field_to_struct_1 (u_union_type
, get_identifier ("a"),
3484 a_struct_type
, &chain
);
3485 TREE_NO_WARNING (tmp
) = 1;
3486 gfc_finish_type (u_union_type
);
3489 reference_type
= make_node (RECORD_TYPE
);
3490 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("next"),
3491 build_pointer_type (reference_type
), &chain
);
3492 TREE_NO_WARNING (tmp
) = 1;
3493 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("type"),
3494 integer_type_node
, &chain
);
3495 TREE_NO_WARNING (tmp
) = 1;
3496 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("item_size"),
3497 size_type_node
, &chain
);
3498 TREE_NO_WARNING (tmp
) = 1;
3499 tmp
= gfc_add_field_to_struct_1 (reference_type
, get_identifier ("u"),
3500 u_union_type
, &chain
);
3501 TREE_NO_WARNING (tmp
) = 1;
3502 gfc_finish_type (reference_type
);
3503 TYPE_NAME (reference_type
) = get_identifier ("caf_reference_t");
3505 return reference_type
;
3508 #include "gt-fortran-trans-types.h"