1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2004, Free Software Foundation, Inc. *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 2, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING. If not, write *
19 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, USA. *
22 * GNAT was originally developed by the GNAT team at New York University. *
23 * Extensive contributions were provided by Ada Core Technologies Inc. *
25 ****************************************************************************/
29 #include "coretypes.h"
55 /* Provide default values for the macros controlling stack checking.
56 This is copied from GCC's expr.h. */
58 #ifndef STACK_CHECK_BUILTIN
59 #define STACK_CHECK_BUILTIN 0
61 #ifndef STACK_CHECK_PROBE_INTERVAL
62 #define STACK_CHECK_PROBE_INTERVAL 4096
64 #ifndef STACK_CHECK_MAX_FRAME_SIZE
65 #define STACK_CHECK_MAX_FRAME_SIZE \
66 (STACK_CHECK_PROBE_INTERVAL - UNITS_PER_WORD)
68 #ifndef STACK_CHECK_MAX_VAR_SIZE
69 #define STACK_CHECK_MAX_VAR_SIZE (STACK_CHECK_MAX_FRAME_SIZE / 100)
72 /* These two variables are used to defer recursively expanding incomplete
73 types while we are processing a record or subprogram type. */
75 static int defer_incomplete_level
= 0;
76 static struct incomplete
78 struct incomplete
*next
;
81 } *defer_incomplete_list
= 0;
83 static void copy_alias_set (tree
, tree
);
84 static tree
substitution_list (Entity_Id
, Entity_Id
, tree
, int);
85 static int allocatable_size_p (tree
, int);
86 static struct attrib
*build_attr_list (Entity_Id
);
87 static tree
elaborate_expression (Node_Id
, Entity_Id
, tree
, int, int, int);
88 static int is_variable_size (tree
);
89 static tree
elaborate_expression_1 (Node_Id
, Entity_Id
, tree
, tree
, int, int);
90 static tree
make_packable_type (tree
);
91 static tree
maybe_pad_type (tree
, tree
, unsigned int, Entity_Id
, const char *,
93 static tree
gnat_to_gnu_field (Entity_Id
, tree
, int, int);
94 static void components_to_record (tree
, Node_Id
, tree
, int, int, tree
*,
96 static int compare_field_bitpos (const PTR
, const PTR
);
97 static Uint
annotate_value (tree
);
98 static void annotate_rep (Entity_Id
, tree
);
99 static tree
compute_field_positions (tree
, tree
, tree
, tree
, unsigned int);
100 static tree
validate_size (Uint
, tree
, Entity_Id
, enum tree_code
, int, int);
101 static void set_rm_size (Uint
, tree
, Entity_Id
);
102 static tree
make_type_from_size (tree
, tree
, int);
103 static unsigned int validate_alignment (Uint
, Entity_Id
, unsigned int);
104 static void check_ok_for_atomic (tree
, Entity_Id
, int);
106 /* Given GNAT_ENTITY, an entity in the incoming GNAT tree, return a
107 GCC type corresponding to that entity. GNAT_ENTITY is assumed to
108 refer to an Ada type. */
111 gnat_to_gnu_type (Entity_Id gnat_entity
)
115 /* The back end never attempts to annotate generic types */
116 if (Is_Generic_Type (gnat_entity
) && type_annotate_only
)
117 return void_type_node
;
119 /* Convert the ada entity type into a GCC TYPE_DECL node. */
120 gnu_decl
= gnat_to_gnu_entity (gnat_entity
, NULL_TREE
, 0);
121 if (TREE_CODE (gnu_decl
) != TYPE_DECL
)
124 return TREE_TYPE (gnu_decl
);
127 /* Given GNAT_ENTITY, a GNAT defining identifier node, which denotes some Ada
128 entity, this routine returns the equivalent GCC tree for that entity
129 (an ..._DECL node) and associates the ..._DECL node with the input GNAT
132 If GNAT_ENTITY is a variable or a constant declaration, GNU_EXPR gives its
133 initial value (in GCC tree form). This is optional for variables.
134 For renamed entities, GNU_EXPR gives the object being renamed.
136 DEFINITION is nonzero if this call is intended for a definition. This is
137 used for separate compilation where it necessary to know whether an
138 external declaration or a definition should be created if the GCC equivalent
139 was not created previously. The value of 1 is normally used for a non-zero
140 DEFINITION, but a value of 2 is used in special circumstances, defined in
144 gnat_to_gnu_entity (Entity_Id gnat_entity
, tree gnu_expr
, int definition
)
148 /* Contains the gnu XXXX_DECL tree node which is equivalent to the input
149 GNAT tree. This node will be associated with the GNAT node by calling
150 the save_gnu_tree routine at the end of the `switch' statement. */
152 /* Nonzero if we have already saved gnu_decl as a gnat association. */
154 /* Nonzero if we incremented defer_incomplete_level. */
155 int this_deferred
= 0;
156 /* Nonzero if we incremented force_global. */
158 /* Nonzero if we should check to see if elaborated during processing. */
159 int maybe_present
= 0;
160 /* Nonzero if we made GNU_DECL and its type here. */
161 int this_made_decl
= 0;
162 struct attrib
*attr_list
= 0;
163 int debug_info_p
= (Needs_Debug_Info (gnat_entity
)
164 || debug_info_level
== DINFO_LEVEL_VERBOSE
);
165 Entity_Kind kind
= Ekind (gnat_entity
);
168 = ((Known_Esize (gnat_entity
)
169 && UI_Is_In_Int_Range (Esize (gnat_entity
)))
170 ? MIN (UI_To_Int (Esize (gnat_entity
)),
171 IN (kind
, Float_Kind
)
172 ? fp_prec_to_size (LONG_DOUBLE_TYPE_SIZE
)
173 : IN (kind
, Access_Kind
) ? POINTER_SIZE
* 2
174 : LONG_LONG_TYPE_SIZE
)
175 : LONG_LONG_TYPE_SIZE
);
178 = ((Is_Imported (gnat_entity
) && No (Address_Clause (gnat_entity
)))
179 || From_With_Type (gnat_entity
));
180 unsigned int align
= 0;
182 /* Since a use of an Itype is a definition, process it as such if it
183 is not in a with'ed unit. */
185 if (! definition
&& Is_Itype (gnat_entity
)
186 && ! present_gnu_tree (gnat_entity
)
187 && In_Extended_Main_Code_Unit (gnat_entity
))
189 /* Ensure that we are in a subprogram mentioned in the Scope
190 chain of this entity, our current scope is global,
191 or that we encountered a task or entry (where we can't currently
192 accurately check scoping). */
193 if (current_function_decl
== 0
194 || DECL_ELABORATION_PROC_P (current_function_decl
))
196 process_type (gnat_entity
);
197 return get_gnu_tree (gnat_entity
);
200 for (gnat_temp
= Scope (gnat_entity
);
201 Present (gnat_temp
); gnat_temp
= Scope (gnat_temp
))
203 if (Is_Type (gnat_temp
))
204 gnat_temp
= Underlying_Type (gnat_temp
);
206 if (Ekind (gnat_temp
) == E_Subprogram_Body
)
208 = Corresponding_Spec (Parent (Declaration_Node (gnat_temp
)));
210 if (IN (Ekind (gnat_temp
), Subprogram_Kind
)
211 && Present (Protected_Body_Subprogram (gnat_temp
)))
212 gnat_temp
= Protected_Body_Subprogram (gnat_temp
);
214 if (Ekind (gnat_temp
) == E_Entry
215 || Ekind (gnat_temp
) == E_Entry_Family
216 || Ekind (gnat_temp
) == E_Task_Type
217 || (IN (Ekind (gnat_temp
), Subprogram_Kind
)
218 && present_gnu_tree (gnat_temp
)
219 && (current_function_decl
220 == gnat_to_gnu_entity (gnat_temp
, NULL_TREE
, 0))))
222 process_type (gnat_entity
);
223 return get_gnu_tree (gnat_entity
);
227 /* gigi abort 122 means that the entity "gnat_entity" has an incorrect
228 scope, i.e. that its scope does not correspond to the subprogram
229 in which it is declared */
233 /* If this is entity 0, something went badly wrong. */
234 if (gnat_entity
== 0)
237 /* If we've already processed this entity, return what we got last time.
238 If we are defining the node, we should not have already processed it.
239 In that case, we will abort below when we try to save a new GCC tree for
240 this object. We also need to handle the case of getting a dummy type
241 when a Full_View exists. */
243 if (present_gnu_tree (gnat_entity
)
245 || (Is_Type (gnat_entity
) && imported_p
)))
247 gnu_decl
= get_gnu_tree (gnat_entity
);
249 if (TREE_CODE (gnu_decl
) == TYPE_DECL
250 && TYPE_IS_DUMMY_P (TREE_TYPE (gnu_decl
))
251 && IN (kind
, Incomplete_Or_Private_Kind
)
252 && Present (Full_View (gnat_entity
)))
254 gnu_decl
= gnat_to_gnu_entity (Full_View (gnat_entity
),
257 save_gnu_tree (gnat_entity
, NULL_TREE
, 0);
258 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
264 /* If this is a numeric or enumeral type, or an access type, a nonzero
265 Esize must be specified unless it was specified by the programmer. */
266 if ((IN (kind
, Numeric_Kind
) || IN (kind
, Enumeration_Kind
)
267 || (IN (kind
, Access_Kind
)
268 && kind
!= E_Access_Protected_Subprogram_Type
269 && kind
!= E_Access_Subtype
))
270 && Unknown_Esize (gnat_entity
)
271 && ! Has_Size_Clause (gnat_entity
))
274 /* Likewise, RM_Size must be specified for all discrete and fixed-point
276 if (IN (kind
, Discrete_Or_Fixed_Point_Kind
)
277 && Unknown_RM_Size (gnat_entity
))
280 /* Get the name of the entity and set up the line number and filename of
281 the original definition for use in any decl we make. */
283 gnu_entity_id
= get_entity_name (gnat_entity
);
284 set_lineno (gnat_entity
, 0);
286 /* If we get here, it means we have not yet done anything with this
287 entity. If we are not defining it here, it must be external,
288 otherwise we should have defined it already. */
289 if (! definition
&& ! Is_Public (gnat_entity
)
290 && ! type_annotate_only
291 && kind
!= E_Discriminant
&& kind
!= E_Component
293 && ! (kind
== E_Constant
&& Present (Full_View (gnat_entity
)))
295 && !IN (kind
, Type_Kind
)
300 /* For cases when we are not defining (i.e., we are referencing from
301 another compilation unit) Public entities, show we are at global level
302 for the purpose of computing sizes. Don't do this for components or
303 discriminants since the relevant test is whether or not the record is
305 if (! definition
&& Is_Public (gnat_entity
)
306 && ! Is_Statically_Allocated (gnat_entity
)
307 && kind
!= E_Discriminant
&& kind
!= E_Component
)
308 force_global
++, this_global
= 1;
310 /* Handle any attributes. */
311 if (Has_Gigi_Rep_Item (gnat_entity
))
312 attr_list
= build_attr_list (gnat_entity
);
317 /* If this is a use of a deferred constant, get its full
319 if (! definition
&& Present (Full_View (gnat_entity
)))
321 gnu_decl
= gnat_to_gnu_entity (Full_View (gnat_entity
),
322 gnu_expr
, definition
);
327 /* If we have an external constant that we are not defining,
328 get the expression that is was defined to represent. We
329 may throw that expression away later if it is not a
331 Do not retrieve the expression if it is an aggregate, because
332 in complex instantiation contexts it may not be expanded */
335 && Present (Expression (Declaration_Node (gnat_entity
)))
336 && ! No_Initialization (Declaration_Node (gnat_entity
))
337 && Nkind (Expression (Declaration_Node (gnat_entity
)))
339 gnu_expr
= gnat_to_gnu (Expression (Declaration_Node (gnat_entity
)));
341 /* Ignore deferred constant definitions; they are processed fully in the
342 front-end. For deferred constant references, get the full
343 definition. On the other hand, constants that are renamings are
344 handled like variable renamings. If No_Initialization is set, this is
345 not a deferred constant but a constant whose value is built
348 if (definition
&& gnu_expr
== 0
349 && ! No_Initialization (Declaration_Node (gnat_entity
))
350 && No (Renamed_Object (gnat_entity
)))
352 gnu_decl
= error_mark_node
;
356 else if (! definition
&& IN (kind
, Incomplete_Or_Private_Kind
)
357 && Present (Full_View (gnat_entity
)))
359 gnu_decl
= gnat_to_gnu_entity (Full_View (gnat_entity
),
368 /* We used to special case VMS exceptions here to directly map them to
369 their associated condition code. Since this code had to be masked
370 dynamically to strip off the severity bits, this caused trouble in
371 the GCC/ZCX case because the "type" pointers we store in the tables
372 have to be static. We now don't special case here anymore, and let
373 the regular processing take place, which leaves us with a regular
374 exception data object for VMS exceptions too. The condition code
375 mapping is taken care of by the front end and the bitmasking by the
382 /* The GNAT record where the component was defined. */
383 Entity_Id gnat_record
= Underlying_Type (Scope (gnat_entity
));
385 /* If the variable is an inherited record component (in the case of
386 extended record types), just return the inherited entity, which
387 must be a FIELD_DECL. Likewise for discriminants.
388 For discriminants of untagged records which have explicit
389 stored discriminants, return the entity for the corresponding
390 stored discriminant. Also use Original_Record_Component
391 if the record has a private extension. */
393 if ((Base_Type (gnat_record
) == gnat_record
394 || Ekind (Scope (gnat_entity
)) == E_Private_Subtype
395 || Ekind (Scope (gnat_entity
)) == E_Record_Subtype_With_Private
396 || Ekind (Scope (gnat_entity
)) == E_Record_Type_With_Private
)
397 && Present (Original_Record_Component (gnat_entity
))
398 && Original_Record_Component (gnat_entity
) != gnat_entity
)
401 = gnat_to_gnu_entity (Original_Record_Component (gnat_entity
),
402 gnu_expr
, definition
);
407 /* If the enclosing record has explicit stored discriminants,
408 then it is an untagged record. If the Corresponding_Discriminant
409 is not empty then this must be a renamed discriminant and its
410 Original_Record_Component must point to the corresponding explicit
411 stored discriminant (i.e., we should have taken the previous
414 else if (Present (Corresponding_Discriminant (gnat_entity
))
415 && Is_Tagged_Type (gnat_record
))
417 /* A tagged record has no explicit stored discriminants. */
419 if (First_Discriminant (gnat_record
)
420 != First_Stored_Discriminant (gnat_record
))
424 = gnat_to_gnu_entity (Corresponding_Discriminant (gnat_entity
),
425 gnu_expr
, definition
);
430 /* If the enclosing record has explicit stored discriminants,
431 then it is an untagged record. If the Corresponding_Discriminant
432 is not empty then this must be a renamed discriminant and its
433 Original_Record_Component must point to the corresponding explicit
434 stored discriminant (i.e., we should have taken the first
437 else if (Present (Corresponding_Discriminant (gnat_entity
))
438 && (First_Discriminant (gnat_record
)
439 != First_Stored_Discriminant (gnat_record
)))
442 /* Otherwise, if we are not defining this and we have no GCC type
443 for the containing record, make one for it. Then we should
444 have made our own equivalent. */
445 else if (! definition
&& ! present_gnu_tree (gnat_record
))
447 /* ??? If this is in a record whose scope is a protected
448 type and we have an Original_Record_Component, use it.
449 This is a workaround for major problems in protected type
452 Entity_Id Scop
= Scope (Scope (gnat_entity
));
453 if ((Is_Protected_Type (Scop
)
454 || (Is_Private_Type (Scop
)
455 && Present (Full_View (Scop
))
456 && Is_Protected_Type (Full_View (Scop
))))
457 && Present (Original_Record_Component (gnat_entity
)))
460 = gnat_to_gnu_entity (Original_Record_Component
462 gnu_expr
, definition
);
467 gnat_to_gnu_entity (Scope (gnat_entity
), NULL_TREE
, 0);
468 gnu_decl
= get_gnu_tree (gnat_entity
);
473 /* Here we have no GCC type and this is a reference rather than a
474 definition. This should never happen. Most likely the cause is a
475 reference before declaration in the gnat tree for gnat_entity. */
480 case E_Loop_Parameter
:
481 case E_Out_Parameter
:
484 /* Simple variables, loop variables, OUT parameters, and exceptions. */
489 = ((kind
== E_Constant
|| kind
== E_Variable
)
490 && ! Is_Statically_Allocated (gnat_entity
)
491 && Is_True_Constant (gnat_entity
)
492 && (((Nkind (Declaration_Node (gnat_entity
))
493 == N_Object_Declaration
)
494 && Present (Expression (Declaration_Node (gnat_entity
))))
495 || Present (Renamed_Object (gnat_entity
))));
496 int inner_const_flag
= const_flag
;
497 int static_p
= Is_Statically_Allocated (gnat_entity
);
498 tree gnu_ext_name
= NULL_TREE
;
500 if (Present (Renamed_Object (gnat_entity
)) && ! definition
)
502 if (kind
== E_Exception
)
503 gnu_expr
= gnat_to_gnu_entity (Renamed_Entity (gnat_entity
),
506 gnu_expr
= gnat_to_gnu (Renamed_Object (gnat_entity
));
509 /* Get the type after elaborating the renamed object. */
510 gnu_type
= gnat_to_gnu_type (Etype (gnat_entity
));
512 /* If this is a loop variable, its type should be the base type.
513 This is because the code for processing a loop determines whether
514 a normal loop end test can be done by comparing the bounds of the
515 loop against those of the base type, which is presumed to be the
516 size used for computation. But this is not correct when the size
517 of the subtype is smaller than the type. */
518 if (kind
== E_Loop_Parameter
)
519 gnu_type
= get_base_type (gnu_type
);
521 /* Reject non-renamed objects whose types are unconstrained arrays or
522 any object whose type is a dummy type or VOID_TYPE. */
524 if ((TREE_CODE (gnu_type
) == UNCONSTRAINED_ARRAY_TYPE
525 && No (Renamed_Object (gnat_entity
)))
526 || TYPE_IS_DUMMY_P (gnu_type
)
527 || TREE_CODE (gnu_type
) == VOID_TYPE
)
529 if (type_annotate_only
)
530 return error_mark_node
;
535 /* If we are defining the object, see if it has a Size value and
536 validate it if so. If we are not defining the object and a Size
537 clause applies, simply retrieve the value. We don't want to ignore
538 the clause and it is expected to have been validated already. Then
539 get the new type, if any. */
541 gnu_size
= validate_size (Esize (gnat_entity
), gnu_type
,
542 gnat_entity
, VAR_DECL
, 0,
543 Has_Size_Clause (gnat_entity
));
544 else if (Has_Size_Clause (gnat_entity
))
545 gnu_size
= UI_To_gnu (Esize (gnat_entity
), bitsizetype
);
550 = make_type_from_size (gnu_type
, gnu_size
,
551 Has_Biased_Representation (gnat_entity
));
553 if (operand_equal_p (TYPE_SIZE (gnu_type
), gnu_size
, 0))
557 /* If this object has self-referential size, it must be a record with
558 a default value. We are supposed to allocate an object of the
559 maximum size in this case unless it is a constant with an
560 initializing expression, in which case we can get the size from
561 that. Note that the resulting size may still be a variable, so
562 this may end up with an indirect allocation. */
564 if (No (Renamed_Object (gnat_entity
))
565 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
)))
567 if (gnu_expr
!= 0 && kind
== E_Constant
)
569 = SUBSTITUTE_PLACEHOLDER_IN_EXPR
570 (TYPE_SIZE (TREE_TYPE (gnu_expr
)), gnu_expr
);
572 /* We may have no GNU_EXPR because No_Initialization is
573 set even though there's an Expression. */
574 else if (kind
== E_Constant
575 && (Nkind (Declaration_Node (gnat_entity
))
576 == N_Object_Declaration
)
577 && Present (Expression (Declaration_Node (gnat_entity
))))
579 = TYPE_SIZE (gnat_to_gnu_type
581 (Expression (Declaration_Node (gnat_entity
)))));
583 gnu_size
= max_size (TYPE_SIZE (gnu_type
), 1);
586 /* If the size is zero bytes, make it one byte since some linkers have
587 trouble with zero-sized objects. If the object will have a
588 template, that will make it nonzero so don't bother. Also avoid
589 doing that for an object renaming or an object with an address
590 clause, as we would lose useful information on the view size
591 (e.g. for null array slices) and we are not allocating the object
593 if (((gnu_size
!= 0 && integer_zerop (gnu_size
))
594 || (TYPE_SIZE (gnu_type
) != 0
595 && integer_zerop (TYPE_SIZE (gnu_type
))))
596 && (! Is_Constr_Subt_For_UN_Aliased (Etype (gnat_entity
))
597 || ! Is_Array_Type (Etype (gnat_entity
)))
598 && ! Present (Renamed_Object (gnat_entity
))
599 && ! Present (Address_Clause (gnat_entity
)))
600 gnu_size
= bitsize_unit_node
;
602 /* If an alignment is specified, use it if valid. Note that
603 exceptions are objects but don't have alignments. */
604 if (kind
!= E_Exception
&& Known_Alignment (gnat_entity
))
606 if (No (Alignment (gnat_entity
)))
610 = validate_alignment (Alignment (gnat_entity
), gnat_entity
,
611 TYPE_ALIGN (gnu_type
));
614 /* If this is an atomic object with no specified size and alignment,
615 but where the size of the type is a constant, set the alignment to
616 the lowest power of two greater than the size, or to the
617 biggest meaningful alignment, whichever is smaller. */
619 if (Is_Atomic (gnat_entity
) && gnu_size
== 0 && align
== 0
620 && TREE_CODE (TYPE_SIZE (gnu_type
)) == INTEGER_CST
)
622 if (! host_integerp (TYPE_SIZE (gnu_type
), 1)
623 || 0 <= compare_tree_int (TYPE_SIZE (gnu_type
),
625 align
= BIGGEST_ALIGNMENT
;
627 align
= ((unsigned int) 1
628 << (floor_log2 (tree_low_cst
629 (TYPE_SIZE (gnu_type
), 1) - 1)
633 /* If the object is set to have atomic components, find the component
634 type and validate it.
636 ??? Note that we ignore Has_Volatile_Components on objects; it's
637 not at all clear what to do in that case. */
639 if (Has_Atomic_Components (gnat_entity
))
642 = (TREE_CODE (gnu_type
) == ARRAY_TYPE
643 ? TREE_TYPE (gnu_type
) : gnu_type
);
645 while (TREE_CODE (gnu_inner
) == ARRAY_TYPE
646 && TYPE_MULTI_ARRAY_P (gnu_inner
))
647 gnu_inner
= TREE_TYPE (gnu_inner
);
649 check_ok_for_atomic (gnu_inner
, gnat_entity
, 1);
652 /* Now check if the type of the object allows atomic access. Note
653 that we must test the type, even if this object has size and
654 alignment to allow such access, because we will be going
655 inside the padded record to assign to the object. We could fix
656 this by always copying via an intermediate value, but it's not
657 clear it's worth the effort. */
658 if (Is_Atomic (gnat_entity
))
659 check_ok_for_atomic (gnu_type
, gnat_entity
, 0);
661 /* If this is an aliased object with an unconstrained nominal subtype,
662 make a type that includes the template. */
663 if (Is_Constr_Subt_For_UN_Aliased (Etype (gnat_entity
))
664 && Is_Array_Type (Etype (gnat_entity
))
665 && ! type_annotate_only
)
668 = TREE_TYPE (gnat_to_gnu_type (Base_Type (Etype (gnat_entity
))));
670 = TREE_TYPE (TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_fat
))));
673 = build_unc_object_type (gnu_temp_type
, gnu_type
,
674 concat_id_with_name (gnu_entity_id
,
678 #ifdef MINIMUM_ATOMIC_ALIGNMENT
679 /* If the size is a constant and no alignment is specified, force
680 the alignment to be the minimum valid atomic alignment. The
681 restriction on constant size avoids problems with variable-size
682 temporaries; if the size is variable, there's no issue with
683 atomic access. Also don't do this for a constant, since it isn't
684 necessary and can interfere with constant replacement. Finally,
685 do not do it for Out parameters since that creates an
686 size inconsistency with In parameters. */
687 if (align
== 0 && MINIMUM_ATOMIC_ALIGNMENT
> TYPE_ALIGN (gnu_type
)
688 && ! FLOAT_TYPE_P (gnu_type
)
689 && ! const_flag
&& No (Renamed_Object (gnat_entity
))
690 && ! imported_p
&& No (Address_Clause (gnat_entity
))
691 && kind
!= E_Out_Parameter
692 && (gnu_size
!= 0 ? TREE_CODE (gnu_size
) == INTEGER_CST
693 : TREE_CODE (TYPE_SIZE (gnu_type
)) == INTEGER_CST
))
694 align
= MINIMUM_ATOMIC_ALIGNMENT
;
697 /* Make a new type with the desired size and alignment, if needed. */
698 gnu_type
= maybe_pad_type (gnu_type
, gnu_size
, align
,
699 gnat_entity
, "PAD", 0, definition
, 1);
701 /* Make a volatile version of this object's type if we are to
702 make the object volatile. Note that 13.3(19) says that we
703 should treat other types of objects as volatile as well. */
704 if ((Treat_As_Volatile (gnat_entity
)
705 || Is_Exported (gnat_entity
)
706 || Is_Imported (gnat_entity
)
707 || Present (Address_Clause (gnat_entity
)))
708 && ! TYPE_VOLATILE (gnu_type
))
709 gnu_type
= build_qualified_type (gnu_type
,
710 (TYPE_QUALS (gnu_type
)
711 | TYPE_QUAL_VOLATILE
));
713 /* Convert the expression to the type of the object except in the
714 case where the object's type is unconstrained or the object's type
715 is a padded record whose field is of self-referential size. In
716 the former case, converting will generate unnecessary evaluations
717 of the CONSTRUCTOR to compute the size and in the latter case, we
718 want to only copy the actual data. */
720 && TREE_CODE (gnu_type
) != UNCONSTRAINED_ARRAY_TYPE
721 && ! CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
))
722 && ! (TREE_CODE (gnu_type
) == RECORD_TYPE
723 && TYPE_IS_PADDING_P (gnu_type
)
724 && (CONTAINS_PLACEHOLDER_P
725 (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type
)))))))
726 gnu_expr
= convert (gnu_type
, gnu_expr
);
728 /* See if this is a renaming. If this is a constant renaming,
729 treat it as a normal variable whose initial value is what
730 is being renamed. We cannot do this if the type is
731 unconstrained or class-wide.
733 Otherwise, if what we are renaming is a reference, we can simply
734 return a stabilized version of that reference, after forcing
735 any SAVE_EXPRs to be evaluated. But, if this is at global level,
736 we can only do this if we know no SAVE_EXPRs will be made.
737 Otherwise, make this into a constant pointer to the object we are
740 if (Present (Renamed_Object (gnat_entity
)))
742 /* If the renamed object had padding, strip off the reference
743 to the inner object and reset our type. */
744 if (TREE_CODE (gnu_expr
) == COMPONENT_REF
745 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (gnu_expr
, 0)))
747 && (TYPE_IS_PADDING_P
748 (TREE_TYPE (TREE_OPERAND (gnu_expr
, 0)))))
750 gnu_expr
= TREE_OPERAND (gnu_expr
, 0);
751 gnu_type
= TREE_TYPE (gnu_expr
);
755 && TREE_CODE (gnu_type
) != UNCONSTRAINED_ARRAY_TYPE
756 && TYPE_MODE (gnu_type
) != BLKmode
757 && Ekind (Etype (gnat_entity
)) != E_Class_Wide_Type
758 && !Is_Array_Type (Etype (gnat_entity
)))
761 /* If this is a declaration or reference, we can just use that
762 declaration or reference as this entity. */
763 else if ((DECL_P (gnu_expr
)
764 || TREE_CODE_CLASS (TREE_CODE (gnu_expr
)) == 'r')
765 && ! Materialize_Entity (gnat_entity
)
766 && (! global_bindings_p ()
767 || (staticp (gnu_expr
)
768 && ! TREE_SIDE_EFFECTS (gnu_expr
))))
770 set_lineno (gnat_entity
, ! global_bindings_p ());
771 gnu_decl
= gnat_stabilize_reference (gnu_expr
, 1);
772 save_gnu_tree (gnat_entity
, gnu_decl
, 1);
775 if (! global_bindings_p ())
776 expand_expr_stmt (build1 (CONVERT_EXPR
, void_type_node
,
782 inner_const_flag
= TREE_READONLY (gnu_expr
);
784 gnu_type
= build_reference_type (gnu_type
);
785 gnu_expr
= build_unary_op (ADDR_EXPR
, gnu_type
, gnu_expr
);
791 /* If this is an aliased object whose nominal subtype is unconstrained,
792 the object is a record that contains both the template and
793 the object. If there is an initializer, it will have already
794 been converted to the right type, but we need to create the
795 template if there is no initializer. */
796 else if (definition
&& TREE_CODE (gnu_type
) == RECORD_TYPE
797 && (TYPE_CONTAINS_TEMPLATE_P (gnu_type
)
798 /* Beware that padding might have been introduced
799 via maybe_pad_type above. */
800 || (TYPE_IS_PADDING_P (gnu_type
)
801 && TREE_CODE (TREE_TYPE (TYPE_FIELDS (gnu_type
)))
803 && TYPE_CONTAINS_TEMPLATE_P
804 (TREE_TYPE (TYPE_FIELDS (gnu_type
)))))
808 = TYPE_IS_PADDING_P (gnu_type
)
809 ? TYPE_FIELDS (TREE_TYPE (TYPE_FIELDS (gnu_type
)))
810 : TYPE_FIELDS (gnu_type
);
813 = gnat_build_constructor
817 build_template (TREE_TYPE (template_field
),
818 TREE_TYPE (TREE_CHAIN (template_field
)),
823 /* If this is a pointer and it does not have an initializing
824 expression, initialize it to NULL, unless the obect is
827 && (POINTER_TYPE_P (gnu_type
) || TYPE_FAT_POINTER_P (gnu_type
))
828 && !Is_Imported (gnat_entity
)
830 gnu_expr
= integer_zero_node
;
832 /* If we are defining the object and it has an Address clause we must
833 get the address expression from the saved GCC tree for the
834 object if the object has a Freeze_Node. Otherwise, we elaborate
835 the address expression here since the front-end has guaranteed
836 in that case that the elaboration has no effects. Note that
837 only the latter mechanism is currently in use. */
838 if (definition
&& Present (Address_Clause (gnat_entity
)))
841 = (present_gnu_tree (gnat_entity
) ? get_gnu_tree (gnat_entity
)
842 : gnat_to_gnu (Expression (Address_Clause (gnat_entity
))));
844 save_gnu_tree (gnat_entity
, NULL_TREE
, 0);
846 /* Ignore the size. It's either meaningless or was handled
849 gnu_type
= build_reference_type (gnu_type
);
850 gnu_address
= convert (gnu_type
, gnu_address
);
852 const_flag
= ! Is_Public (gnat_entity
);
854 /* If we don't have an initializing expression for the underlying
855 variable, the initializing expression for the pointer is the
856 specified address. Otherwise, we have to make a COMPOUND_EXPR
857 to assign both the address and the initial value. */
859 gnu_expr
= gnu_address
;
862 = build (COMPOUND_EXPR
, gnu_type
,
864 (MODIFY_EXPR
, NULL_TREE
,
865 build_unary_op (INDIRECT_REF
, NULL_TREE
,
871 /* If it has an address clause and we are not defining it, mark it
872 as an indirect object. Likewise for Stdcall objects that are
874 if ((! definition
&& Present (Address_Clause (gnat_entity
)))
875 || (Is_Imported (gnat_entity
)
876 && Convention (gnat_entity
) == Convention_Stdcall
))
878 gnu_type
= build_reference_type (gnu_type
);
883 /* If we are at top level and this object is of variable size,
884 make the actual type a hidden pointer to the real type and
885 make the initializer be a memory allocation and initialization.
886 Likewise for objects we aren't defining (presumed to be
887 external references from other packages), but there we do
888 not set up an initialization.
890 If the object's size overflows, make an allocator too, so that
891 Storage_Error gets raised. Note that we will never free
892 such memory, so we presume it never will get allocated. */
894 if (! allocatable_size_p (TYPE_SIZE_UNIT (gnu_type
),
895 global_bindings_p () || ! definition
898 && ! allocatable_size_p (gnu_size
,
899 global_bindings_p () || ! definition
902 gnu_type
= build_reference_type (gnu_type
);
907 /* Get the data part of GNU_EXPR in case this was a
908 aliased object whose nominal subtype is unconstrained.
909 In that case the pointer above will be a thin pointer and
910 build_allocator will automatically make the template and
911 constructor already made above. */
915 tree gnu_alloc_type
= TREE_TYPE (gnu_type
);
917 if (TREE_CODE (gnu_alloc_type
) == RECORD_TYPE
918 && TYPE_CONTAINS_TEMPLATE_P (gnu_alloc_type
))
921 = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_alloc_type
)));
923 = build_component_ref
924 (gnu_expr
, NULL_TREE
,
925 TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (gnu_expr
))), 0);
928 if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type
)) == INTEGER_CST
929 && TREE_CONSTANT_OVERFLOW (TYPE_SIZE_UNIT (gnu_alloc_type
))
930 && ! Is_Imported (gnat_entity
))
931 post_error ("Storage_Error will be raised at run-time?",
934 gnu_expr
= build_allocator (gnu_alloc_type
, gnu_expr
,
935 gnu_type
, 0, 0, gnat_entity
);
944 /* If this object would go into the stack and has an alignment
945 larger than the default largest alignment, make a variable
946 to hold the "aligning type" with a modified initial value,
947 if any, then point to it and make that the value of this
948 variable, which is now indirect. */
950 if (! global_bindings_p () && ! static_p
&& definition
951 && ! imported_p
&& TYPE_ALIGN (gnu_type
) > BIGGEST_ALIGNMENT
)
954 = make_aligning_type (gnu_type
, TYPE_ALIGN (gnu_type
),
955 TYPE_SIZE_UNIT (gnu_type
));
958 set_lineno (gnat_entity
, 1);
960 = create_var_decl (create_concat_name (gnat_entity
, "ALIGN"),
961 NULL_TREE
, gnu_new_type
, gnu_expr
,
967 (MODIFY_EXPR
, NULL_TREE
,
968 build_component_ref (gnu_new_var
, NULL_TREE
,
969 TYPE_FIELDS (gnu_new_type
), 0),
972 gnu_type
= build_reference_type (gnu_type
);
975 (ADDR_EXPR
, gnu_type
,
976 build_component_ref (gnu_new_var
, NULL_TREE
,
977 TYPE_FIELDS (gnu_new_type
), 0));
984 /* Convert the expression to the type of the object except in the
985 case where the object's type is unconstrained or the object's type
986 is a padded record whose field is of self-referential size. In
987 the former case, converting will generate unnecessary evaluations
988 of the CONSTRUCTOR to compute the size and in the latter case, we
989 want to only copy the actual data. */
991 && TREE_CODE (gnu_type
) != UNCONSTRAINED_ARRAY_TYPE
992 && ! CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
))
993 && ! (TREE_CODE (gnu_type
) == RECORD_TYPE
994 && TYPE_IS_PADDING_P (gnu_type
)
995 && (CONTAINS_PLACEHOLDER_P
996 (TYPE_SIZE (TREE_TYPE (TYPE_FIELDS (gnu_type
)))))))
997 gnu_expr
= convert (gnu_type
, gnu_expr
);
999 /* If this name is external or there was a name specified, use it,
1000 unless this is a VMS exception object since this would conflict
1001 with the symbol we need to export in addition. Don't use the
1002 Interface_Name if there is an address clause (see CD30005). */
1003 if (! Is_VMS_Exception (gnat_entity
)
1005 ((Present (Interface_Name (gnat_entity
))
1006 && No (Address_Clause (gnat_entity
)))
1008 (Is_Public (gnat_entity
)
1009 && (! Is_Imported (gnat_entity
) || Is_Exported (gnat_entity
)))))
1010 gnu_ext_name
= create_concat_name (gnat_entity
, 0);
1013 gnu_type
= build_qualified_type (gnu_type
, (TYPE_QUALS (gnu_type
)
1014 | TYPE_QUAL_CONST
));
1016 /* If this is constant initialized to a static constant and the
1017 object has an aggregrate type, force it to be statically
1019 if (const_flag
&& gnu_expr
&& TREE_CONSTANT (gnu_expr
)
1020 && host_integerp (TYPE_SIZE_UNIT (gnu_type
), 1)
1021 && (AGGREGATE_TYPE_P (gnu_type
)
1022 && ! (TREE_CODE (gnu_type
) == RECORD_TYPE
1023 && TYPE_IS_PADDING_P (gnu_type
))))
1026 set_lineno (gnat_entity
, ! global_bindings_p ());
1027 gnu_decl
= create_var_decl (gnu_entity_id
, gnu_ext_name
, gnu_type
,
1028 gnu_expr
, const_flag
,
1029 Is_Public (gnat_entity
),
1030 imported_p
|| !definition
,
1031 static_p
, attr_list
);
1033 DECL_BY_REF_P (gnu_decl
) = used_by_ref
;
1034 DECL_POINTS_TO_READONLY_P (gnu_decl
) = used_by_ref
&& inner_const_flag
;
1036 /* If we have an address clause and we've made this indirect, it's
1037 not enough to merely mark the type as volatile since volatile
1038 references only conflict with other volatile references while this
1039 reference must conflict with all other references. So ensure that
1040 the dereferenced value has alias set 0. */
1041 if (Present (Address_Clause (gnat_entity
)) && used_by_ref
)
1042 DECL_POINTER_ALIAS_SET (gnu_decl
) = 0;
1044 if (definition
&& DECL_SIZE (gnu_decl
) != 0
1045 && gnu_block_stack
!= 0
1046 && TREE_VALUE (gnu_block_stack
) != 0
1047 && (TREE_CODE (DECL_SIZE (gnu_decl
)) != INTEGER_CST
1048 || (flag_stack_check
&& ! STACK_CHECK_BUILTIN
1049 && 0 < compare_tree_int (DECL_SIZE_UNIT (gnu_decl
),
1050 STACK_CHECK_MAX_VAR_SIZE
))))
1051 update_setjmp_buf (TREE_VALUE (gnu_block_stack
));
1053 /* If this is a public constant or we're not optimizing and we're not
1054 making a VAR_DECL for it, make one just for export or debugger
1055 use. Likewise if the address is taken or if the object or type is
1057 if (definition
&& TREE_CODE (gnu_decl
) == CONST_DECL
1058 && (Is_Public (gnat_entity
)
1060 || Address_Taken (gnat_entity
)
1061 || Is_Aliased (gnat_entity
)
1062 || Is_Aliased (Etype (gnat_entity
))))
1063 SET_DECL_CONST_CORRESPONDING_VAR
1065 create_var_decl (gnu_entity_id
, gnu_ext_name
, gnu_type
,
1066 gnu_expr
, 0, Is_Public (gnat_entity
), 0,
1069 /* If this is declared in a block that contains an block with an
1070 exception handler, we must force this variable in memory to
1071 suppress an invalid optimization. */
1072 if (Has_Nested_Block_With_Handler (Scope (gnat_entity
))
1073 && Exception_Mechanism
!= GCC_ZCX
)
1075 gnat_mark_addressable (gnu_decl
);
1076 flush_addressof (gnu_decl
);
1079 /* Back-annotate the Alignment of the object if not already in the
1080 tree. Likewise for Esize if the object is of a constant size.
1081 But if the "object" is actually a pointer to an object, the
1082 alignment and size are the same as teh type, so don't back-annotate
1083 the values for the pointer. */
1084 if (! used_by_ref
&& Unknown_Alignment (gnat_entity
))
1085 Set_Alignment (gnat_entity
,
1086 UI_From_Int (DECL_ALIGN (gnu_decl
) / BITS_PER_UNIT
));
1088 if (! used_by_ref
&& Unknown_Esize (gnat_entity
)
1089 && DECL_SIZE (gnu_decl
) != 0)
1091 tree gnu_back_size
= DECL_SIZE (gnu_decl
);
1093 if (TREE_CODE (TREE_TYPE (gnu_decl
)) == RECORD_TYPE
1094 && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (gnu_decl
)))
1096 = TYPE_SIZE (TREE_TYPE (TREE_CHAIN
1097 (TYPE_FIELDS (TREE_TYPE (gnu_decl
)))));
1099 Set_Esize (gnat_entity
, annotate_value (gnu_back_size
));
1105 /* Return a TYPE_DECL for "void" that we previously made. */
1106 gnu_decl
= void_type_decl_node
;
1109 case E_Enumeration_Type
:
1110 /* A special case, for the types Character and Wide_Character in
1111 Standard, we do not list all the literals. So if the literals
1112 are not specified, make this an unsigned type. */
1113 if (No (First_Literal (gnat_entity
)))
1115 gnu_type
= make_unsigned_type (esize
);
1119 /* Normal case of non-character type, or non-Standard character type */
1121 /* Here we have a list of enumeral constants in First_Literal.
1122 We make a CONST_DECL for each and build into GNU_LITERAL_LIST
1123 the list to be places into TYPE_FIELDS. Each node in the list
1124 is a TREE_LIST node whose TREE_VALUE is the literal name
1125 and whose TREE_PURPOSE is the value of the literal.
1127 Esize contains the number of bits needed to represent the enumeral
1128 type, Type_Low_Bound also points to the first literal and
1129 Type_High_Bound points to the last literal. */
1131 Entity_Id gnat_literal
;
1132 tree gnu_literal_list
= NULL_TREE
;
1134 if (Is_Unsigned_Type (gnat_entity
))
1135 gnu_type
= make_unsigned_type (esize
);
1137 gnu_type
= make_signed_type (esize
);
1139 TREE_SET_CODE (gnu_type
, ENUMERAL_TYPE
);
1141 for (gnat_literal
= First_Literal (gnat_entity
);
1142 Present (gnat_literal
);
1143 gnat_literal
= Next_Literal (gnat_literal
))
1145 tree gnu_value
= UI_To_gnu (Enumeration_Rep (gnat_literal
),
1148 = create_var_decl (get_entity_name (gnat_literal
),
1149 0, gnu_type
, gnu_value
, 1, 0, 0, 0, 0);
1151 save_gnu_tree (gnat_literal
, gnu_literal
, 0);
1152 gnu_literal_list
= tree_cons (DECL_NAME (gnu_literal
),
1153 gnu_value
, gnu_literal_list
);
1156 TYPE_VALUES (gnu_type
) = nreverse (gnu_literal_list
);
1158 /* Note that the bounds are updated at the end of this function
1159 because to avoid an infinite recursion when we get the bounds of
1160 this type, since those bounds are objects of this type. */
1164 case E_Signed_Integer_Type
:
1165 case E_Ordinary_Fixed_Point_Type
:
1166 case E_Decimal_Fixed_Point_Type
:
1167 /* For integer types, just make a signed type the appropriate number
1169 gnu_type
= make_signed_type (esize
);
1172 case E_Modular_Integer_Type
:
1173 /* For modular types, make the unsigned type of the proper number of
1174 bits and then set up the modulus, if required. */
1176 enum machine_mode mode
;
1180 if (Is_Packed_Array_Type (gnat_entity
))
1181 esize
= UI_To_Int (RM_Size (gnat_entity
));
1183 /* Find the smallest mode at least ESIZE bits wide and make a class
1186 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
1187 GET_MODE_BITSIZE (mode
) < esize
;
1188 mode
= GET_MODE_WIDER_MODE (mode
))
1191 gnu_type
= make_unsigned_type (GET_MODE_BITSIZE (mode
));
1192 TYPE_PACKED_ARRAY_TYPE_P (gnu_type
)
1193 = Is_Packed_Array_Type (gnat_entity
);
1195 /* Get the modulus in this type. If it overflows, assume it is because
1196 it is equal to 2**Esize. Note that there is no overflow checking
1197 done on unsigned type, so we detect the overflow by looking for
1198 a modulus of zero, which is otherwise invalid. */
1199 gnu_modulus
= UI_To_gnu (Modulus (gnat_entity
), gnu_type
);
1201 if (! integer_zerop (gnu_modulus
))
1203 TYPE_MODULAR_P (gnu_type
) = 1;
1204 SET_TYPE_MODULUS (gnu_type
, gnu_modulus
);
1205 gnu_high
= fold (build (MINUS_EXPR
, gnu_type
, gnu_modulus
,
1206 convert (gnu_type
, integer_one_node
)));
1209 /* If we have to set TYPE_PRECISION different from its natural value,
1210 make a subtype to do do. Likewise if there is a modulus and
1211 it is not one greater than TYPE_MAX_VALUE. */
1212 if (TYPE_PRECISION (gnu_type
) != esize
1213 || (TYPE_MODULAR_P (gnu_type
)
1214 && ! tree_int_cst_equal (TYPE_MAX_VALUE (gnu_type
), gnu_high
)))
1216 tree gnu_subtype
= make_node (INTEGER_TYPE
);
1218 TYPE_NAME (gnu_type
) = create_concat_name (gnat_entity
, "UMT");
1219 TREE_TYPE (gnu_subtype
) = gnu_type
;
1220 TYPE_MIN_VALUE (gnu_subtype
) = TYPE_MIN_VALUE (gnu_type
);
1221 TYPE_MAX_VALUE (gnu_subtype
)
1222 = TYPE_MODULAR_P (gnu_type
)
1223 ? gnu_high
: TYPE_MAX_VALUE (gnu_type
);
1224 TYPE_PRECISION (gnu_subtype
) = esize
;
1225 TYPE_UNSIGNED (gnu_subtype
) = 1;
1226 TYPE_EXTRA_SUBTYPE_P (gnu_subtype
) = 1;
1227 TYPE_PACKED_ARRAY_TYPE_P (gnu_subtype
)
1228 = Is_Packed_Array_Type (gnat_entity
);
1229 layout_type (gnu_subtype
);
1231 gnu_type
= gnu_subtype
;
1236 case E_Signed_Integer_Subtype
:
1237 case E_Enumeration_Subtype
:
1238 case E_Modular_Integer_Subtype
:
1239 case E_Ordinary_Fixed_Point_Subtype
:
1240 case E_Decimal_Fixed_Point_Subtype
:
1242 /* For integral subtypes, we make a new INTEGER_TYPE. Note
1243 that we do not want to call build_range_type since we would
1244 like each subtype node to be distinct. This will be important
1245 when memory aliasing is implemented.
1247 The TREE_TYPE field of the INTEGER_TYPE we make points to the
1248 parent type; this fact is used by the arithmetic conversion
1251 We elaborate the Ancestor_Subtype if it is not in the current
1252 unit and one of our bounds is non-static. We do this to ensure
1253 consistent naming in the case where several subtypes share the same
1254 bounds by always elaborating the first such subtype first, thus
1258 && Present (Ancestor_Subtype (gnat_entity
))
1259 && ! In_Extended_Main_Code_Unit (Ancestor_Subtype (gnat_entity
))
1260 && (! Compile_Time_Known_Value (Type_Low_Bound (gnat_entity
))
1261 || ! Compile_Time_Known_Value (Type_High_Bound (gnat_entity
))))
1262 gnat_to_gnu_entity (Ancestor_Subtype (gnat_entity
),
1263 gnu_expr
, definition
);
1265 gnu_type
= make_node (INTEGER_TYPE
);
1266 if (Is_Packed_Array_Type (gnat_entity
))
1268 esize
= UI_To_Int (RM_Size (gnat_entity
));
1269 TYPE_PACKED_ARRAY_TYPE_P (gnu_type
) = 1;
1272 TYPE_PRECISION (gnu_type
) = esize
;
1273 TREE_TYPE (gnu_type
) = get_unpadded_type (Etype (gnat_entity
));
1275 TYPE_MIN_VALUE (gnu_type
)
1276 = convert (TREE_TYPE (gnu_type
),
1277 elaborate_expression (Type_Low_Bound (gnat_entity
),
1279 get_identifier ("L"), definition
, 1,
1280 Needs_Debug_Info (gnat_entity
)));
1282 TYPE_MAX_VALUE (gnu_type
)
1283 = convert (TREE_TYPE (gnu_type
),
1284 elaborate_expression (Type_High_Bound (gnat_entity
),
1286 get_identifier ("U"), definition
, 1,
1287 Needs_Debug_Info (gnat_entity
)));
1289 /* One of the above calls might have caused us to be elaborated,
1290 so don't blow up if so. */
1291 if (present_gnu_tree (gnat_entity
))
1297 TYPE_BIASED_REPRESENTATION_P (gnu_type
)
1298 = Has_Biased_Representation (gnat_entity
);
1300 /* This should be an unsigned type if the lower bound is constant
1301 and non-negative or if the base type is unsigned; a signed type
1303 TYPE_UNSIGNED (gnu_type
)
1304 = (TYPE_UNSIGNED (TREE_TYPE (gnu_type
))
1305 || (TREE_CODE (TYPE_MIN_VALUE (gnu_type
)) == INTEGER_CST
1306 && TREE_INT_CST_HIGH (TYPE_MIN_VALUE (gnu_type
)) >= 0)
1307 || TYPE_BIASED_REPRESENTATION_P (gnu_type
)
1308 || Is_Unsigned_Type (gnat_entity
));
1310 layout_type (gnu_type
);
1312 /* If the type we are dealing with is to represent a packed array,
1313 we need to have the bits left justified on big-endian targets
1314 (see exp_packd.ads). We build a record with a bitfield of the
1315 appropriate size to achieve this. */
1316 if (Is_Packed_Array_Type (gnat_entity
) && BYTES_BIG_ENDIAN
)
1318 tree gnu_field_type
= gnu_type
;
1321 TYPE_RM_SIZE_INT (gnu_field_type
)
1322 = UI_To_gnu (RM_Size (gnat_entity
), bitsizetype
);
1323 gnu_type
= make_node (RECORD_TYPE
);
1324 TYPE_NAME (gnu_type
) = create_concat_name (gnat_entity
, "LJM");
1325 TYPE_ALIGN (gnu_type
) = TYPE_ALIGN (gnu_field_type
);
1326 TYPE_PACKED (gnu_type
) = 1;
1328 /* Don't notify the field as "addressable", since we won't be taking
1329 it's address and it would prevent create_field_decl from making a
1331 gnu_field
= create_field_decl (get_identifier ("OBJECT"),
1332 gnu_field_type
, gnu_type
, 1, 0, 0, 0);
1334 finish_record_type (gnu_type
, gnu_field
, 0, 0);
1335 TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_type
) = 1;
1336 SET_TYPE_ADA_SIZE (gnu_type
, bitsize_int (esize
));
1341 case E_Floating_Point_Type
:
1342 /* If this is a VAX floating-point type, use an integer of the proper
1343 size. All the operations will be handled with ASM statements. */
1344 if (Vax_Float (gnat_entity
))
1346 gnu_type
= make_signed_type (esize
);
1347 TYPE_VAX_FLOATING_POINT_P (gnu_type
) = 1;
1348 SET_TYPE_DIGITS_VALUE (gnu_type
,
1349 UI_To_gnu (Digits_Value (gnat_entity
),
1354 /* The type of the Low and High bounds can be our type if this is
1355 a type from Standard, so set them at the end of the function. */
1356 gnu_type
= make_node (REAL_TYPE
);
1357 TYPE_PRECISION (gnu_type
) = fp_size_to_prec (esize
);
1358 layout_type (gnu_type
);
1361 case E_Floating_Point_Subtype
:
1362 if (Vax_Float (gnat_entity
))
1364 gnu_type
= gnat_to_gnu_type (Etype (gnat_entity
));
1370 && Present (Ancestor_Subtype (gnat_entity
))
1371 && ! In_Extended_Main_Code_Unit (Ancestor_Subtype (gnat_entity
))
1372 && (! Compile_Time_Known_Value (Type_Low_Bound (gnat_entity
))
1373 || ! Compile_Time_Known_Value (Type_High_Bound (gnat_entity
))))
1374 gnat_to_gnu_entity (Ancestor_Subtype (gnat_entity
),
1375 gnu_expr
, definition
);
1377 gnu_type
= make_node (REAL_TYPE
);
1378 TREE_TYPE (gnu_type
) = get_unpadded_type (Etype (gnat_entity
));
1379 TYPE_PRECISION (gnu_type
) = fp_size_to_prec (esize
);
1381 TYPE_MIN_VALUE (gnu_type
)
1382 = convert (TREE_TYPE (gnu_type
),
1383 elaborate_expression (Type_Low_Bound (gnat_entity
),
1384 gnat_entity
, get_identifier ("L"),
1386 Needs_Debug_Info (gnat_entity
)));
1388 TYPE_MAX_VALUE (gnu_type
)
1389 = convert (TREE_TYPE (gnu_type
),
1390 elaborate_expression (Type_High_Bound (gnat_entity
),
1391 gnat_entity
, get_identifier ("U"),
1393 Needs_Debug_Info (gnat_entity
)));
1395 /* One of the above calls might have caused us to be elaborated,
1396 so don't blow up if so. */
1397 if (present_gnu_tree (gnat_entity
))
1403 layout_type (gnu_type
);
1407 /* Array and String Types and Subtypes
1409 Unconstrained array types are represented by E_Array_Type and
1410 constrained array types are represented by E_Array_Subtype. There
1411 are no actual objects of an unconstrained array type; all we have
1412 are pointers to that type.
1414 The following fields are defined on array types and subtypes:
1416 Component_Type Component type of the array.
1417 Number_Dimensions Number of dimensions (an int).
1418 First_Index Type of first index. */
1423 tree gnu_template_fields
= NULL_TREE
;
1424 tree gnu_template_type
= make_node (RECORD_TYPE
);
1425 tree gnu_ptr_template
= build_pointer_type (gnu_template_type
);
1426 tree gnu_fat_type
= make_node (RECORD_TYPE
);
1427 int ndim
= Number_Dimensions (gnat_entity
);
1429 = (Convention (gnat_entity
) == Convention_Fortran
) ? ndim
- 1 : 0;
1431 = (Convention (gnat_entity
) == Convention_Fortran
) ? - 1 : 1;
1432 tree
*gnu_index_types
= (tree
*) alloca (ndim
* sizeof (tree
*));
1433 tree
*gnu_temp_fields
= (tree
*) alloca (ndim
* sizeof (tree
*));
1434 tree gnu_comp_size
= 0;
1435 tree gnu_max_size
= size_one_node
;
1436 tree gnu_max_size_unit
;
1438 Entity_Id gnat_ind_subtype
;
1439 Entity_Id gnat_ind_base_subtype
;
1440 tree gnu_template_reference
;
1443 TYPE_NAME (gnu_template_type
)
1444 = create_concat_name (gnat_entity
, "XUB");
1445 TYPE_NAME (gnu_fat_type
) = create_concat_name (gnat_entity
, "XUP");
1446 TYPE_IS_FAT_POINTER_P (gnu_fat_type
) = 1;
1447 TYPE_READONLY (gnu_template_type
) = 1;
1449 /* Make a node for the array. If we are not defining the array
1450 suppress expanding incomplete types and save the node as the type
1452 gnu_type
= make_node (UNCONSTRAINED_ARRAY_TYPE
);
1455 defer_incomplete_level
++;
1456 this_deferred
= this_made_decl
= 1;
1457 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
1458 ! Comes_From_Source (gnat_entity
),
1460 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
1464 /* Build the fat pointer type. Use a "void *" object instead of
1465 a pointer to the array type since we don't have the array type
1466 yet (it will reference the fat pointer via the bounds). */
1467 tem
= chainon (chainon (NULL_TREE
,
1468 create_field_decl (get_identifier ("P_ARRAY"),
1470 gnu_fat_type
, 0, 0, 0, 0)),
1471 create_field_decl (get_identifier ("P_BOUNDS"),
1473 gnu_fat_type
, 0, 0, 0, 0));
1475 /* Make sure we can put this into a register. */
1476 TYPE_ALIGN (gnu_fat_type
) = MIN (BIGGEST_ALIGNMENT
, 2 * POINTER_SIZE
);
1477 finish_record_type (gnu_fat_type
, tem
, 0, 1);
1479 /* Build a reference to the template from a PLACEHOLDER_EXPR that
1480 is the fat pointer. This will be used to access the individual
1481 fields once we build them. */
1482 tem
= build (COMPONENT_REF
, gnu_ptr_template
,
1483 build (PLACEHOLDER_EXPR
, gnu_fat_type
),
1484 TREE_CHAIN (TYPE_FIELDS (gnu_fat_type
)));
1485 gnu_template_reference
1486 = build_unary_op (INDIRECT_REF
, gnu_template_type
, tem
);
1487 TREE_READONLY (gnu_template_reference
) = 1;
1489 /* Now create the GCC type for each index and add the fields for
1490 that index to the template. */
1491 for (index
= firstdim
, gnat_ind_subtype
= First_Index (gnat_entity
),
1492 gnat_ind_base_subtype
1493 = First_Index (Implementation_Base_Type (gnat_entity
));
1494 index
< ndim
&& index
>= 0;
1496 gnat_ind_subtype
= Next_Index (gnat_ind_subtype
),
1497 gnat_ind_base_subtype
= Next_Index (gnat_ind_base_subtype
))
1499 char field_name
[10];
1500 tree gnu_ind_subtype
1501 = get_unpadded_type (Base_Type (Etype (gnat_ind_subtype
)));
1502 tree gnu_base_subtype
1503 = get_unpadded_type (Etype (gnat_ind_base_subtype
));
1505 = convert (sizetype
, TYPE_MIN_VALUE (gnu_base_subtype
));
1507 = convert (sizetype
, TYPE_MAX_VALUE (gnu_base_subtype
));
1508 tree gnu_min_field
, gnu_max_field
, gnu_min
, gnu_max
;
1510 /* Make the FIELD_DECLs for the minimum and maximum of this
1511 type and then make extractions of that field from the
1513 set_lineno (gnat_entity
, 0);
1514 sprintf (field_name
, "LB%d", index
);
1515 gnu_min_field
= create_field_decl (get_identifier (field_name
),
1517 gnu_template_type
, 0, 0, 0, 0);
1518 field_name
[0] = 'U';
1519 gnu_max_field
= create_field_decl (get_identifier (field_name
),
1521 gnu_template_type
, 0, 0, 0, 0);
1523 gnu_temp_fields
[index
] = chainon (gnu_min_field
, gnu_max_field
);
1525 /* We can't use build_component_ref here since the template
1526 type isn't complete yet. */
1527 gnu_min
= build (COMPONENT_REF
, gnu_ind_subtype
,
1528 gnu_template_reference
, gnu_min_field
);
1529 gnu_max
= build (COMPONENT_REF
, gnu_ind_subtype
,
1530 gnu_template_reference
, gnu_max_field
);
1531 TREE_READONLY (gnu_min
) = TREE_READONLY (gnu_max
) = 1;
1533 /* Make a range type with the new ranges, but using
1534 the Ada subtype. Then we convert to sizetype. */
1535 gnu_index_types
[index
]
1536 = create_index_type (convert (sizetype
, gnu_min
),
1537 convert (sizetype
, gnu_max
),
1538 build_range_type (gnu_ind_subtype
,
1540 /* Update the maximum size of the array, in elements. */
1542 = size_binop (MULT_EXPR
, gnu_max_size
,
1543 size_binop (PLUS_EXPR
, size_one_node
,
1544 size_binop (MINUS_EXPR
, gnu_base_max
,
1547 TYPE_NAME (gnu_index_types
[index
])
1548 = create_concat_name (gnat_entity
, field_name
);
1551 for (index
= 0; index
< ndim
; index
++)
1553 = chainon (gnu_template_fields
, gnu_temp_fields
[index
]);
1555 /* Install all the fields into the template. */
1556 finish_record_type (gnu_template_type
, gnu_template_fields
, 0, 0);
1557 TYPE_READONLY (gnu_template_type
) = 1;
1559 /* Now make the array of arrays and update the pointer to the array
1560 in the fat pointer. Note that it is the first field. */
1562 tem
= gnat_to_gnu_type (Component_Type (gnat_entity
));
1564 /* Get and validate any specified Component_Size, but if Packed,
1565 ignore it since the front end will have taken care of it. */
1567 = validate_size (Component_Size (gnat_entity
), tem
,
1569 (Is_Bit_Packed_Array (gnat_entity
)
1570 ? TYPE_DECL
: VAR_DECL
), 1,
1571 Has_Component_Size_Clause (gnat_entity
));
1573 if (Has_Atomic_Components (gnat_entity
))
1574 check_ok_for_atomic (tem
, gnat_entity
, 1);
1576 /* If the component type is a RECORD_TYPE that has a self-referential
1577 size, use the maxium size. */
1578 if (gnu_comp_size
== 0 && TREE_CODE (tem
) == RECORD_TYPE
1579 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (tem
)))
1580 gnu_comp_size
= max_size (TYPE_SIZE (tem
), 1);
1582 if (! Is_Bit_Packed_Array (gnat_entity
) && gnu_comp_size
!= 0)
1584 tem
= make_type_from_size (tem
, gnu_comp_size
, 0);
1585 tem
= maybe_pad_type (tem
, gnu_comp_size
, 0, gnat_entity
,
1586 "C_PAD", 0, definition
, 1);
1589 if (Has_Volatile_Components (gnat_entity
))
1590 tem
= build_qualified_type (tem
,
1591 TYPE_QUALS (tem
) | TYPE_QUAL_VOLATILE
);
1593 /* If Component_Size is not already specified, annotate it with the
1594 size of the component. */
1595 if (Unknown_Component_Size (gnat_entity
))
1596 Set_Component_Size (gnat_entity
, annotate_value (TYPE_SIZE (tem
)));
1598 gnu_max_size_unit
= size_binop (MAX_EXPR
, size_zero_node
,
1599 size_binop (MULT_EXPR
, gnu_max_size
,
1600 TYPE_SIZE_UNIT (tem
)));
1601 gnu_max_size
= size_binop (MAX_EXPR
, bitsize_zero_node
,
1602 size_binop (MULT_EXPR
,
1603 convert (bitsizetype
,
1607 for (index
= ndim
- 1; index
>= 0; index
--)
1609 tem
= build_array_type (tem
, gnu_index_types
[index
]);
1610 TYPE_MULTI_ARRAY_P (tem
) = (index
> 0);
1612 /* If the type below this an multi-array type, then this
1613 does not not have aliased components.
1615 ??? Otherwise, for now, we say that any component of aggregate
1616 type is addressable because the front end may take 'Reference
1617 of it. But we have to make it addressable if it must be passed
1618 by reference or it that is the default. */
1619 TYPE_NONALIASED_COMPONENT (tem
)
1620 = ((TREE_CODE (TREE_TYPE (tem
)) == ARRAY_TYPE
1621 && TYPE_MULTI_ARRAY_P (TREE_TYPE (tem
))) ? 1
1622 : (! Has_Aliased_Components (gnat_entity
)
1623 && ! AGGREGATE_TYPE_P (TREE_TYPE (tem
))));
1626 /* If an alignment is specified, use it if valid. But ignore it for
1627 types that represent the unpacked base type for packed arrays. */
1628 if (No (Packed_Array_Type (gnat_entity
))
1629 && Known_Alignment (gnat_entity
))
1631 if (No (Alignment (gnat_entity
)))
1635 = validate_alignment (Alignment (gnat_entity
), gnat_entity
,
1639 TYPE_CONVENTION_FORTRAN_P (tem
)
1640 = (Convention (gnat_entity
) == Convention_Fortran
);
1641 TREE_TYPE (TYPE_FIELDS (gnu_fat_type
)) = build_pointer_type (tem
);
1643 /* The result type is an UNCONSTRAINED_ARRAY_TYPE that indicates the
1644 corresponding fat pointer. */
1645 TREE_TYPE (gnu_type
) = TYPE_POINTER_TO (gnu_type
)
1646 = TYPE_REFERENCE_TO (gnu_type
) = gnu_fat_type
;
1647 TYPE_MODE (gnu_type
) = BLKmode
;
1648 TYPE_ALIGN (gnu_type
) = TYPE_ALIGN (tem
);
1649 SET_TYPE_UNCONSTRAINED_ARRAY (gnu_fat_type
, gnu_type
);
1651 /* If the maximum size doesn't overflow, use it. */
1652 if (TREE_CODE (gnu_max_size
) == INTEGER_CST
1653 && ! TREE_OVERFLOW (gnu_max_size
))
1655 = size_binop (MIN_EXPR
, gnu_max_size
, TYPE_SIZE (tem
));
1656 if (TREE_CODE (gnu_max_size_unit
) == INTEGER_CST
1657 && ! TREE_OVERFLOW (gnu_max_size_unit
))
1658 TYPE_SIZE_UNIT (tem
)
1659 = size_binop (MIN_EXPR
, gnu_max_size_unit
,
1660 TYPE_SIZE_UNIT (tem
));
1662 create_type_decl (create_concat_name (gnat_entity
, "XUA"),
1663 tem
, 0, ! Comes_From_Source (gnat_entity
),
1665 rest_of_type_compilation (gnu_fat_type
, global_bindings_p ());
1667 /* Create a record type for the object and its template and
1668 set the template at a negative offset. */
1669 tem
= build_unc_object_type (gnu_template_type
, tem
,
1670 create_concat_name (gnat_entity
, "XUT"));
1671 DECL_FIELD_OFFSET (TYPE_FIELDS (tem
))
1672 = size_binop (MINUS_EXPR
, size_zero_node
,
1673 byte_position (TREE_CHAIN (TYPE_FIELDS (tem
))));
1674 DECL_FIELD_OFFSET (TREE_CHAIN (TYPE_FIELDS (tem
))) = size_zero_node
;
1675 DECL_FIELD_BIT_OFFSET (TREE_CHAIN (TYPE_FIELDS (tem
)))
1676 = bitsize_zero_node
;
1677 SET_TYPE_UNCONSTRAINED_ARRAY (tem
, gnu_type
);
1678 TYPE_OBJECT_RECORD_TYPE (gnu_type
) = tem
;
1680 /* Give the thin pointer type a name. */
1681 create_type_decl (create_concat_name (gnat_entity
, "XUX"),
1682 build_pointer_type (tem
), 0,
1683 ! Comes_From_Source (gnat_entity
), debug_info_p
);
1687 case E_String_Subtype
:
1688 case E_Array_Subtype
:
1690 /* This is the actual data type for array variables. Multidimensional
1691 arrays are implemented in the gnu tree as arrays of arrays. Note
1692 that for the moment arrays which have sparse enumeration subtypes as
1693 index components create sparse arrays, which is obviously space
1694 inefficient but so much easier to code for now.
1696 Also note that the subtype never refers to the unconstrained
1697 array type, which is somewhat at variance with Ada semantics.
1699 First check to see if this is simply a renaming of the array
1700 type. If so, the result is the array type. */
1702 gnu_type
= gnat_to_gnu_type (Etype (gnat_entity
));
1703 if (! Is_Constrained (gnat_entity
))
1708 int array_dim
= Number_Dimensions (gnat_entity
);
1710 = ((Convention (gnat_entity
) == Convention_Fortran
)
1711 ? array_dim
- 1 : 0);
1713 = (Convention (gnat_entity
) == Convention_Fortran
) ? -1 : 1;
1714 Entity_Id gnat_ind_subtype
;
1715 Entity_Id gnat_ind_base_subtype
;
1716 tree gnu_base_type
= gnu_type
;
1717 tree
*gnu_index_type
= (tree
*) alloca (array_dim
* sizeof (tree
*));
1718 tree gnu_comp_size
= 0;
1719 tree gnu_max_size
= size_one_node
;
1720 tree gnu_max_size_unit
;
1721 int need_index_type_struct
= 0;
1722 int max_overflow
= 0;
1724 /* First create the gnu types for each index. Create types for
1725 debugging information to point to the index types if the
1726 are not integer types, have variable bounds, or are
1727 wider than sizetype. */
1729 for (index
= first_dim
, gnat_ind_subtype
= First_Index (gnat_entity
),
1730 gnat_ind_base_subtype
1731 = First_Index (Implementation_Base_Type (gnat_entity
));
1732 index
< array_dim
&& index
>= 0;
1734 gnat_ind_subtype
= Next_Index (gnat_ind_subtype
),
1735 gnat_ind_base_subtype
= Next_Index (gnat_ind_base_subtype
))
1737 tree gnu_index_subtype
1738 = get_unpadded_type (Etype (gnat_ind_subtype
));
1740 = convert (sizetype
, TYPE_MIN_VALUE (gnu_index_subtype
));
1742 = convert (sizetype
, TYPE_MAX_VALUE (gnu_index_subtype
));
1743 tree gnu_base_subtype
1744 = get_unpadded_type (Etype (gnat_ind_base_subtype
));
1746 = convert (sizetype
, TYPE_MIN_VALUE (gnu_base_subtype
));
1748 = convert (sizetype
, TYPE_MAX_VALUE (gnu_base_subtype
));
1749 tree gnu_base_type
= get_base_type (gnu_base_subtype
);
1750 tree gnu_base_base_min
1751 = convert (sizetype
, TYPE_MIN_VALUE (gnu_base_type
));
1752 tree gnu_base_base_max
1753 = convert (sizetype
, TYPE_MAX_VALUE (gnu_base_type
));
1757 /* If the minimum and maximum values both overflow in
1758 SIZETYPE, but the difference in the original type
1759 does not overflow in SIZETYPE, ignore the overflow
1761 if ((TYPE_PRECISION (gnu_index_subtype
)
1762 > TYPE_PRECISION (sizetype
))
1763 && TREE_CODE (gnu_min
) == INTEGER_CST
1764 && TREE_CODE (gnu_max
) == INTEGER_CST
1765 && TREE_OVERFLOW (gnu_min
) && TREE_OVERFLOW (gnu_max
)
1767 (fold (build (MINUS_EXPR
, gnu_index_subtype
,
1768 TYPE_MAX_VALUE (gnu_index_subtype
),
1769 TYPE_MIN_VALUE (gnu_index_subtype
))))))
1770 TREE_OVERFLOW (gnu_min
) = TREE_OVERFLOW (gnu_max
)
1771 = TREE_CONSTANT_OVERFLOW (gnu_min
)
1772 = TREE_CONSTANT_OVERFLOW (gnu_max
) = 0;
1774 /* Similarly, if the range is null, use bounds of 1..0 for
1775 the sizetype bounds. */
1776 else if ((TYPE_PRECISION (gnu_index_subtype
)
1777 > TYPE_PRECISION (sizetype
))
1778 && TREE_CODE (gnu_min
) == INTEGER_CST
1779 && TREE_CODE (gnu_max
) == INTEGER_CST
1780 && (TREE_OVERFLOW (gnu_min
) || TREE_OVERFLOW (gnu_max
))
1781 && tree_int_cst_lt (TYPE_MAX_VALUE (gnu_index_subtype
),
1782 TYPE_MIN_VALUE (gnu_index_subtype
)))
1783 gnu_min
= size_one_node
, gnu_max
= size_zero_node
;
1785 /* Now compute the size of this bound. We need to provide
1786 GCC with an upper bound to use but have to deal with the
1787 "superflat" case. There are three ways to do this. If we
1788 can prove that the array can never be superflat, we can
1789 just use the high bound of the index subtype. If we can
1790 prove that the low bound minus one can't overflow, we
1791 can do this as MAX (hb, lb - 1). Otherwise, we have to use
1792 the expression hb >= lb ? hb : lb - 1. */
1793 gnu_high
= size_binop (MINUS_EXPR
, gnu_min
, size_one_node
);
1795 /* See if the base array type is already flat. If it is, we
1796 are probably compiling an ACVC test, but it will cause the
1797 code below to malfunction if we don't handle it specially. */
1798 if (TREE_CODE (gnu_base_min
) == INTEGER_CST
1799 && TREE_CODE (gnu_base_max
) == INTEGER_CST
1800 && ! TREE_CONSTANT_OVERFLOW (gnu_base_min
)
1801 && ! TREE_CONSTANT_OVERFLOW (gnu_base_max
)
1802 && tree_int_cst_lt (gnu_base_max
, gnu_base_min
))
1803 gnu_high
= size_zero_node
, gnu_min
= size_one_node
;
1805 /* If gnu_high is now an integer which overflowed, the array
1806 cannot be superflat. */
1807 else if (TREE_CODE (gnu_high
) == INTEGER_CST
1808 && TREE_OVERFLOW (gnu_high
))
1810 else if (TYPE_UNSIGNED (gnu_base_subtype
)
1811 || TREE_CODE (gnu_high
) == INTEGER_CST
)
1812 gnu_high
= size_binop (MAX_EXPR
, gnu_max
, gnu_high
);
1816 (sizetype
, build_binary_op (GE_EXPR
, integer_type_node
,
1820 gnu_index_type
[index
]
1821 = create_index_type (gnu_min
, gnu_high
, gnu_index_subtype
);
1823 /* Also compute the maximum size of the array. Here we
1824 see if any constraint on the index type of the base type
1825 can be used in the case of self-referential bound on
1826 the index type of the subtype. We look for a non-"infinite"
1827 and non-self-referential bound from any type involved and
1828 handle each bound separately. */
1830 if ((TREE_CODE (gnu_min
) == INTEGER_CST
1831 && ! TREE_OVERFLOW (gnu_min
)
1832 && ! operand_equal_p (gnu_min
, gnu_base_base_min
, 0))
1833 || ! CONTAINS_PLACEHOLDER_P (gnu_min
))
1834 gnu_base_min
= gnu_min
;
1836 if ((TREE_CODE (gnu_max
) == INTEGER_CST
1837 && ! TREE_OVERFLOW (gnu_max
)
1838 && ! operand_equal_p (gnu_max
, gnu_base_base_max
, 0))
1839 || ! CONTAINS_PLACEHOLDER_P (gnu_max
))
1840 gnu_base_max
= gnu_max
;
1842 if ((TREE_CODE (gnu_base_min
) == INTEGER_CST
1843 && TREE_CONSTANT_OVERFLOW (gnu_base_min
))
1844 || operand_equal_p (gnu_base_min
, gnu_base_base_min
, 0)
1845 || (TREE_CODE (gnu_base_max
) == INTEGER_CST
1846 && TREE_CONSTANT_OVERFLOW (gnu_base_max
))
1847 || operand_equal_p (gnu_base_max
, gnu_base_base_max
, 0))
1850 gnu_base_min
= size_binop (MAX_EXPR
, gnu_base_min
, gnu_min
);
1851 gnu_base_max
= size_binop (MIN_EXPR
, gnu_base_max
, gnu_max
);
1854 = size_binop (MAX_EXPR
,
1855 size_binop (PLUS_EXPR
, size_one_node
,
1856 size_binop (MINUS_EXPR
, gnu_base_max
,
1860 if (TREE_CODE (gnu_this_max
) == INTEGER_CST
1861 && TREE_CONSTANT_OVERFLOW (gnu_this_max
))
1865 = size_binop (MULT_EXPR
, gnu_max_size
, gnu_this_max
);
1867 if (! integer_onep (TYPE_MIN_VALUE (gnu_index_subtype
))
1868 || (TREE_CODE (TYPE_MAX_VALUE (gnu_index_subtype
))
1870 || TREE_CODE (gnu_index_subtype
) != INTEGER_TYPE
1871 || (TREE_TYPE (gnu_index_subtype
) != 0
1872 && (TREE_CODE (TREE_TYPE (gnu_index_subtype
))
1874 || TYPE_BIASED_REPRESENTATION_P (gnu_index_subtype
)
1875 || (TYPE_PRECISION (gnu_index_subtype
)
1876 > TYPE_PRECISION (sizetype
)))
1877 need_index_type_struct
= 1;
1880 /* Then flatten: create the array of arrays. */
1882 gnu_type
= gnat_to_gnu_type (Component_Type (gnat_entity
));
1884 /* One of the above calls might have caused us to be elaborated,
1885 so don't blow up if so. */
1886 if (present_gnu_tree (gnat_entity
))
1892 /* Get and validate any specified Component_Size, but if Packed,
1893 ignore it since the front end will have taken care of it. */
1895 = validate_size (Component_Size (gnat_entity
), gnu_type
,
1897 (Is_Bit_Packed_Array (gnat_entity
)
1898 ? TYPE_DECL
: VAR_DECL
),
1899 1, Has_Component_Size_Clause (gnat_entity
));
1901 /* If the component type is a RECORD_TYPE that has a self-referential
1902 size, use the maxium size. */
1903 if (gnu_comp_size
== 0 && TREE_CODE (gnu_type
) == RECORD_TYPE
1904 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
)))
1905 gnu_comp_size
= max_size (TYPE_SIZE (gnu_type
), 1);
1907 if (! Is_Bit_Packed_Array (gnat_entity
) && gnu_comp_size
!= 0)
1909 gnu_type
= make_type_from_size (gnu_type
, gnu_comp_size
, 0);
1910 gnu_type
= maybe_pad_type (gnu_type
, gnu_comp_size
, 0,
1911 gnat_entity
, "C_PAD", 0,
1915 if (Has_Volatile_Components (Base_Type (gnat_entity
)))
1916 gnu_type
= build_qualified_type (gnu_type
,
1917 (TYPE_QUALS (gnu_type
)
1918 | TYPE_QUAL_VOLATILE
));
1920 gnu_max_size_unit
= size_binop (MULT_EXPR
, gnu_max_size
,
1921 TYPE_SIZE_UNIT (gnu_type
));
1922 gnu_max_size
= size_binop (MULT_EXPR
,
1923 convert (bitsizetype
, gnu_max_size
),
1924 TYPE_SIZE (gnu_type
));
1926 for (index
= array_dim
- 1; index
>= 0; index
--)
1928 gnu_type
= build_array_type (gnu_type
, gnu_index_type
[index
]);
1929 TYPE_MULTI_ARRAY_P (gnu_type
) = (index
> 0);
1930 /* If the type below this an multi-array type, then this
1931 does not not have aliased components.
1933 ??? Otherwise, for now, we say that any component of aggregate
1934 type is addressable because the front end may take 'Reference
1935 of it. But we have to make it addressable if it must be passed
1936 by reference or it that is the default. */
1937 TYPE_NONALIASED_COMPONENT (gnu_type
)
1938 = ((TREE_CODE (TREE_TYPE (gnu_type
)) == ARRAY_TYPE
1939 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type
))) ? 1
1940 : (! Has_Aliased_Components (gnat_entity
)
1941 && ! AGGREGATE_TYPE_P (TREE_TYPE (gnu_type
))));
1944 /* If we are at file level and this is a multi-dimensional array, we
1945 need to make a variable corresponding to the stride of the
1946 inner dimensions. */
1947 if (global_bindings_p () && array_dim
> 1)
1949 tree gnu_str_name
= get_identifier ("ST");
1952 for (gnu_arr_type
= TREE_TYPE (gnu_type
);
1953 TREE_CODE (gnu_arr_type
) == ARRAY_TYPE
;
1954 gnu_arr_type
= TREE_TYPE (gnu_arr_type
),
1955 gnu_str_name
= concat_id_with_name (gnu_str_name
, "ST"))
1957 TYPE_SIZE (gnu_arr_type
)
1958 = elaborate_expression_1 (gnat_entity
, gnat_entity
,
1959 TYPE_SIZE (gnu_arr_type
),
1960 gnu_str_name
, definition
, 0);
1961 TYPE_SIZE_UNIT (gnu_arr_type
)
1962 = elaborate_expression_1
1963 (gnat_entity
, gnat_entity
, TYPE_SIZE_UNIT (gnu_arr_type
),
1964 concat_id_with_name (gnu_str_name
, "U"), definition
, 0);
1968 /* If we need to write out a record type giving the names of
1969 the bounds, do it now. */
1970 if (need_index_type_struct
&& debug_info_p
)
1972 tree gnu_bound_rec_type
= make_node (RECORD_TYPE
);
1973 tree gnu_field_list
= 0;
1976 TYPE_NAME (gnu_bound_rec_type
)
1977 = create_concat_name (gnat_entity
, "XA");
1979 for (index
= array_dim
- 1; index
>= 0; index
--)
1982 = TYPE_NAME (TYPE_INDEX_TYPE (gnu_index_type
[index
]));
1984 if (TREE_CODE (gnu_type_name
) == TYPE_DECL
)
1985 gnu_type_name
= DECL_NAME (gnu_type_name
);
1987 gnu_field
= create_field_decl (gnu_type_name
,
1990 0, NULL_TREE
, NULL_TREE
, 0);
1991 TREE_CHAIN (gnu_field
) = gnu_field_list
;
1992 gnu_field_list
= gnu_field
;
1995 finish_record_type (gnu_bound_rec_type
, gnu_field_list
, 0, 0);
1998 TYPE_CONVENTION_FORTRAN_P (gnu_type
)
1999 = (Convention (gnat_entity
) == Convention_Fortran
);
2000 TYPE_PACKED_ARRAY_TYPE_P (gnu_type
)
2001 = Is_Packed_Array_Type (gnat_entity
);
2003 /* If our size depends on a placeholder and the maximum size doesn't
2004 overflow, use it. */
2005 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
))
2006 && ! (TREE_CODE (gnu_max_size
) == INTEGER_CST
2007 && TREE_OVERFLOW (gnu_max_size
))
2008 && ! (TREE_CODE (gnu_max_size_unit
) == INTEGER_CST
2009 && TREE_OVERFLOW (gnu_max_size_unit
))
2012 TYPE_SIZE (gnu_type
) = size_binop (MIN_EXPR
, gnu_max_size
,
2013 TYPE_SIZE (gnu_type
));
2014 TYPE_SIZE_UNIT (gnu_type
)
2015 = size_binop (MIN_EXPR
, gnu_max_size_unit
,
2016 TYPE_SIZE_UNIT (gnu_type
));
2019 /* Set our alias set to that of our base type. This gives all
2020 array subtypes the same alias set. */
2021 copy_alias_set (gnu_type
, gnu_base_type
);
2024 /* If this is a packed type, make this type the same as the packed
2025 array type, but do some adjusting in the type first. */
2027 if (Present (Packed_Array_Type (gnat_entity
)))
2029 Entity_Id gnat_index
;
2030 tree gnu_inner_type
;
2032 /* First finish the type we had been making so that we output
2033 debugging information for it */
2034 gnu_type
= build_qualified_type (gnu_type
,
2035 (TYPE_QUALS (gnu_type
)
2036 | (TYPE_QUAL_VOLATILE
2037 * Treat_As_Volatile (gnat_entity
))));
2038 set_lineno (gnat_entity
, 0);
2039 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
2040 ! Comes_From_Source (gnat_entity
),
2042 if (! Comes_From_Source (gnat_entity
))
2043 DECL_ARTIFICIAL (gnu_decl
) = 1;
2045 /* Save it as our equivalent in case the call below elaborates
2047 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
2049 gnu_decl
= gnat_to_gnu_entity (Packed_Array_Type (gnat_entity
),
2052 gnu_inner_type
= gnu_type
= TREE_TYPE (gnu_decl
);
2053 save_gnu_tree (gnat_entity
, NULL_TREE
, 0);
2055 while (TREE_CODE (gnu_inner_type
) == RECORD_TYPE
2056 && (TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_inner_type
)
2057 || TYPE_IS_PADDING_P (gnu_inner_type
)))
2058 gnu_inner_type
= TREE_TYPE (TYPE_FIELDS (gnu_inner_type
));
2060 /* We need to point the type we just made to our index type so
2061 the actual bounds can be put into a template. */
2063 if ((TREE_CODE (gnu_inner_type
) == ARRAY_TYPE
2064 && TYPE_ACTUAL_BOUNDS (gnu_inner_type
) == 0)
2065 || (TREE_CODE (gnu_inner_type
) == INTEGER_TYPE
2066 && ! TYPE_HAS_ACTUAL_BOUNDS_P (gnu_inner_type
)))
2068 if (TREE_CODE (gnu_inner_type
) == INTEGER_TYPE
)
2070 /* The TYPE_ACTUAL_BOUNDS field is also used for the modulus.
2071 If it is, we need to make another type. */
2072 if (TYPE_MODULAR_P (gnu_inner_type
))
2076 gnu_subtype
= make_node (INTEGER_TYPE
);
2078 TREE_TYPE (gnu_subtype
) = gnu_inner_type
;
2079 TYPE_MIN_VALUE (gnu_subtype
)
2080 = TYPE_MIN_VALUE (gnu_inner_type
);
2081 TYPE_MAX_VALUE (gnu_subtype
)
2082 = TYPE_MAX_VALUE (gnu_inner_type
);
2083 TYPE_PRECISION (gnu_subtype
)
2084 = TYPE_PRECISION (gnu_inner_type
);
2085 TYPE_UNSIGNED (gnu_subtype
)
2086 = TYPE_UNSIGNED (gnu_inner_type
);
2087 TYPE_EXTRA_SUBTYPE_P (gnu_subtype
) = 1;
2088 layout_type (gnu_subtype
);
2090 gnu_inner_type
= gnu_subtype
;
2093 TYPE_HAS_ACTUAL_BOUNDS_P (gnu_inner_type
) = 1;
2096 SET_TYPE_ACTUAL_BOUNDS (gnu_inner_type
, NULL_TREE
);
2098 for (gnat_index
= First_Index (gnat_entity
);
2099 Present (gnat_index
); gnat_index
= Next_Index (gnat_index
))
2100 SET_TYPE_ACTUAL_BOUNDS (gnu_inner_type
,
2101 tree_cons (NULL_TREE
,
2102 get_unpadded_type (Etype (gnat_index
)),
2103 TYPE_ACTUAL_BOUNDS (gnu_inner_type
)));
2105 if (Convention (gnat_entity
) != Convention_Fortran
)
2106 SET_TYPE_ACTUAL_BOUNDS (gnu_inner_type
,
2107 nreverse (TYPE_ACTUAL_BOUNDS (gnu_inner_type
)));
2109 if (TREE_CODE (gnu_type
) == RECORD_TYPE
2110 && TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_type
))
2111 TREE_TYPE (TYPE_FIELDS (gnu_type
)) = gnu_inner_type
;
2115 /* Abort if packed array with no packed array type field set. */
2116 else if (Is_Packed (gnat_entity
))
2121 case E_String_Literal_Subtype
:
2122 /* Create the type for a string literal. */
2124 Entity_Id gnat_full_type
2125 = (IN (Ekind (Etype (gnat_entity
)), Private_Kind
)
2126 && Present (Full_View (Etype (gnat_entity
)))
2127 ? Full_View (Etype (gnat_entity
)) : Etype (gnat_entity
));
2128 tree gnu_string_type
= get_unpadded_type (gnat_full_type
);
2129 tree gnu_string_array_type
2130 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_string_type
))));
2131 tree gnu_string_index_type
2132 = get_base_type (TREE_TYPE (TYPE_INDEX_TYPE
2133 (TYPE_DOMAIN (gnu_string_array_type
))));
2134 tree gnu_lower_bound
2135 = convert (gnu_string_index_type
,
2136 gnat_to_gnu (String_Literal_Low_Bound (gnat_entity
)));
2137 int length
= UI_To_Int (String_Literal_Length (gnat_entity
));
2138 tree gnu_length
= ssize_int (length
- 1);
2139 tree gnu_upper_bound
2140 = build_binary_op (PLUS_EXPR
, gnu_string_index_type
,
2142 convert (gnu_string_index_type
, gnu_length
));
2144 = build_range_type (gnu_string_index_type
,
2145 gnu_lower_bound
, gnu_upper_bound
);
2147 = create_index_type (convert (sizetype
,
2148 TYPE_MIN_VALUE (gnu_range_type
)),
2150 TYPE_MAX_VALUE (gnu_range_type
)),
2154 = build_array_type (gnat_to_gnu_type (Component_Type (gnat_entity
)),
2159 /* Record Types and Subtypes
2161 The following fields are defined on record types:
2163 Has_Discriminants True if the record has discriminants
2164 First_Discriminant Points to head of list of discriminants
2165 First_Entity Points to head of list of fields
2166 Is_Tagged_Type True if the record is tagged
2168 Implementation of Ada records and discriminated records:
2170 A record type definition is transformed into the equivalent of a C
2171 struct definition. The fields that are the discriminants which are
2172 found in the Full_Type_Declaration node and the elements of the
2173 Component_List found in the Record_Type_Definition node. The
2174 Component_List can be a recursive structure since each Variant of
2175 the Variant_Part of the Component_List has a Component_List.
2177 Processing of a record type definition comprises starting the list of
2178 field declarations here from the discriminants and the calling the
2179 function components_to_record to add the rest of the fields from the
2180 component list and return the gnu type node. The function
2181 components_to_record will call itself recursively as it traverses
2185 if (Has_Complex_Representation (gnat_entity
))
2188 = build_complex_type
2190 (Etype (Defining_Entity
2191 (First (Component_Items
2194 (Declaration_Node (gnat_entity
)))))))));
2200 Node_Id full_definition
= Declaration_Node (gnat_entity
);
2201 Node_Id record_definition
= Type_Definition (full_definition
);
2202 Entity_Id gnat_field
;
2204 tree gnu_field_list
= NULL_TREE
;
2205 tree gnu_get_parent
;
2206 int packed
= (Is_Packed (gnat_entity
) ? 1
2207 : (Component_Alignment (gnat_entity
)
2208 == Calign_Storage_Unit
) ? -1
2210 int has_rep
= Has_Specified_Layout (gnat_entity
);
2211 int all_rep
= has_rep
;
2213 = (Is_Tagged_Type (gnat_entity
)
2214 && Nkind (record_definition
) == N_Derived_Type_Definition
);
2216 /* See if all fields have a rep clause. Stop when we find one
2218 for (gnat_field
= First_Entity (gnat_entity
);
2219 Present (gnat_field
) && all_rep
;
2220 gnat_field
= Next_Entity (gnat_field
))
2221 if ((Ekind (gnat_field
) == E_Component
2222 || Ekind (gnat_field
) == E_Discriminant
)
2223 && No (Component_Clause (gnat_field
)))
2226 /* If this is a record extension, go a level further to find the
2227 record definition. Also, verify we have a Parent_Subtype. */
2230 if (! type_annotate_only
2231 || Present (Record_Extension_Part (record_definition
)))
2232 record_definition
= Record_Extension_Part (record_definition
);
2234 if (! type_annotate_only
&& No (Parent_Subtype (gnat_entity
)))
2238 /* Make a node for the record. If we are not defining the record,
2239 suppress expanding incomplete types and save the node as the type
2240 for GNAT_ENTITY. We use the same RECORD_TYPE as for a dummy type
2241 and reset TYPE_DUMMY_P to show it's no longer a dummy.
2243 It is very tempting to delay resetting this bit until we are done
2244 with completing the type, e.g. to let possible intermediate
2245 elaboration of access types designating the record know it is not
2246 complete and arrange for update_pointer_to to fix things up later.
2248 It would be wrong, however, because dummy types are expected only
2249 to be created for Ada incomplete or private types, which is not
2250 what we have here. Doing so would make other parts of gigi think
2251 we are dealing with a really incomplete or private type, and have
2252 nasty side effects, typically on the generation of the associated
2253 debugging information. */
2254 gnu_type
= make_dummy_type (gnat_entity
);
2255 TYPE_DUMMY_P (gnu_type
) = 0;
2257 if (TREE_CODE (TYPE_NAME (gnu_type
)) == TYPE_DECL
&& debug_info_p
)
2258 DECL_IGNORED_P (TYPE_NAME (gnu_type
)) = 0;
2260 TYPE_ALIGN (gnu_type
) = 0;
2261 TYPE_PACKED (gnu_type
) = packed
!= 0 || has_rep
;
2265 defer_incomplete_level
++;
2267 set_lineno (gnat_entity
, 0);
2268 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
2269 ! Comes_From_Source (gnat_entity
),
2271 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
2272 this_made_decl
= saved
= 1;
2275 /* If both a size and rep clause was specified, put the size in
2276 the record type now so that it can get the proper mode. */
2277 if (has_rep
&& Known_Esize (gnat_entity
))
2278 TYPE_SIZE (gnu_type
) = UI_To_gnu (Esize (gnat_entity
), sizetype
);
2280 /* Always set the alignment here so that it can be used to
2281 set the mode, if it is making the alignment stricter. If
2282 it is invalid, it will be checked again below. If this is to
2283 be Atomic, choose a default alignment of a word unless we know
2284 the size and it's smaller. */
2285 if (Known_Alignment (gnat_entity
))
2286 TYPE_ALIGN (gnu_type
)
2287 = validate_alignment (Alignment (gnat_entity
), gnat_entity
, 0);
2288 else if (Is_Atomic (gnat_entity
))
2289 TYPE_ALIGN (gnu_type
)
2290 = (esize
>= BITS_PER_WORD
? BITS_PER_WORD
2291 : 1 << ((floor_log2 (esize
) - 1) + 1));
2293 /* If we have a Parent_Subtype, make a field for the parent. If
2294 this record has rep clauses, force the position to zero. */
2295 if (Present (Parent_Subtype (gnat_entity
)))
2299 /* A major complexity here is that the parent subtype will
2300 reference our discriminants. But those must reference
2301 the parent component of this record. So here we will
2302 initialize each of those components to a COMPONENT_REF.
2303 The first operand of that COMPONENT_REF is another
2304 COMPONENT_REF which will be filled in below, once
2305 the parent type can be safely built. */
2307 gnu_get_parent
= build (COMPONENT_REF
, void_type_node
,
2308 build (PLACEHOLDER_EXPR
, gnu_type
),
2309 build_decl (FIELD_DECL
, NULL_TREE
,
2312 if (Has_Discriminants (gnat_entity
))
2313 for (gnat_field
= First_Stored_Discriminant (gnat_entity
);
2314 Present (gnat_field
);
2315 gnat_field
= Next_Stored_Discriminant (gnat_field
))
2316 if (Present (Corresponding_Discriminant (gnat_field
)))
2319 build (COMPONENT_REF
,
2320 get_unpadded_type (Etype (gnat_field
)),
2322 gnat_to_gnu_entity (Corresponding_Discriminant
2327 gnu_parent
= gnat_to_gnu_type (Parent_Subtype (gnat_entity
));
2330 = create_field_decl (get_identifier
2331 (Get_Name_String (Name_uParent
)),
2332 gnu_parent
, gnu_type
, 0,
2333 has_rep
? TYPE_SIZE (gnu_parent
) : 0,
2334 has_rep
? bitsize_zero_node
: 0, 1);
2335 DECL_INTERNAL_P (gnu_field_list
) = 1;
2337 TREE_TYPE (gnu_get_parent
) = gnu_parent
;
2338 TREE_OPERAND (gnu_get_parent
, 1) = gnu_field_list
;
2341 /* Add the fields for the discriminants into the record. */
2342 if (! Is_Unchecked_Union (gnat_entity
)
2343 && Has_Discriminants (gnat_entity
))
2344 for (gnat_field
= First_Stored_Discriminant (gnat_entity
);
2345 Present (gnat_field
);
2346 gnat_field
= Next_Stored_Discriminant (gnat_field
))
2348 /* If this is a record extension and this discriminant
2349 is the renaming of another discriminant, we've already
2350 handled the discriminant above. */
2351 if (Present (Parent_Subtype (gnat_entity
))
2352 && Present (Corresponding_Discriminant (gnat_field
)))
2356 = gnat_to_gnu_field (gnat_field
, gnu_type
, packed
, definition
);
2358 /* Make an expression using a PLACEHOLDER_EXPR from the
2359 FIELD_DECL node just created and link that with the
2360 corresponding GNAT defining identifier. Then add to the
2362 save_gnu_tree (gnat_field
,
2363 build (COMPONENT_REF
, TREE_TYPE (gnu_field
),
2364 build (PLACEHOLDER_EXPR
,
2365 DECL_CONTEXT (gnu_field
)),
2369 TREE_CHAIN (gnu_field
) = gnu_field_list
;
2370 gnu_field_list
= gnu_field
;
2373 /* Put the discriminants into the record (backwards), so we can
2374 know the appropriate discriminant to use for the names of the
2376 TYPE_FIELDS (gnu_type
) = gnu_field_list
;
2378 /* Add the listed fields into the record and finish up. */
2379 components_to_record (gnu_type
, Component_List (record_definition
),
2380 gnu_field_list
, packed
, definition
, 0,
2383 TYPE_VOLATILE (gnu_type
) = Treat_As_Volatile (gnat_entity
);
2384 TYPE_BY_REFERENCE_P (gnu_type
) = Is_By_Reference_Type (gnat_entity
);
2386 /* If this is an extension type, reset the tree for any
2387 inherited discriminants. Also remove the PLACEHOLDER_EXPR
2388 for non-inherited discriminants. */
2389 if (! Is_Unchecked_Union (gnat_entity
)
2390 && Has_Discriminants (gnat_entity
))
2391 for (gnat_field
= First_Stored_Discriminant (gnat_entity
);
2392 Present (gnat_field
);
2393 gnat_field
= Next_Stored_Discriminant (gnat_field
))
2395 if (Present (Parent_Subtype (gnat_entity
))
2396 && Present (Corresponding_Discriminant (gnat_field
)))
2397 save_gnu_tree (gnat_field
, NULL_TREE
, 0);
2400 gnu_field
= get_gnu_tree (gnat_field
);
2401 save_gnu_tree (gnat_field
, NULL_TREE
, 0);
2402 save_gnu_tree (gnat_field
, TREE_OPERAND (gnu_field
, 1), 0);
2406 /* If it is a tagged record force the type to BLKmode to insure
2407 that these objects will always be placed in memory. Do the
2408 same thing for limited record types. */
2409 if (Is_Tagged_Type (gnat_entity
) || Is_Limited_Record (gnat_entity
))
2410 TYPE_MODE (gnu_type
) = BLKmode
;
2412 /* If this is a derived type, we must make the alias set of this type
2413 the same as that of the type we are derived from. We assume here
2414 that the other type is already frozen. */
2415 if (Etype (gnat_entity
) != gnat_entity
2416 && ! (Is_Private_Type (Etype (gnat_entity
))
2417 && Full_View (Etype (gnat_entity
)) == gnat_entity
))
2418 copy_alias_set (gnu_type
, gnat_to_gnu_type (Etype (gnat_entity
)));
2420 /* Fill in locations of fields. */
2421 annotate_rep (gnat_entity
, gnu_type
);
2423 /* If there are any entities in the chain corresponding to
2424 components that we did not elaborate, ensure we elaborate their
2425 types if they are Itypes. */
2426 for (gnat_temp
= First_Entity (gnat_entity
);
2427 Present (gnat_temp
); gnat_temp
= Next_Entity (gnat_temp
))
2428 if ((Ekind (gnat_temp
) == E_Component
2429 || Ekind (gnat_temp
) == E_Discriminant
)
2430 && Is_Itype (Etype (gnat_temp
))
2431 && ! present_gnu_tree (gnat_temp
))
2432 gnat_to_gnu_entity (Etype (gnat_temp
), NULL_TREE
, 0);
2436 case E_Class_Wide_Subtype
:
2437 /* If an equivalent type is present, that is what we should use.
2438 Otherwise, fall through to handle this like a record subtype
2439 since it may have constraints. */
2441 if (Present (Equivalent_Type (gnat_entity
)))
2443 gnu_decl
= gnat_to_gnu_entity (Equivalent_Type (gnat_entity
),
2449 /* ... fall through ... */
2451 case E_Record_Subtype
:
2453 /* If Cloned_Subtype is Present it means this record subtype has
2454 identical layout to that type or subtype and we should use
2455 that GCC type for this one. The front end guarantees that
2456 the component list is shared. */
2457 if (Present (Cloned_Subtype (gnat_entity
)))
2459 gnu_decl
= gnat_to_gnu_entity (Cloned_Subtype (gnat_entity
),
2464 /* Otherwise, first ensure the base type is elaborated. Then, if we are
2465 changing the type, make a new type with each field having the
2466 type of the field in the new subtype but having the position
2467 computed by transforming every discriminant reference according
2468 to the constraints. We don't see any difference between
2469 private and nonprivate type here since derivations from types should
2470 have been deferred until the completion of the private type. */
2473 Entity_Id gnat_base_type
= Implementation_Base_Type (gnat_entity
);
2478 defer_incomplete_level
++, this_deferred
= 1;
2480 /* Get the base type initially for its alignment and sizes. But
2481 if it is a padded type, we do all the other work with the
2483 gnu_type
= gnu_orig_type
= gnu_base_type
2484 = gnat_to_gnu_type (gnat_base_type
);
2486 if (TREE_CODE (gnu_type
) == RECORD_TYPE
2487 && TYPE_IS_PADDING_P (gnu_type
))
2488 gnu_type
= gnu_orig_type
= TREE_TYPE (TYPE_FIELDS (gnu_type
));
2490 if (present_gnu_tree (gnat_entity
))
2496 /* When the type has discriminants, and these discriminants
2497 affect the shape of what it built, factor them in.
2499 If we are making a subtype of an Unchecked_Union (must be an
2500 Itype), just return the type.
2502 We can't just use Is_Constrained because private subtypes without
2503 discriminants of full types with discriminants with default
2504 expressions are Is_Constrained but aren't constrained! */
2506 if (IN (Ekind (gnat_base_type
), Record_Kind
)
2507 && ! Is_For_Access_Subtype (gnat_entity
)
2508 && ! Is_Unchecked_Union (gnat_base_type
)
2509 && Is_Constrained (gnat_entity
)
2510 && Stored_Constraint (gnat_entity
) != No_Elist
2511 && Present (Discriminant_Constraint (gnat_entity
)))
2513 Entity_Id gnat_field
;
2514 Entity_Id gnat_root_type
;
2515 tree gnu_field_list
= 0;
2517 = compute_field_positions (gnu_orig_type
, NULL_TREE
,
2518 size_zero_node
, bitsize_zero_node
,
2521 = substitution_list (gnat_entity
, gnat_base_type
, NULL_TREE
,
2525 /* If this is a derived type, we may be seeing fields from any
2526 original records, so add those positions and discriminant
2527 substitutions to our lists. */
2528 for (gnat_root_type
= gnat_base_type
;
2529 Underlying_Type (Etype (gnat_root_type
)) != gnat_root_type
;
2530 gnat_root_type
= Underlying_Type (Etype (gnat_root_type
)))
2533 = compute_field_positions
2534 (gnat_to_gnu_type (Etype (gnat_root_type
)),
2535 gnu_pos_list
, size_zero_node
, bitsize_zero_node
,
2538 if (Present (Parent_Subtype (gnat_root_type
)))
2540 = substitution_list (Parent_Subtype (gnat_root_type
),
2541 Empty
, gnu_subst_list
, definition
);
2544 gnu_type
= make_node (RECORD_TYPE
);
2545 TYPE_NAME (gnu_type
) = gnu_entity_id
;
2546 TYPE_STUB_DECL (gnu_type
)
2547 = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, gnu_type
));
2548 TYPE_ALIGN (gnu_type
) = TYPE_ALIGN (gnu_base_type
);
2550 for (gnat_field
= First_Entity (gnat_entity
);
2551 Present (gnat_field
); gnat_field
= Next_Entity (gnat_field
))
2552 if (Ekind (gnat_field
) == E_Component
2553 || Ekind (gnat_field
) == E_Discriminant
)
2556 = gnat_to_gnu_entity
2557 (Original_Record_Component (gnat_field
), NULL_TREE
, 0);
2559 = TREE_VALUE (purpose_member (gnu_old_field
,
2561 tree gnu_pos
= TREE_PURPOSE (gnu_offset
);
2562 tree gnu_bitpos
= TREE_VALUE (TREE_VALUE (gnu_offset
));
2564 = gnat_to_gnu_type (Etype (gnat_field
));
2565 tree gnu_size
= TYPE_SIZE (gnu_field_type
);
2566 tree gnu_new_pos
= 0;
2567 unsigned int offset_align
2568 = tree_low_cst (TREE_PURPOSE (TREE_VALUE (gnu_offset
)),
2572 /* If there was a component clause, the field types must be
2573 the same for the type and subtype, so copy the data from
2574 the old field to avoid recomputation here. */
2575 if (Present (Component_Clause
2576 (Original_Record_Component (gnat_field
))))
2578 gnu_size
= DECL_SIZE (gnu_old_field
);
2579 gnu_field_type
= TREE_TYPE (gnu_old_field
);
2582 /* If this was a bitfield, get the size from the old field.
2583 Also ensure the type can be placed into a bitfield. */
2584 else if (DECL_BIT_FIELD (gnu_old_field
))
2586 gnu_size
= DECL_SIZE (gnu_old_field
);
2587 if (TYPE_MODE (gnu_field_type
) == BLKmode
2588 && TREE_CODE (gnu_field_type
) == RECORD_TYPE
2589 && host_integerp (TYPE_SIZE (gnu_field_type
), 1))
2590 gnu_field_type
= make_packable_type (gnu_field_type
);
2593 if (CONTAINS_PLACEHOLDER_P (gnu_pos
))
2594 for (gnu_temp
= gnu_subst_list
;
2595 gnu_temp
; gnu_temp
= TREE_CHAIN (gnu_temp
))
2596 gnu_pos
= substitute_in_expr (gnu_pos
,
2597 TREE_PURPOSE (gnu_temp
),
2598 TREE_VALUE (gnu_temp
));
2600 /* If the size is now a constant, we can set it as the
2601 size of the field when we make it. Otherwise, we need
2602 to deal with it specially. */
2603 if (TREE_CONSTANT (gnu_pos
))
2604 gnu_new_pos
= bit_from_pos (gnu_pos
, gnu_bitpos
);
2608 (DECL_NAME (gnu_old_field
), gnu_field_type
, gnu_type
,
2609 0, gnu_size
, gnu_new_pos
,
2610 ! DECL_NONADDRESSABLE_P (gnu_old_field
));
2612 if (! TREE_CONSTANT (gnu_pos
))
2614 normalize_offset (&gnu_pos
, &gnu_bitpos
, offset_align
);
2615 DECL_FIELD_OFFSET (gnu_field
) = gnu_pos
;
2616 DECL_FIELD_BIT_OFFSET (gnu_field
) = gnu_bitpos
;
2617 SET_DECL_OFFSET_ALIGN (gnu_field
, offset_align
);
2618 DECL_SIZE (gnu_field
) = gnu_size
;
2619 DECL_SIZE_UNIT (gnu_field
)
2620 = convert (sizetype
,
2621 size_binop (CEIL_DIV_EXPR
, gnu_size
,
2622 bitsize_unit_node
));
2623 layout_decl (gnu_field
, DECL_OFFSET_ALIGN (gnu_field
));
2626 DECL_INTERNAL_P (gnu_field
)
2627 = DECL_INTERNAL_P (gnu_old_field
);
2628 SET_DECL_ORIGINAL_FIELD (gnu_field
,
2629 (DECL_ORIGINAL_FIELD (gnu_old_field
) != 0
2630 ? DECL_ORIGINAL_FIELD (gnu_old_field
)
2632 DECL_DISCRIMINANT_NUMBER (gnu_field
)
2633 = DECL_DISCRIMINANT_NUMBER (gnu_old_field
);
2634 TREE_THIS_VOLATILE (gnu_field
)
2635 = TREE_THIS_VOLATILE (gnu_old_field
);
2636 TREE_CHAIN (gnu_field
) = gnu_field_list
;
2637 gnu_field_list
= gnu_field
;
2638 save_gnu_tree (gnat_field
, gnu_field
, 0);
2641 finish_record_type (gnu_type
, nreverse (gnu_field_list
), 1, 0);
2643 /* Now set the size, alignment and alias set of the new type to
2644 match that of the old one, doing any substitutions, as
2646 TYPE_ALIGN (gnu_type
) = TYPE_ALIGN (gnu_base_type
);
2647 TYPE_SIZE (gnu_type
) = TYPE_SIZE (gnu_base_type
);
2648 TYPE_SIZE_UNIT (gnu_type
) = TYPE_SIZE_UNIT (gnu_base_type
);
2649 SET_TYPE_ADA_SIZE (gnu_type
, TYPE_ADA_SIZE (gnu_base_type
));
2650 copy_alias_set (gnu_type
, gnu_base_type
);
2652 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
)))
2653 for (gnu_temp
= gnu_subst_list
;
2654 gnu_temp
; gnu_temp
= TREE_CHAIN (gnu_temp
))
2655 TYPE_SIZE (gnu_type
)
2656 = substitute_in_expr (TYPE_SIZE (gnu_type
),
2657 TREE_PURPOSE (gnu_temp
),
2658 TREE_VALUE (gnu_temp
));
2660 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE_UNIT (gnu_type
)))
2661 for (gnu_temp
= gnu_subst_list
;
2662 gnu_temp
; gnu_temp
= TREE_CHAIN (gnu_temp
))
2663 TYPE_SIZE_UNIT (gnu_type
)
2664 = substitute_in_expr (TYPE_SIZE_UNIT (gnu_type
),
2665 TREE_PURPOSE (gnu_temp
),
2666 TREE_VALUE (gnu_temp
));
2668 if (TYPE_ADA_SIZE (gnu_type
) != 0
2669 && CONTAINS_PLACEHOLDER_P (TYPE_ADA_SIZE (gnu_type
)))
2670 for (gnu_temp
= gnu_subst_list
;
2671 gnu_temp
; gnu_temp
= TREE_CHAIN (gnu_temp
))
2672 SET_TYPE_ADA_SIZE (gnu_type
,
2673 substitute_in_expr (TYPE_ADA_SIZE (gnu_type
),
2674 TREE_PURPOSE (gnu_temp
),
2675 TREE_VALUE (gnu_temp
)));
2677 /* Recompute the mode of this record type now that we know its
2679 compute_record_mode (gnu_type
);
2681 /* Fill in locations of fields. */
2682 annotate_rep (gnat_entity
, gnu_type
);
2685 /* If we've made a new type, record it and make an XVS type to show
2686 what this is a subtype of. Some debuggers require the XVS
2687 type to be output first, so do it in that order. */
2688 if (gnu_type
!= gnu_orig_type
)
2692 tree gnu_subtype_marker
= make_node (RECORD_TYPE
);
2693 tree gnu_orig_name
= TYPE_NAME (gnu_orig_type
);
2695 if (TREE_CODE (gnu_orig_name
) == TYPE_DECL
)
2696 gnu_orig_name
= DECL_NAME (gnu_orig_name
);
2698 TYPE_NAME (gnu_subtype_marker
)
2699 = create_concat_name (gnat_entity
, "XVS");
2700 finish_record_type (gnu_subtype_marker
,
2701 create_field_decl (gnu_orig_name
,
2709 TYPE_VOLATILE (gnu_type
) = Treat_As_Volatile (gnat_entity
);
2710 TYPE_NAME (gnu_type
) = gnu_entity_id
;
2711 TYPE_STUB_DECL (gnu_type
)
2712 = pushdecl (build_decl (TYPE_DECL
, TYPE_NAME (gnu_type
),
2714 DECL_ARTIFICIAL (TYPE_STUB_DECL (gnu_type
)) = 1;
2715 DECL_IGNORED_P (TYPE_STUB_DECL (gnu_type
)) = ! debug_info_p
;
2716 rest_of_type_compilation (gnu_type
, global_bindings_p ());
2719 /* Otherwise, go down all the components in the new type and
2720 make them equivalent to those in the base type. */
2722 for (gnat_temp
= First_Entity (gnat_entity
); Present (gnat_temp
);
2723 gnat_temp
= Next_Entity (gnat_temp
))
2724 if ((Ekind (gnat_temp
) == E_Discriminant
2725 && ! Is_Unchecked_Union (gnat_base_type
))
2726 || Ekind (gnat_temp
) == E_Component
)
2727 save_gnu_tree (gnat_temp
,
2729 (Original_Record_Component (gnat_temp
)), 0);
2733 case E_Access_Subprogram_Type
:
2734 case E_Anonymous_Access_Subprogram_Type
:
2735 /* If we are not defining this entity, and we have incomplete
2736 entities being processed above us, make a dummy type and
2737 fill it in later. */
2738 if (! definition
&& defer_incomplete_level
!= 0)
2740 struct incomplete
*p
2741 = (struct incomplete
*) xmalloc (sizeof (struct incomplete
));
2744 = build_pointer_type
2745 (make_dummy_type (Directly_Designated_Type (gnat_entity
)));
2746 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
2747 ! Comes_From_Source (gnat_entity
),
2749 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
2750 this_made_decl
= saved
= 1;
2752 p
->old_type
= TREE_TYPE (gnu_type
);
2753 p
->full_type
= Directly_Designated_Type (gnat_entity
);
2754 p
->next
= defer_incomplete_list
;
2755 defer_incomplete_list
= p
;
2759 /* ... fall through ... */
2761 case E_Allocator_Type
:
2763 case E_Access_Attribute_Type
:
2764 case E_Anonymous_Access_Type
:
2765 case E_General_Access_Type
:
2767 Entity_Id gnat_desig_type
= Directly_Designated_Type (gnat_entity
);
2768 Entity_Id gnat_desig_full
2769 = ((IN (Ekind (Etype (gnat_desig_type
)),
2770 Incomplete_Or_Private_Kind
))
2771 ? Full_View (gnat_desig_type
) : 0);
2772 /* We want to know if we'll be seeing the freeze node for any
2773 incomplete type we may be pointing to. */
2775 = (Present (gnat_desig_full
)
2776 ? In_Extended_Main_Code_Unit (gnat_desig_full
)
2777 : In_Extended_Main_Code_Unit (gnat_desig_type
));
2780 tree gnu_desig_type
= 0;
2781 enum machine_mode p_mode
= mode_for_size (esize
, MODE_INT
, 0);
2783 if (!targetm
.valid_pointer_mode (p_mode
))
2786 if (No (gnat_desig_full
)
2787 && (Ekind (gnat_desig_type
) == E_Class_Wide_Type
2788 || (Ekind (gnat_desig_type
) == E_Class_Wide_Subtype
2789 && Present (Equivalent_Type (gnat_desig_type
)))))
2791 if (Present (Equivalent_Type (gnat_desig_type
)))
2793 gnat_desig_full
= Equivalent_Type (gnat_desig_type
);
2794 if (IN (Ekind (gnat_desig_full
), Incomplete_Or_Private_Kind
))
2795 gnat_desig_full
= Full_View (gnat_desig_full
);
2797 else if (IN (Ekind (Root_Type (gnat_desig_type
)),
2798 Incomplete_Or_Private_Kind
))
2799 gnat_desig_full
= Full_View (Root_Type (gnat_desig_type
));
2802 if (Present (gnat_desig_full
) && Is_Concurrent_Type (gnat_desig_full
))
2803 gnat_desig_full
= Corresponding_Record_Type (gnat_desig_full
);
2805 /* If either the designated type or its full view is an
2806 unconstrained array subtype, replace it with the type it's a
2807 subtype of. This avoids problems with multiple copies of
2808 unconstrained array types. */
2809 if (Ekind (gnat_desig_type
) == E_Array_Subtype
2810 && ! Is_Constrained (gnat_desig_type
))
2811 gnat_desig_type
= Etype (gnat_desig_type
);
2812 if (Present (gnat_desig_full
)
2813 && Ekind (gnat_desig_full
) == E_Array_Subtype
2814 && ! Is_Constrained (gnat_desig_full
))
2815 gnat_desig_full
= Etype (gnat_desig_full
);
2817 /* If the designated type is a subtype of an incomplete record type,
2818 use the parent type to avoid order of elaboration issues. This
2819 can lose some code efficiency, but there is no alternative. */
2820 if (Present (gnat_desig_full
)
2821 && Ekind (gnat_desig_full
) == E_Record_Subtype
2822 && Ekind (Etype (gnat_desig_full
)) == E_Record_Type
)
2823 gnat_desig_full
= Etype (gnat_desig_full
);
2825 /* If we are pointing to an incomplete type whose completion is an
2826 unconstrained array, make a fat pointer type instead of a pointer
2827 to VOID. The two types in our fields will be pointers to VOID and
2828 will be replaced in update_pointer_to. Similiarly, if the type
2829 itself is a dummy type or an unconstrained array. Also make
2830 a dummy TYPE_OBJECT_RECORD_TYPE in case we have any thin
2833 if ((Present (gnat_desig_full
)
2834 && Is_Array_Type (gnat_desig_full
)
2835 && ! Is_Constrained (gnat_desig_full
))
2836 || (present_gnu_tree (gnat_desig_type
)
2837 && TYPE_IS_DUMMY_P (TREE_TYPE
2838 (get_gnu_tree (gnat_desig_type
)))
2839 && Is_Array_Type (gnat_desig_type
)
2840 && ! Is_Constrained (gnat_desig_type
))
2841 || (present_gnu_tree (gnat_desig_type
)
2842 && (TREE_CODE (TREE_TYPE (get_gnu_tree (gnat_desig_type
)))
2843 == UNCONSTRAINED_ARRAY_TYPE
)
2844 && (TYPE_POINTER_TO (TREE_TYPE
2845 (get_gnu_tree (gnat_desig_type
)))
2847 || (No (gnat_desig_full
) && ! in_main_unit
2848 && defer_incomplete_level
!= 0
2849 && ! present_gnu_tree (gnat_desig_type
)
2850 && Is_Array_Type (gnat_desig_type
)
2851 && ! Is_Constrained (gnat_desig_type
)))
2854 = (present_gnu_tree (gnat_desig_type
)
2855 ? gnat_to_gnu_type (gnat_desig_type
)
2856 : make_dummy_type (gnat_desig_type
));
2859 /* Show the dummy we get will be a fat pointer. */
2860 got_fat_p
= made_dummy
= 1;
2862 /* If the call above got something that has a pointer, that
2863 pointer is our type. This could have happened either
2864 because the type was elaborated or because somebody
2865 else executed the code below. */
2866 gnu_type
= TYPE_POINTER_TO (gnu_old
);
2869 gnu_type
= make_node (RECORD_TYPE
);
2870 SET_TYPE_UNCONSTRAINED_ARRAY (gnu_type
, gnu_old
);
2871 TYPE_POINTER_TO (gnu_old
) = gnu_type
;
2873 set_lineno (gnat_entity
, 0);
2875 = chainon (chainon (NULL_TREE
,
2877 (get_identifier ("P_ARRAY"),
2878 ptr_void_type_node
, gnu_type
,
2880 create_field_decl (get_identifier ("P_BOUNDS"),
2882 gnu_type
, 0, 0, 0, 0));
2884 /* Make sure we can place this into a register. */
2885 TYPE_ALIGN (gnu_type
)
2886 = MIN (BIGGEST_ALIGNMENT
, 2 * POINTER_SIZE
);
2887 TYPE_IS_FAT_POINTER_P (gnu_type
) = 1;
2888 finish_record_type (gnu_type
, fields
, 0, 1);
2890 TYPE_OBJECT_RECORD_TYPE (gnu_old
) = make_node (RECORD_TYPE
);
2891 TYPE_NAME (TYPE_OBJECT_RECORD_TYPE (gnu_old
))
2892 = concat_id_with_name (get_entity_name (gnat_desig_type
),
2894 TYPE_DUMMY_P (TYPE_OBJECT_RECORD_TYPE (gnu_old
)) = 1;
2898 /* If we already know what the full type is, use it. */
2899 else if (Present (gnat_desig_full
)
2900 && present_gnu_tree (gnat_desig_full
))
2901 gnu_desig_type
= TREE_TYPE (get_gnu_tree (gnat_desig_full
));
2903 /* Get the type of the thing we are to point to and build a pointer
2904 to it. If it is a reference to an incomplete or private type with a
2905 full view that is a record, make a dummy type node and get the
2906 actual type later when we have verified it is safe. */
2907 else if (! in_main_unit
2908 && ! present_gnu_tree (gnat_desig_type
)
2909 && Present (gnat_desig_full
)
2910 && ! present_gnu_tree (gnat_desig_full
)
2911 && Is_Record_Type (gnat_desig_full
))
2913 gnu_desig_type
= make_dummy_type (gnat_desig_type
);
2917 /* Likewise if we are pointing to a record or array and we are to defer
2918 elaborating incomplete types. We do this since this access type
2919 may be the full view of some private type. Note that the
2920 unconstrained array case is handled above. */
2921 else if ((! in_main_unit
|| imported_p
) && defer_incomplete_level
!= 0
2922 && ! present_gnu_tree (gnat_desig_type
)
2923 && ((Is_Record_Type (gnat_desig_type
)
2924 || Is_Array_Type (gnat_desig_type
))
2925 || (Present (gnat_desig_full
)
2926 && (Is_Record_Type (gnat_desig_full
)
2927 || Is_Array_Type (gnat_desig_full
)))))
2929 gnu_desig_type
= make_dummy_type (gnat_desig_type
);
2932 else if (gnat_desig_type
== gnat_entity
)
2935 = build_pointer_type_for_mode (make_node (VOID_TYPE
),
2937 No_Strict_Aliasing (gnat_entity
));
2938 TREE_TYPE (gnu_type
) = TYPE_POINTER_TO (gnu_type
) = gnu_type
;
2941 gnu_desig_type
= gnat_to_gnu_type (gnat_desig_type
);
2943 /* It is possible that the above call to gnat_to_gnu_type resolved our
2944 type. If so, just return it. */
2945 if (present_gnu_tree (gnat_entity
))
2951 /* If we have a GCC type for the designated type, possibly modify it
2952 if we are pointing only to constant objects and then make a pointer
2953 to it. Don't do this for unconstrained arrays. */
2954 if (gnu_type
== 0 && gnu_desig_type
!= 0)
2956 if (Is_Access_Constant (gnat_entity
)
2957 && TREE_CODE (gnu_desig_type
) != UNCONSTRAINED_ARRAY_TYPE
)
2960 = build_qualified_type
2962 TYPE_QUALS (gnu_desig_type
) | TYPE_QUAL_CONST
);
2964 /* Some extra processing is required if we are building a
2965 pointer to an incomplete type (in the GCC sense). We might
2966 have such a type if we just made a dummy, or directly out
2967 of the call to gnat_to_gnu_type above if we are processing
2968 an access type for a record component designating the
2969 record type itself. */
2970 if (! COMPLETE_TYPE_P (gnu_desig_type
))
2972 /* We must ensure that the pointer to variant we make will
2973 be processed by update_pointer_to when the initial type
2974 is completed. Pretend we made a dummy and let further
2975 processing act as usual. */
2978 /* We must ensure that update_pointer_to will not retrieve
2979 the dummy variant when building a properly qualified
2980 version of the complete type. We take advantage of the
2981 fact that get_qualified_type is requiring TYPE_NAMEs to
2982 match to influence build_qualified_type and then also
2983 update_pointer_to here. */
2984 TYPE_NAME (gnu_desig_type
)
2985 = create_concat_name (gnat_desig_type
, "INCOMPLETE_CST");
2990 = build_pointer_type_for_mode (gnu_desig_type
, p_mode
,
2991 No_Strict_Aliasing (gnat_entity
));
2994 /* If we are not defining this object and we made a dummy pointer,
2995 save our current definition, evaluate the actual type, and replace
2996 the tentative type we made with the actual one. If we are to defer
2997 actually looking up the actual type, make an entry in the
3000 if (! in_main_unit
&& made_dummy
)
3003 = TYPE_FAT_POINTER_P (gnu_type
)
3004 ? TYPE_UNCONSTRAINED_ARRAY (gnu_type
) : TREE_TYPE (gnu_type
);
3006 if (esize
== POINTER_SIZE
3007 && (got_fat_p
|| TYPE_FAT_POINTER_P (gnu_type
)))
3009 = build_pointer_type
3010 (TYPE_OBJECT_RECORD_TYPE
3011 (TYPE_UNCONSTRAINED_ARRAY (gnu_type
)));
3013 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
3014 ! Comes_From_Source (gnat_entity
),
3016 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
3017 this_made_decl
= saved
= 1;
3019 if (defer_incomplete_level
== 0)
3021 update_pointer_to (TYPE_MAIN_VARIANT (gnu_old_type
),
3022 gnat_to_gnu_type (gnat_desig_type
));
3023 /* Note that the call to gnat_to_gnu_type here might have
3024 updated gnu_old_type directly, in which case it is not a
3025 dummy type any more when we get into update_pointer_to.
3027 This may happen for instance when the designated type is a
3028 record type, because their elaboration starts with an
3029 initial node from make_dummy_type, which may yield the same
3030 node as the one we got.
3032 Besides, variants of this non-dummy type might have been
3033 created along the way. update_pointer_to is expected to
3034 properly take care of those situations. */
3038 struct incomplete
*p
3039 = (struct incomplete
*) xmalloc (sizeof (struct incomplete
));
3041 p
->old_type
= gnu_old_type
;
3042 p
->full_type
= gnat_desig_type
;
3043 p
->next
= defer_incomplete_list
;
3044 defer_incomplete_list
= p
;
3050 case E_Access_Protected_Subprogram_Type
:
3051 case E_Anonymous_Access_Protected_Subprogram_Type
:
3052 if (type_annotate_only
&& No (Equivalent_Type (gnat_entity
)))
3053 gnu_type
= build_pointer_type (void_type_node
);
3055 /* The runtime representation is the equivalent type. */
3056 gnu_type
= gnat_to_gnu_type (Equivalent_Type (gnat_entity
));
3058 if (Is_Itype (Directly_Designated_Type (gnat_entity
))
3059 && ! present_gnu_tree (Directly_Designated_Type (gnat_entity
))
3060 && No (Freeze_Node (Directly_Designated_Type (gnat_entity
)))
3061 && ! Is_Record_Type (Scope (Directly_Designated_Type (gnat_entity
))))
3062 gnat_to_gnu_entity (Directly_Designated_Type (gnat_entity
),
3067 case E_Access_Subtype
:
3069 /* We treat this as identical to its base type; any constraint is
3070 meaningful only to the front end.
3072 The designated type must be elaborated as well, if it does
3073 not have its own freeze node. Designated (sub)types created
3074 for constrained components of records with discriminants are
3075 not frozen by the front end and thus not elaborated by gigi,
3076 because their use may appear before the base type is frozen,
3077 and because it is not clear that they are needed anywhere in
3078 Gigi. With the current model, there is no correct place where
3079 they could be elaborated. */
3081 gnu_type
= gnat_to_gnu_type (Etype (gnat_entity
));
3082 if (Is_Itype (Directly_Designated_Type (gnat_entity
))
3083 && ! present_gnu_tree (Directly_Designated_Type (gnat_entity
))
3084 && Is_Frozen (Directly_Designated_Type (gnat_entity
))
3085 && No (Freeze_Node (Directly_Designated_Type (gnat_entity
))))
3087 /* If we are not defining this entity, and we have incomplete
3088 entities being processed above us, make a dummy type and
3089 elaborate it later. */
3090 if (! definition
&& defer_incomplete_level
!= 0)
3092 struct incomplete
*p
3093 = (struct incomplete
*) xmalloc (sizeof (struct incomplete
));
3095 = build_pointer_type
3096 (make_dummy_type (Directly_Designated_Type (gnat_entity
)));
3098 p
->old_type
= TREE_TYPE (gnu_ptr_type
);
3099 p
->full_type
= Directly_Designated_Type (gnat_entity
);
3100 p
->next
= defer_incomplete_list
;
3101 defer_incomplete_list
= p
;
3104 (IN (Ekind (Base_Type (Directly_Designated_Type (gnat_entity
))),
3105 Incomplete_Or_Private_Kind
))
3108 gnat_to_gnu_entity (Directly_Designated_Type (gnat_entity
),
3115 /* Subprogram Entities
3117 The following access functions are defined for subprograms (functions
3120 First_Formal The first formal parameter.
3121 Is_Imported Indicates that the subprogram has appeared in
3122 an INTERFACE or IMPORT pragma. For now we
3123 assume that the external language is C.
3124 Is_Inlined True if the subprogram is to be inlined.
3126 In addition for function subprograms we have:
3128 Etype Return type of the function.
3130 Each parameter is first checked by calling must_pass_by_ref on its
3131 type to determine if it is passed by reference. For parameters which
3132 are copied in, if they are Ada IN OUT or OUT parameters, their return
3133 value becomes part of a record which becomes the return type of the
3134 function (C function - note that this applies only to Ada procedures
3135 so there is no Ada return type). Additional code to store back the
3136 parameters will be generated on the caller side. This transformation
3137 is done here, not in the front-end.
3139 The intended result of the transformation can be seen from the
3140 equivalent source rewritings that follow:
3142 struct temp {int a,b};
3143 procedure P (A,B: IN OUT ...) is temp P (int A,B) {
3145 end P; return {A,B};
3155 For subprogram types we need to perform mainly the same conversions to
3156 GCC form that are needed for procedures and function declarations. The
3157 only difference is that at the end, we make a type declaration instead
3158 of a function declaration. */
3160 case E_Subprogram_Type
:
3164 /* The first GCC parameter declaration (a PARM_DECL node). The
3165 PARM_DECL nodes are chained through the TREE_CHAIN field, so this
3166 actually is the head of this parameter list. */
3167 tree gnu_param_list
= NULL_TREE
;
3168 /* The type returned by a function. If the subprogram is a procedure
3169 this type should be void_type_node. */
3170 tree gnu_return_type
= void_type_node
;
3171 /* List of fields in return type of procedure with copy in copy out
3173 tree gnu_field_list
= NULL_TREE
;
3174 /* Non-null for subprograms containing parameters passed by copy in
3175 copy out (Ada IN OUT or OUT parameters not passed by reference),
3176 in which case it is the list of nodes used to specify the values of
3177 the in out/out parameters that are returned as a record upon
3178 procedure return. The TREE_PURPOSE of an element of this list is
3179 a field of the record and the TREE_VALUE is the PARM_DECL
3180 corresponding to that field. This list will be saved in the
3181 TYPE_CI_CO_LIST field of the FUNCTION_TYPE node we create. */
3182 tree gnu_return_list
= NULL_TREE
;
3183 Entity_Id gnat_param
;
3184 int inline_flag
= Is_Inlined (gnat_entity
);
3185 int public_flag
= Is_Public (gnat_entity
);
3187 = (Is_Public (gnat_entity
) && !definition
) || imported_p
;
3188 int pure_flag
= Is_Pure (gnat_entity
);
3189 int volatile_flag
= No_Return (gnat_entity
);
3190 int returns_by_ref
= 0;
3191 int returns_unconstrained
= 0;
3192 tree gnu_ext_name
= create_concat_name (gnat_entity
, 0);
3193 int has_copy_in_out
= 0;
3196 if (kind
== E_Subprogram_Type
&& ! definition
)
3197 /* A parameter may refer to this type, so defer completion
3198 of any incomplete types. */
3199 defer_incomplete_level
++, this_deferred
= 1;
3201 /* If the subprogram has an alias, it is probably inherited, so
3202 we can use the original one. If the original "subprogram"
3203 is actually an enumeration literal, it may be the first use
3204 of its type, so we must elaborate that type now. */
3205 if (Present (Alias (gnat_entity
)))
3207 if (Ekind (Alias (gnat_entity
)) == E_Enumeration_Literal
)
3208 gnat_to_gnu_entity (Etype (Alias (gnat_entity
)), NULL_TREE
, 0);
3210 gnu_decl
= gnat_to_gnu_entity (Alias (gnat_entity
),
3213 /* Elaborate any Itypes in the parameters of this entity. */
3214 for (gnat_temp
= First_Formal (gnat_entity
);
3215 Present (gnat_temp
);
3216 gnat_temp
= Next_Formal_With_Extras (gnat_temp
))
3217 if (Is_Itype (Etype (gnat_temp
)))
3218 gnat_to_gnu_entity (Etype (gnat_temp
), NULL_TREE
, 0);
3223 if (kind
== E_Function
|| kind
== E_Subprogram_Type
)
3224 gnu_return_type
= gnat_to_gnu_type (Etype (gnat_entity
));
3226 /* If this function returns by reference, make the actual
3227 return type of this function the pointer and mark the decl. */
3228 if (Returns_By_Ref (gnat_entity
))
3231 gnu_return_type
= build_pointer_type (gnu_return_type
);
3234 /* If the Mechanism is By_Reference, ensure the return type uses
3235 the machine's by-reference mechanism, which may not the same
3236 as above (e.g., it might be by passing a fake parameter). */
3237 else if (kind
== E_Function
3238 && Mechanism (gnat_entity
) == By_Reference
)
3240 gnu_return_type
= copy_type (gnu_return_type
);
3241 TREE_ADDRESSABLE (gnu_return_type
) = 1;
3244 /* If we are supposed to return an unconstrained array,
3245 actually return a fat pointer and make a note of that. Return
3246 a pointer to an unconstrained record of variable size. */
3247 else if (TREE_CODE (gnu_return_type
) == UNCONSTRAINED_ARRAY_TYPE
)
3249 gnu_return_type
= TREE_TYPE (gnu_return_type
);
3250 returns_unconstrained
= 1;
3253 /* If the type requires a transient scope, the result is allocated
3254 on the secondary stack, so the result type of the function is
3256 else if (Requires_Transient_Scope (Etype (gnat_entity
)))
3258 gnu_return_type
= build_pointer_type (gnu_return_type
);
3259 returns_unconstrained
= 1;
3262 /* If the type is a padded type and the underlying type would not
3263 be passed by reference or this function has a foreign convention,
3264 return the underlying type. */
3265 else if (TREE_CODE (gnu_return_type
) == RECORD_TYPE
3266 && TYPE_IS_PADDING_P (gnu_return_type
)
3267 && (! default_pass_by_ref (TREE_TYPE
3268 (TYPE_FIELDS (gnu_return_type
)))
3269 || Has_Foreign_Convention (gnat_entity
)))
3270 gnu_return_type
= TREE_TYPE (TYPE_FIELDS (gnu_return_type
));
3272 /* Look at all our parameters and get the type of
3273 each. While doing this, build a copy-out structure if
3276 /* If the return type has a size that overflows, we cannot have
3277 a function that returns that type. This usage doesn't make
3278 sense anyway, so give an error here. */
3279 if (TYPE_SIZE_UNIT (gnu_return_type
)
3280 && TREE_OVERFLOW (TYPE_SIZE_UNIT (gnu_return_type
)))
3282 post_error ("cannot return type whose size overflows",
3284 gnu_return_type
= copy_node (gnu_return_type
);
3285 TYPE_SIZE (gnu_return_type
) = bitsize_zero_node
;
3286 TYPE_SIZE_UNIT (gnu_return_type
) = size_zero_node
;
3287 TYPE_MAIN_VARIANT (gnu_return_type
) = gnu_return_type
;
3288 TYPE_NEXT_VARIANT (gnu_return_type
) = 0;
3291 for (gnat_param
= First_Formal (gnat_entity
), parmnum
= 0;
3292 Present (gnat_param
);
3293 gnat_param
= Next_Formal_With_Extras (gnat_param
), parmnum
++)
3295 tree gnu_param_name
= get_entity_name (gnat_param
);
3296 tree gnu_param_type
= gnat_to_gnu_type (Etype (gnat_param
));
3297 tree gnu_param
, gnu_field
;
3300 int by_component_ptr_p
= 0;
3301 int copy_in_copy_out_flag
= 0;
3302 int req_by_copy
= 0, req_by_ref
= 0;
3304 /* See if a Mechanism was supplied that forced this
3305 parameter to be passed one way or another. */
3306 if (Is_Valued_Procedure (gnat_entity
) && parmnum
== 0)
3308 else if (Mechanism (gnat_param
) == Default
)
3310 else if (Mechanism (gnat_param
) == By_Copy
)
3312 else if (Mechanism (gnat_param
) == By_Reference
)
3314 else if (Mechanism (gnat_param
) <= By_Descriptor
)
3316 else if (Mechanism (gnat_param
) > 0)
3318 if (TREE_CODE (gnu_param_type
) == UNCONSTRAINED_ARRAY_TYPE
3319 || TREE_CODE (TYPE_SIZE (gnu_param_type
)) != INTEGER_CST
3320 || 0 < compare_tree_int (TYPE_SIZE (gnu_param_type
),
3321 Mechanism (gnat_param
)))
3327 post_error ("unsupported mechanism for&", gnat_param
);
3329 /* If this is either a foreign function or if the
3330 underlying type won't be passed by refererence, strip off
3331 possible padding type. */
3332 if (TREE_CODE (gnu_param_type
) == RECORD_TYPE
3333 && TYPE_IS_PADDING_P (gnu_param_type
)
3334 && (req_by_ref
|| Has_Foreign_Convention (gnat_entity
)
3335 || ! must_pass_by_ref (TREE_TYPE (TYPE_FIELDS
3336 (gnu_param_type
)))))
3337 gnu_param_type
= TREE_TYPE (TYPE_FIELDS (gnu_param_type
));
3339 /* If this is an IN parameter it is read-only, so make a variant
3340 of the type that is read-only.
3342 ??? However, if this is an unconstrained array, that type can
3343 be very complex. So skip it for now. Likewise for any other
3344 self-referential type. */
3345 if (Ekind (gnat_param
) == E_In_Parameter
3346 && TREE_CODE (gnu_param_type
) != UNCONSTRAINED_ARRAY_TYPE
3347 && ! (TYPE_SIZE (gnu_param_type
) != 0
3348 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_param_type
))))
3350 = build_qualified_type (gnu_param_type
,
3351 (TYPE_QUALS (gnu_param_type
)
3352 | TYPE_QUAL_CONST
));
3354 /* For foreign conventions, pass arrays as a pointer to the
3355 underlying type. First check for unconstrained array and get
3356 the underlying array. Then get the component type and build
3358 if (Has_Foreign_Convention (gnat_entity
)
3359 && TREE_CODE (gnu_param_type
) == UNCONSTRAINED_ARRAY_TYPE
)
3361 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS
3362 (TREE_TYPE (gnu_param_type
))));
3366 = build_pointer_type
3367 (build_vms_descriptor (gnu_param_type
,
3368 Mechanism (gnat_param
),
3371 else if (Has_Foreign_Convention (gnat_entity
)
3373 && TREE_CODE (gnu_param_type
) == ARRAY_TYPE
)
3375 /* Strip off any multi-dimensional entries, then strip
3376 off the last array to get the component type. */
3377 while (TREE_CODE (TREE_TYPE (gnu_param_type
)) == ARRAY_TYPE
3378 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_param_type
)))
3379 gnu_param_type
= TREE_TYPE (gnu_param_type
);
3381 by_component_ptr_p
= 1;
3382 gnu_param_type
= TREE_TYPE (gnu_param_type
);
3384 if (Ekind (gnat_param
) == E_In_Parameter
)
3386 = build_qualified_type (gnu_param_type
,
3387 (TYPE_QUALS (gnu_param_type
)
3388 | TYPE_QUAL_CONST
));
3390 gnu_param_type
= build_pointer_type (gnu_param_type
);
3393 /* Fat pointers are passed as thin pointers for foreign
3395 else if (Has_Foreign_Convention (gnat_entity
)
3396 && TYPE_FAT_POINTER_P (gnu_param_type
))
3398 = make_type_from_size (gnu_param_type
,
3399 size_int (POINTER_SIZE
), 0);
3401 /* If we must pass or were requested to pass by reference, do so.
3402 If we were requested to pass by copy, do so.
3403 Otherwise, for foreign conventions, pass all in out parameters
3404 or aggregates by reference. For COBOL and Fortran, pass
3405 all integer and FP types that way too. For Convention Ada,
3406 use the standard Ada default. */
3407 else if (must_pass_by_ref (gnu_param_type
) || req_by_ref
3409 && ((Has_Foreign_Convention (gnat_entity
)
3410 && (Ekind (gnat_param
) != E_In_Parameter
3411 || AGGREGATE_TYPE_P (gnu_param_type
)))
3412 || (((Convention (gnat_entity
)
3413 == Convention_Fortran
)
3414 || (Convention (gnat_entity
)
3415 == Convention_COBOL
))
3416 && (INTEGRAL_TYPE_P (gnu_param_type
)
3417 || FLOAT_TYPE_P (gnu_param_type
)))
3418 /* For convention Ada, see if we pass by reference
3420 || (! Has_Foreign_Convention (gnat_entity
)
3421 && default_pass_by_ref (gnu_param_type
)))))
3423 gnu_param_type
= build_reference_type (gnu_param_type
);
3427 else if (Ekind (gnat_param
) != E_In_Parameter
)
3428 copy_in_copy_out_flag
= 1;
3430 if (req_by_copy
&& (by_ref_p
|| by_component_ptr_p
))
3431 post_error ("?cannot pass & by copy", gnat_param
);
3433 /* If this is an OUT parameter that isn't passed by reference
3434 and isn't a pointer or aggregate, we don't make a PARM_DECL
3435 for it. Instead, it will be a VAR_DECL created when we process
3436 the procedure. For the special parameter of Valued_Procedure,
3439 An exception is made to cover the RM-6.4.1 rule requiring "by
3440 copy" out parameters with discriminants or implicit initial
3441 values to be handled like in out parameters. These type are
3442 normally built as aggregates, and hence passed by reference,
3443 except for some packed arrays which end up encoded in special
3446 The exception we need to make is then for packed arrays of
3447 records with discriminants or implicit initial values. We have
3448 no light/easy way to check for the latter case, so we merely
3449 check for packed arrays of records. This may lead to useless
3450 copy-in operations, but in very rare cases only, as these would
3451 be exceptions in a set of already exceptional situations. */
3452 if (Ekind (gnat_param
) == E_Out_Parameter
&& ! by_ref_p
3453 && ((Is_Valued_Procedure (gnat_entity
) && parmnum
== 0)
3455 && ! POINTER_TYPE_P (gnu_param_type
)
3456 && ! AGGREGATE_TYPE_P (gnu_param_type
)))
3457 && ! (Is_Array_Type (Etype (gnat_param
))
3458 && Is_Packed (Etype (gnat_param
))
3459 && Is_Composite_Type (Component_Type
3460 (Etype (gnat_param
)))))
3464 set_lineno (gnat_param
, 0);
3467 (gnu_param_name
, gnu_param_type
,
3468 by_ref_p
|| by_component_ptr_p
3469 || Ekind (gnat_param
) == E_In_Parameter
);
3471 DECL_BY_REF_P (gnu_param
) = by_ref_p
;
3472 DECL_BY_COMPONENT_PTR_P (gnu_param
) = by_component_ptr_p
;
3473 DECL_BY_DESCRIPTOR_P (gnu_param
) = by_descr_p
;
3474 DECL_POINTS_TO_READONLY_P (gnu_param
)
3475 = (Ekind (gnat_param
) == E_In_Parameter
3476 && (by_ref_p
|| by_component_ptr_p
));
3477 save_gnu_tree (gnat_param
, gnu_param
, 0);
3478 gnu_param_list
= chainon (gnu_param
, gnu_param_list
);
3480 /* If a parameter is a pointer, this function may modify
3481 memory through it and thus shouldn't be considered
3482 a pure function. Also, the memory may be modified
3483 between two calls, so they can't be CSE'ed. The latter
3484 case also handles by-ref parameters. */
3485 if (POINTER_TYPE_P (gnu_param_type
)
3486 || TYPE_FAT_POINTER_P (gnu_param_type
))
3490 if (copy_in_copy_out_flag
)
3492 if (! has_copy_in_out
)
3494 if (TREE_CODE (gnu_return_type
) != VOID_TYPE
)
3497 gnu_return_type
= make_node (RECORD_TYPE
);
3498 TYPE_NAME (gnu_return_type
) = get_identifier ("RETURN");
3499 has_copy_in_out
= 1;
3502 set_lineno (gnat_param
, 0);
3503 gnu_field
= create_field_decl (gnu_param_name
, gnu_param_type
,
3504 gnu_return_type
, 0, 0, 0, 0);
3505 TREE_CHAIN (gnu_field
) = gnu_field_list
;
3506 gnu_field_list
= gnu_field
;
3507 gnu_return_list
= tree_cons (gnu_field
, gnu_param
,
3512 /* Do not compute record for out parameters if subprogram is
3513 stubbed since structures are incomplete for the back-end. */
3514 if (gnu_field_list
!= 0
3515 && Convention (gnat_entity
) != Convention_Stubbed
)
3516 finish_record_type (gnu_return_type
, nreverse (gnu_field_list
),
3519 /* If we have a CICO list but it has only one entry, we convert
3520 this function into a function that simply returns that one
3522 if (list_length (gnu_return_list
) == 1)
3523 gnu_return_type
= TREE_TYPE (TREE_PURPOSE (gnu_return_list
));
3526 if (Convention (gnat_entity
) == Convention_Stdcall
)
3529 = (struct attrib
*) xmalloc (sizeof (struct attrib
));
3531 attr
->next
= attr_list
;
3532 attr
->type
= ATTR_MACHINE_ATTRIBUTE
;
3533 attr
->name
= get_identifier ("stdcall");
3534 attr
->arg
= NULL_TREE
;
3535 attr
->error_point
= gnat_entity
;
3540 /* Both lists ware built in reverse. */
3541 gnu_param_list
= nreverse (gnu_param_list
);
3542 gnu_return_list
= nreverse (gnu_return_list
);
3545 = create_subprog_type (gnu_return_type
, gnu_param_list
,
3546 gnu_return_list
, returns_unconstrained
,
3548 Function_Returns_With_DSP (gnat_entity
));
3550 /* ??? For now, don't consider nested functions pure. */
3551 if (! global_bindings_p ())
3554 /* A subprogram (something that doesn't return anything) shouldn't
3555 be considered Pure since there would be no reason for such a
3556 subprogram. Note that procedures with Out (or In Out) parameters
3557 have already been converted into a function with a return type. */
3558 if (TREE_CODE (gnu_return_type
) == VOID_TYPE
)
3562 = build_qualified_type (gnu_type
,
3563 (TYPE_QUALS (gnu_type
)
3564 | (TYPE_QUAL_CONST
* pure_flag
)
3565 | (TYPE_QUAL_VOLATILE
* volatile_flag
)));
3567 set_lineno (gnat_entity
, 0);
3569 /* If there was no specified Interface_Name and the external and
3570 internal names of the subprogram are the same, only use the
3571 internal name to allow disambiguation of nested subprograms. */
3572 if (No (Interface_Name (gnat_entity
)) && gnu_ext_name
== gnu_entity_id
)
3575 /* If we are defining the subprogram and it has an Address clause
3576 we must get the address expression from the saved GCC tree for the
3577 subprogram if it has a Freeze_Node. Otherwise, we elaborate
3578 the address expression here since the front-end has guaranteed
3579 in that case that the elaboration has no effects. If there is
3580 an Address clause and we are not defining the object, just
3581 make it a constant. */
3582 if (Present (Address_Clause (gnat_entity
)))
3584 tree gnu_address
= 0;
3588 = (present_gnu_tree (gnat_entity
)
3589 ? get_gnu_tree (gnat_entity
)
3590 : gnat_to_gnu (Expression (Address_Clause (gnat_entity
))));
3592 save_gnu_tree (gnat_entity
, NULL_TREE
, 0);
3594 gnu_type
= build_reference_type (gnu_type
);
3595 if (gnu_address
!= 0)
3596 gnu_address
= convert (gnu_type
, gnu_address
);
3599 = create_var_decl (gnu_entity_id
, gnu_ext_name
, gnu_type
,
3600 gnu_address
, 0, Is_Public (gnat_entity
),
3602 DECL_BY_REF_P (gnu_decl
) = 1;
3605 else if (kind
== E_Subprogram_Type
)
3606 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
3607 ! Comes_From_Source (gnat_entity
),
3611 gnu_decl
= create_subprog_decl (gnu_entity_id
, gnu_ext_name
,
3612 gnu_type
, gnu_param_list
,
3613 inline_flag
, public_flag
,
3614 extern_flag
, attr_list
);
3615 DECL_STUBBED_P (gnu_decl
)
3616 = Convention (gnat_entity
) == Convention_Stubbed
;
3621 case E_Incomplete_Type
:
3622 case E_Private_Type
:
3623 case E_Limited_Private_Type
:
3624 case E_Record_Type_With_Private
:
3625 case E_Private_Subtype
:
3626 case E_Limited_Private_Subtype
:
3627 case E_Record_Subtype_With_Private
:
3629 /* If this type does not have a full view in the unit we are
3630 compiling, then just get the type from its Etype. */
3631 if (No (Full_View (gnat_entity
)))
3633 /* If this is an incomplete type with no full view, it must
3634 be a Taft Amendement type, so just return a dummy type. */
3635 if (kind
== E_Incomplete_Type
)
3636 gnu_type
= make_dummy_type (gnat_entity
);
3638 else if (Present (Underlying_Full_View (gnat_entity
)))
3639 gnu_decl
= gnat_to_gnu_entity (Underlying_Full_View (gnat_entity
),
3643 gnu_decl
= gnat_to_gnu_entity (Etype (gnat_entity
),
3651 /* Otherwise, if we are not defining the type now, get the
3652 type from the full view. But always get the type from the full
3653 view for define on use types, since otherwise we won't see them! */
3655 else if (! definition
3656 || (Is_Itype (Full_View (gnat_entity
))
3657 && No (Freeze_Node (gnat_entity
)))
3658 || (Is_Itype (gnat_entity
)
3659 && No (Freeze_Node (Full_View (gnat_entity
)))))
3661 gnu_decl
= gnat_to_gnu_entity (Full_View (gnat_entity
),
3667 /* For incomplete types, make a dummy type entry which will be
3669 gnu_type
= make_dummy_type (gnat_entity
);
3671 /* Save this type as the full declaration's type so we can do any needed
3672 updates when we see it. */
3673 set_lineno (gnat_entity
, 0);
3674 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
3675 ! Comes_From_Source (gnat_entity
),
3677 save_gnu_tree (Full_View (gnat_entity
), gnu_decl
, 0);
3680 /* Simple class_wide types are always viewed as their root_type
3681 by Gigi unless an Equivalent_Type is specified. */
3682 case E_Class_Wide_Type
:
3683 if (Present (Equivalent_Type (gnat_entity
)))
3684 gnu_type
= gnat_to_gnu_type (Equivalent_Type (gnat_entity
));
3686 gnu_type
= gnat_to_gnu_type (Root_Type (gnat_entity
));
3692 case E_Task_Subtype
:
3693 case E_Protected_Type
:
3694 case E_Protected_Subtype
:
3695 if (type_annotate_only
&& No (Corresponding_Record_Type (gnat_entity
)))
3696 gnu_type
= void_type_node
;
3698 gnu_type
= gnat_to_gnu_type (Corresponding_Record_Type (gnat_entity
));
3704 gnu_decl
= create_label_decl (gnu_entity_id
);
3709 /* Nothing at all to do here, so just return an ERROR_MARK and claim
3710 we've already saved it, so we don't try to. */
3711 gnu_decl
= error_mark_node
;
3719 /* If we had a case where we evaluated another type and it might have
3720 defined this one, handle it here. */
3721 if (maybe_present
&& present_gnu_tree (gnat_entity
))
3723 gnu_decl
= get_gnu_tree (gnat_entity
);
3727 /* If we are processing a type and there is either no decl for it or
3728 we just made one, do some common processing for the type, such as
3729 handling alignment and possible padding. */
3731 if ((gnu_decl
== 0 || this_made_decl
) && IN (kind
, Type_Kind
))
3733 if (Is_Tagged_Type (gnat_entity
)
3734 || Is_Class_Wide_Equivalent_Type (gnat_entity
))
3735 TYPE_ALIGN_OK (gnu_type
) = 1;
3737 if (AGGREGATE_TYPE_P (gnu_type
) && Is_By_Reference_Type (gnat_entity
))
3738 TYPE_BY_REFERENCE_P (gnu_type
) = 1;
3740 /* ??? Don't set the size for a String_Literal since it is either
3741 confirming or we don't handle it properly (if the low bound is
3743 if (gnu_size
== 0 && kind
!= E_String_Literal_Subtype
)
3744 gnu_size
= validate_size (Esize (gnat_entity
), gnu_type
, gnat_entity
,
3745 TYPE_DECL
, 0, Has_Size_Clause (gnat_entity
));
3747 /* If a size was specified, see if we can make a new type of that size
3748 by rearranging the type, for example from a fat to a thin pointer. */
3752 = make_type_from_size (gnu_type
, gnu_size
,
3753 Has_Biased_Representation (gnat_entity
));
3755 if (operand_equal_p (TYPE_SIZE (gnu_type
), gnu_size
, 0)
3756 && operand_equal_p (rm_size (gnu_type
), gnu_size
, 0))
3760 /* If the alignment hasn't already been processed and this is
3761 not an unconstrained array, see if an alignment is specified.
3762 If not, we pick a default alignment for atomic objects. */
3763 if (align
!= 0 || TREE_CODE (gnu_type
) == UNCONSTRAINED_ARRAY_TYPE
)
3765 else if (Known_Alignment (gnat_entity
))
3766 align
= validate_alignment (Alignment (gnat_entity
), gnat_entity
,
3767 TYPE_ALIGN (gnu_type
));
3768 else if (Is_Atomic (gnat_entity
) && gnu_size
== 0
3769 && host_integerp (TYPE_SIZE (gnu_type
), 1)
3770 && integer_pow2p (TYPE_SIZE (gnu_type
)))
3771 align
= MIN (BIGGEST_ALIGNMENT
,
3772 tree_low_cst (TYPE_SIZE (gnu_type
), 1));
3773 else if (Is_Atomic (gnat_entity
) && gnu_size
!= 0
3774 && host_integerp (gnu_size
, 1)
3775 && integer_pow2p (gnu_size
))
3776 align
= MIN (BIGGEST_ALIGNMENT
, tree_low_cst (gnu_size
, 1));
3778 /* See if we need to pad the type. If we did, and made a record,
3779 the name of the new type may be changed. So get it back for
3780 us when we make the new TYPE_DECL below. */
3781 gnu_type
= maybe_pad_type (gnu_type
, gnu_size
, align
,
3782 gnat_entity
, "PAD", 1, definition
, 0);
3783 if (TREE_CODE (gnu_type
) == RECORD_TYPE
3784 && TYPE_IS_PADDING_P (gnu_type
))
3786 gnu_entity_id
= TYPE_NAME (gnu_type
);
3787 if (TREE_CODE (gnu_entity_id
) == TYPE_DECL
)
3788 gnu_entity_id
= DECL_NAME (gnu_entity_id
);
3791 set_rm_size (RM_Size (gnat_entity
), gnu_type
, gnat_entity
);
3793 /* If we are at global level, GCC will have applied variable_size to
3794 the type, but that won't have done anything. So, if it's not
3795 a constant or self-referential, call elaborate_expression_1 to
3796 make a variable for the size rather than calculating it each time.
3797 Handle both the RM size and the actual size. */
3798 if (global_bindings_p ()
3799 && TYPE_SIZE (gnu_type
) != 0
3800 && ! TREE_CONSTANT (TYPE_SIZE (gnu_type
))
3801 && ! CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type
)))
3803 if (TREE_CODE (gnu_type
) == RECORD_TYPE
3804 && operand_equal_p (TYPE_ADA_SIZE (gnu_type
),
3805 TYPE_SIZE (gnu_type
), 0))
3807 TYPE_SIZE (gnu_type
)
3808 = elaborate_expression_1 (gnat_entity
, gnat_entity
,
3809 TYPE_SIZE (gnu_type
),
3810 get_identifier ("SIZE"),
3812 SET_TYPE_ADA_SIZE (gnu_type
, TYPE_SIZE (gnu_type
));
3816 TYPE_SIZE (gnu_type
)
3817 = elaborate_expression_1 (gnat_entity
, gnat_entity
,
3818 TYPE_SIZE (gnu_type
),
3819 get_identifier ("SIZE"),
3822 /* ??? For now, store the size as a multiple of the alignment
3823 in bytes so that we can see the alignment from the tree. */
3824 TYPE_SIZE_UNIT (gnu_type
)
3826 (MULT_EXPR
, sizetype
,
3827 elaborate_expression_1
3828 (gnat_entity
, gnat_entity
,
3829 build_binary_op (EXACT_DIV_EXPR
, sizetype
,
3830 TYPE_SIZE_UNIT (gnu_type
),
3831 size_int (TYPE_ALIGN (gnu_type
)
3833 get_identifier ("SIZE_A_UNIT"),
3835 size_int (TYPE_ALIGN (gnu_type
) / BITS_PER_UNIT
));
3837 if (TREE_CODE (gnu_type
) == RECORD_TYPE
)
3838 SET_TYPE_ADA_SIZE (gnu_type
,
3839 elaborate_expression_1 (gnat_entity
, gnat_entity
,
3840 TYPE_ADA_SIZE (gnu_type
),
3841 get_identifier ("RM_SIZE"),
3846 /* If this is a record type or subtype, call elaborate_expression_1 on
3847 any field position. Do this for both global and local types.
3848 Skip any fields that we haven't made trees for to avoid problems with
3849 class wide types. */
3850 if (IN (kind
, Record_Kind
))
3851 for (gnat_temp
= First_Entity (gnat_entity
); Present (gnat_temp
);
3852 gnat_temp
= Next_Entity (gnat_temp
))
3853 if (Ekind (gnat_temp
) == E_Component
&& present_gnu_tree (gnat_temp
))
3855 tree gnu_field
= get_gnu_tree (gnat_temp
);
3857 /* ??? Unfortunately, GCC needs to be able to prove the
3858 alignment of this offset and if it's a variable, it can't.
3859 In GCC 3.4, we'll use DECL_OFFSET_ALIGN in some way, but
3860 right now, we have to put in an explicit multiply and
3861 divide by that value. */
3862 if (! CONTAINS_PLACEHOLDER_P (DECL_FIELD_OFFSET (gnu_field
)))
3863 DECL_FIELD_OFFSET (gnu_field
)
3865 (MULT_EXPR
, sizetype
,
3866 elaborate_expression_1
3867 (gnat_temp
, gnat_temp
,
3868 build_binary_op (EXACT_DIV_EXPR
, sizetype
,
3869 DECL_FIELD_OFFSET (gnu_field
),
3870 size_int (DECL_OFFSET_ALIGN (gnu_field
)
3872 get_identifier ("OFFSET"),
3874 size_int (DECL_OFFSET_ALIGN (gnu_field
) / BITS_PER_UNIT
));
3877 gnu_type
= build_qualified_type (gnu_type
,
3878 (TYPE_QUALS (gnu_type
)
3879 | (TYPE_QUAL_VOLATILE
3880 * Treat_As_Volatile (gnat_entity
))));
3882 if (Is_Atomic (gnat_entity
))
3883 check_ok_for_atomic (gnu_type
, gnat_entity
, 0);
3885 if (Known_Alignment (gnat_entity
))
3886 TYPE_USER_ALIGN (gnu_type
) = 1;
3890 set_lineno (gnat_entity
, 0);
3891 gnu_decl
= create_type_decl (gnu_entity_id
, gnu_type
, attr_list
,
3892 ! Comes_From_Source (gnat_entity
),
3896 TREE_TYPE (gnu_decl
) = gnu_type
;
3899 if (IN (kind
, Type_Kind
) && ! TYPE_IS_DUMMY_P (TREE_TYPE (gnu_decl
)))
3901 gnu_type
= TREE_TYPE (gnu_decl
);
3903 /* Back-annotate the Alignment of the type if not already in the
3904 tree. Likewise for sizes. */
3905 if (Unknown_Alignment (gnat_entity
))
3906 Set_Alignment (gnat_entity
,
3907 UI_From_Int (TYPE_ALIGN (gnu_type
) / BITS_PER_UNIT
));
3909 if (Unknown_Esize (gnat_entity
) && TYPE_SIZE (gnu_type
) != 0)
3911 /* If the size is self-referential, we annotate the maximum
3912 value of that size. */
3913 tree gnu_size
= TYPE_SIZE (gnu_type
);
3915 if (CONTAINS_PLACEHOLDER_P (gnu_size
))
3916 gnu_size
= max_size (gnu_size
, 1);
3918 Set_Esize (gnat_entity
, annotate_value (gnu_size
));
3920 if (type_annotate_only
&& Is_Tagged_Type (gnat_entity
))
3922 /* In this mode the tag and the parent components are not
3923 generated by the front-end, so the sizes must be adjusted
3929 if (Is_Derived_Type (gnat_entity
))
3932 = UI_To_Int (Esize (Etype (Base_Type (gnat_entity
))));
3933 Set_Alignment (gnat_entity
,
3934 Alignment (Etype (Base_Type (gnat_entity
))));
3937 size_offset
= POINTER_SIZE
;
3939 new_size
= UI_To_Int (Esize (gnat_entity
)) + size_offset
;
3940 Set_Esize (gnat_entity
,
3941 UI_From_Int (((new_size
+ (POINTER_SIZE
- 1))
3942 / POINTER_SIZE
) * POINTER_SIZE
));
3943 Set_RM_Size (gnat_entity
, Esize (gnat_entity
));
3947 if (Unknown_RM_Size (gnat_entity
) && rm_size (gnu_type
) != 0)
3948 Set_RM_Size (gnat_entity
, annotate_value (rm_size (gnu_type
)));
3951 if (! Comes_From_Source (gnat_entity
) && DECL_P (gnu_decl
))
3952 DECL_ARTIFICIAL (gnu_decl
) = 1;
3954 if (! debug_info_p
&& DECL_P (gnu_decl
)
3955 && TREE_CODE (gnu_decl
) != FUNCTION_DECL
)
3956 DECL_IGNORED_P (gnu_decl
) = 1;
3958 /* If this decl is really indirect, adjust it. */
3959 if (TREE_CODE (gnu_decl
) == VAR_DECL
)
3960 adjust_decl_rtl (gnu_decl
);
3962 /* If we haven't already, associate the ..._DECL node that we just made with
3963 the input GNAT entity node. */
3965 save_gnu_tree (gnat_entity
, gnu_decl
, 0);
3967 /* If this is an enumeral or floating-point type, we were not able to set
3968 the bounds since they refer to the type. These bounds are always static.
3970 For enumeration types, also write debugging information and declare the
3971 enumeration literal table, if needed. */
3973 if ((kind
== E_Enumeration_Type
&& Present (First_Literal (gnat_entity
)))
3974 || (kind
== E_Floating_Point_Type
&& ! Vax_Float (gnat_entity
)))
3976 tree gnu_scalar_type
= gnu_type
;
3978 /* If this is a padded type, we need to use the underlying type. */
3979 if (TREE_CODE (gnu_scalar_type
) == RECORD_TYPE
3980 && TYPE_IS_PADDING_P (gnu_scalar_type
))
3981 gnu_scalar_type
= TREE_TYPE (TYPE_FIELDS (gnu_scalar_type
));
3983 /* If this is a floating point type and we haven't set a floating
3984 point type yet, use this in the evaluation of the bounds. */
3985 if (longest_float_type_node
== 0 && kind
== E_Floating_Point_Type
)
3986 longest_float_type_node
= gnu_type
;
3988 TYPE_MIN_VALUE (gnu_scalar_type
)
3989 = gnat_to_gnu (Type_Low_Bound (gnat_entity
));
3990 TYPE_MAX_VALUE (gnu_scalar_type
)
3991 = gnat_to_gnu (Type_High_Bound (gnat_entity
));
3993 if (kind
== E_Enumeration_Type
)
3995 TYPE_STUB_DECL (gnu_scalar_type
) = gnu_decl
;
3997 /* Since this has both a typedef and a tag, avoid outputting
3999 DECL_ARTIFICIAL (gnu_decl
) = 1;
4000 rest_of_type_compilation (gnu_scalar_type
, global_bindings_p ());
4004 /* If we deferred processing of incomplete types, re-enable it. If there
4005 were no other disables and we have some to process, do so. */
4006 if (this_deferred
&& --defer_incomplete_level
== 0
4007 && defer_incomplete_list
!= 0)
4009 struct incomplete
*incp
= defer_incomplete_list
;
4010 struct incomplete
*next
;
4012 defer_incomplete_list
= 0;
4013 for (; incp
; incp
= next
)
4017 if (incp
->old_type
!= 0)
4018 update_pointer_to (TYPE_MAIN_VARIANT (incp
->old_type
),
4019 gnat_to_gnu_type (incp
->full_type
));
4024 /* If we are not defining this type, see if it's in the incomplete list.
4025 If so, handle that list entry now. */
4026 else if (! definition
)
4028 struct incomplete
*incp
;
4030 for (incp
= defer_incomplete_list
; incp
; incp
= incp
->next
)
4031 if (incp
->old_type
!= 0 && incp
->full_type
== gnat_entity
)
4033 update_pointer_to (TYPE_MAIN_VARIANT (incp
->old_type
),
4034 TREE_TYPE (gnu_decl
));
4042 if (Is_Packed_Array_Type (gnat_entity
)
4043 && Is_Itype (Associated_Node_For_Itype (gnat_entity
))
4044 && No (Freeze_Node (Associated_Node_For_Itype (gnat_entity
)))
4045 && ! present_gnu_tree (Associated_Node_For_Itype (gnat_entity
)))
4046 gnat_to_gnu_entity (Associated_Node_For_Itype (gnat_entity
), NULL_TREE
, 0);
4051 /* Given GNAT_ENTITY, elaborate all expressions that are required to
4052 be elaborated at the point of its definition, but do nothing else. */
4055 elaborate_entity (Entity_Id gnat_entity
)
4057 switch (Ekind (gnat_entity
))
4059 case E_Signed_Integer_Subtype
:
4060 case E_Modular_Integer_Subtype
:
4061 case E_Enumeration_Subtype
:
4062 case E_Ordinary_Fixed_Point_Subtype
:
4063 case E_Decimal_Fixed_Point_Subtype
:
4064 case E_Floating_Point_Subtype
:
4066 Node_Id gnat_lb
= Type_Low_Bound (gnat_entity
);
4067 Node_Id gnat_hb
= Type_High_Bound (gnat_entity
);
4069 /* ??? Tests for avoiding static constaint error expression
4070 is needed until the front stops generating bogus conversions
4071 on bounds of real types. */
4073 if (! Raises_Constraint_Error (gnat_lb
))
4074 elaborate_expression (gnat_lb
, gnat_entity
, get_identifier ("L"),
4075 1, 0, Needs_Debug_Info (gnat_entity
));
4076 if (! Raises_Constraint_Error (gnat_hb
))
4077 elaborate_expression (gnat_hb
, gnat_entity
, get_identifier ("U"),
4078 1, 0, Needs_Debug_Info (gnat_entity
));
4084 Node_Id full_definition
= Declaration_Node (gnat_entity
);
4085 Node_Id record_definition
= Type_Definition (full_definition
);
4087 /* If this is a record extension, go a level further to find the
4088 record definition. */
4089 if (Nkind (record_definition
) == N_Derived_Type_Definition
)
4090 record_definition
= Record_Extension_Part (record_definition
);
4094 case E_Record_Subtype
:
4095 case E_Private_Subtype
:
4096 case E_Limited_Private_Subtype
:
4097 case E_Record_Subtype_With_Private
:
4098 if (Is_Constrained (gnat_entity
)
4099 && Has_Discriminants (Base_Type (gnat_entity
))
4100 && Present (Discriminant_Constraint (gnat_entity
)))
4102 Node_Id gnat_discriminant_expr
;
4103 Entity_Id gnat_field
;
4105 for (gnat_field
= First_Discriminant (Base_Type (gnat_entity
)),
4106 gnat_discriminant_expr
4107 = First_Elmt (Discriminant_Constraint (gnat_entity
));
4108 Present (gnat_field
);
4109 gnat_field
= Next_Discriminant (gnat_field
),
4110 gnat_discriminant_expr
= Next_Elmt (gnat_discriminant_expr
))
4111 /* ??? For now, ignore access discriminants. */
4112 if (! Is_Access_Type (Etype (Node (gnat_discriminant_expr
))))
4113 elaborate_expression (Node (gnat_discriminant_expr
),
4115 get_entity_name (gnat_field
), 1, 0, 0);
4122 /* Mark GNAT_ENTITY as going out of scope at this point. Recursively mark
4123 any entities on its entity chain similarly. */
4126 mark_out_of_scope (Entity_Id gnat_entity
)
4128 Entity_Id gnat_sub_entity
;
4129 unsigned int kind
= Ekind (gnat_entity
);
4131 /* If this has an entity list, process all in the list. */
4132 if (IN (kind
, Class_Wide_Kind
) || IN (kind
, Concurrent_Kind
)
4133 || IN (kind
, Private_Kind
)
4134 || kind
== E_Block
|| kind
== E_Entry
|| kind
== E_Entry_Family
4135 || kind
== E_Function
|| kind
== E_Generic_Function
4136 || kind
== E_Generic_Package
|| kind
== E_Generic_Procedure
4137 || kind
== E_Loop
|| kind
== E_Operator
|| kind
== E_Package
4138 || kind
== E_Package_Body
|| kind
== E_Procedure
4139 || kind
== E_Record_Type
|| kind
== E_Record_Subtype
4140 || kind
== E_Subprogram_Body
|| kind
== E_Subprogram_Type
)
4141 for (gnat_sub_entity
= First_Entity (gnat_entity
);
4142 Present (gnat_sub_entity
);
4143 gnat_sub_entity
= Next_Entity (gnat_sub_entity
))
4144 if (Scope (gnat_sub_entity
) == gnat_entity
4145 && gnat_sub_entity
!= gnat_entity
)
4146 mark_out_of_scope (gnat_sub_entity
);
4148 /* Now clear this if it has been defined, but only do so if it isn't
4149 a subprogram or parameter. We could refine this, but it isn't
4150 worth it. If this is statically allocated, it is supposed to
4151 hang around out of cope. */
4152 if (present_gnu_tree (gnat_entity
) && ! Is_Statically_Allocated (gnat_entity
)
4153 && kind
!= E_Procedure
&& kind
!= E_Function
&& ! IN (kind
, Formal_Kind
))
4155 save_gnu_tree (gnat_entity
, NULL_TREE
, 1);
4156 save_gnu_tree (gnat_entity
, error_mark_node
, 1);
4160 /* Set the alias set of GNU_NEW_TYPE to be that of GNU_OLD_TYPE. If this
4161 is a multi-dimensional array type, do this recursively. */
4164 copy_alias_set (tree gnu_new_type
, tree gnu_old_type
)
4166 if (TREE_CODE (gnu_new_type
) == ARRAY_TYPE
4167 && TREE_CODE (TREE_TYPE (gnu_new_type
)) == ARRAY_TYPE
4168 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_new_type
)))
4170 /* We need to be careful here in case GNU_OLD_TYPE is an unconstrained
4171 array. In that case, it doesn't have the same shape as GNU_NEW_TYPE,
4172 so we need to go down to what does. */
4173 if (TREE_CODE (gnu_old_type
) == UNCONSTRAINED_ARRAY_TYPE
)
4175 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_old_type
))));
4177 copy_alias_set (TREE_TYPE (gnu_new_type
), TREE_TYPE (gnu_old_type
));
4180 TYPE_ALIAS_SET (gnu_new_type
) = get_alias_set (gnu_old_type
);
4181 record_component_aliases (gnu_new_type
);
4184 /* Return a TREE_LIST describing the substitutions needed to reflect
4185 discriminant substitutions from GNAT_SUBTYPE to GNAT_TYPE and add
4186 them to GNU_LIST. If GNAT_TYPE is not specified, use the base type
4187 of GNAT_SUBTYPE. The substitions can be in any order. TREE_PURPOSE
4188 gives the tree for the discriminant and TREE_VALUES is the replacement
4189 value. They are in the form of operands to substitute_in_expr.
4190 DEFINITION is as in gnat_to_gnu_entity. */
4193 substitution_list (Entity_Id gnat_subtype
,
4194 Entity_Id gnat_type
,
4198 Entity_Id gnat_discrim
;
4202 gnat_type
= Implementation_Base_Type (gnat_subtype
);
4204 if (Has_Discriminants (gnat_type
))
4205 for (gnat_discrim
= First_Stored_Discriminant (gnat_type
),
4206 gnat_value
= First_Elmt (Stored_Constraint (gnat_subtype
));
4207 Present (gnat_discrim
);
4208 gnat_discrim
= Next_Stored_Discriminant (gnat_discrim
),
4209 gnat_value
= Next_Elmt (gnat_value
))
4210 /* Ignore access discriminants. */
4211 if (! Is_Access_Type (Etype (Node (gnat_value
))))
4212 gnu_list
= tree_cons (gnat_to_gnu_entity (gnat_discrim
, NULL_TREE
, 0),
4213 elaborate_expression
4214 (Node (gnat_value
), gnat_subtype
,
4215 get_entity_name (gnat_discrim
), definition
,
4222 /* For the following two functions: for each GNAT entity, the GCC
4223 tree node used as a dummy for that entity, if any. */
4225 static GTY((length ("max_gnat_nodes"))) tree
* dummy_node_table
;
4227 /* Initialize the above table. */
4230 init_dummy_type (void)
4234 dummy_node_table
= (tree
*) ggc_alloc (max_gnat_nodes
* sizeof (tree
));
4236 for (gnat_node
= 0; gnat_node
< max_gnat_nodes
; gnat_node
++)
4237 dummy_node_table
[gnat_node
] = NULL_TREE
;
4239 dummy_node_table
-= First_Node_Id
;
4242 /* Make a dummy type corresponding to GNAT_TYPE. */
4245 make_dummy_type (Entity_Id gnat_type
)
4247 Entity_Id gnat_underlying
;
4250 /* Find a full type for GNAT_TYPE, taking into account any class wide
4252 if (Is_Class_Wide_Type (gnat_type
) && Present (Equivalent_Type (gnat_type
)))
4253 gnat_type
= Equivalent_Type (gnat_type
);
4254 else if (Ekind (gnat_type
) == E_Class_Wide_Type
)
4255 gnat_type
= Root_Type (gnat_type
);
4257 for (gnat_underlying
= gnat_type
;
4258 (IN (Ekind (gnat_underlying
), Incomplete_Or_Private_Kind
)
4259 && Present (Full_View (gnat_underlying
)));
4260 gnat_underlying
= Full_View (gnat_underlying
))
4263 /* If it there already a dummy type, use that one. Else make one. */
4264 if (dummy_node_table
[gnat_underlying
])
4265 return dummy_node_table
[gnat_underlying
];
4267 /* If this is a record, make this a RECORD_TYPE or UNION_TYPE; else make
4269 if (Is_Record_Type (gnat_underlying
))
4270 gnu_type
= make_node (Is_Unchecked_Union (gnat_underlying
)
4271 ? UNION_TYPE
: RECORD_TYPE
);
4273 gnu_type
= make_node (ENUMERAL_TYPE
);
4275 TYPE_NAME (gnu_type
) = get_entity_name (gnat_type
);
4276 if (AGGREGATE_TYPE_P (gnu_type
))
4277 TYPE_STUB_DECL (gnu_type
)
4278 = pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, gnu_type
));
4280 TYPE_DUMMY_P (gnu_type
) = 1;
4281 dummy_node_table
[gnat_underlying
] = gnu_type
;
4286 /* Return 1 if the size represented by GNU_SIZE can be handled by an
4287 allocation. If STATIC_P is non-zero, consider only what can be
4288 done with a static allocation. */
4291 allocatable_size_p (tree gnu_size
, int static_p
)
4293 HOST_WIDE_INT our_size
;
4295 /* If this is not a static allocation, the only case we want to forbid
4296 is an overflowing size. That will be converted into a raise a
4299 return ! (TREE_CODE (gnu_size
) == INTEGER_CST
4300 && TREE_CONSTANT_OVERFLOW (gnu_size
));
4302 /* Otherwise, we need to deal with both variable sizes and constant
4303 sizes that won't fit in a host int. We use int instead of HOST_WIDE_INT
4304 since assemblers may not like very large sizes. */
4305 if (!host_integerp (gnu_size
, 1))
4308 our_size
= tree_low_cst (gnu_size
, 1);
4309 return (int) our_size
== our_size
;
4312 /* Return a list of attributes for GNAT_ENTITY, if any. */
4314 static struct attrib
*
4315 build_attr_list (Entity_Id gnat_entity
)
4317 struct attrib
*attr_list
= 0;
4320 for (gnat_temp
= First_Rep_Item (gnat_entity
); Present (gnat_temp
);
4321 gnat_temp
= Next_Rep_Item (gnat_temp
))
4322 if (Nkind (gnat_temp
) == N_Pragma
)
4324 struct attrib
*attr
;
4325 tree gnu_arg0
= 0, gnu_arg1
= 0;
4326 Node_Id gnat_assoc
= Pragma_Argument_Associations (gnat_temp
);
4327 enum attr_type etype
;
4329 if (Present (gnat_assoc
) && Present (First (gnat_assoc
))
4330 && Present (Next (First (gnat_assoc
)))
4331 && (Nkind (Expression (Next (First (gnat_assoc
))))
4332 == N_String_Literal
))
4334 gnu_arg0
= get_identifier (TREE_STRING_POINTER
4337 (First (gnat_assoc
))))));
4338 if (Present (Next (Next (First (gnat_assoc
))))
4339 && (Nkind (Expression (Next (Next (First (gnat_assoc
)))))
4340 == N_String_Literal
))
4341 gnu_arg1
= get_identifier (TREE_STRING_POINTER
4345 (First (gnat_assoc
)))))));
4348 switch (Get_Pragma_Id (Chars (gnat_temp
)))
4350 case Pragma_Machine_Attribute
:
4351 etype
= ATTR_MACHINE_ATTRIBUTE
;
4354 case Pragma_Linker_Alias
:
4355 etype
= ATTR_LINK_ALIAS
;
4358 case Pragma_Linker_Section
:
4359 etype
= ATTR_LINK_SECTION
;
4362 case Pragma_Weak_External
:
4363 etype
= ATTR_WEAK_EXTERNAL
;
4370 attr
= (struct attrib
*) xmalloc (sizeof (struct attrib
));
4371 attr
->next
= attr_list
;
4373 attr
->name
= gnu_arg0
;
4374 attr
->arg
= gnu_arg1
;
4376 = Present (Next (First (gnat_assoc
)))
4377 ? Expression (Next (First (gnat_assoc
))) : gnat_temp
;
4384 /* Get the unpadded version of a GNAT type. */
4387 get_unpadded_type (Entity_Id gnat_entity
)
4389 tree type
= gnat_to_gnu_type (gnat_entity
);
4391 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_IS_PADDING_P (type
))
4392 type
= TREE_TYPE (TYPE_FIELDS (type
));
4397 /* Called when we need to protect a variable object using a save_expr. */
4400 maybe_variable (tree gnu_operand
, Node_Id gnat_node
)
4402 if (TREE_CONSTANT (gnu_operand
) || TREE_READONLY (gnu_operand
)
4403 || TREE_CODE (gnu_operand
) == SAVE_EXPR
4404 || TREE_CODE (gnu_operand
) == NULL_EXPR
)
4407 /* If we will be generating code, make sure we are at the proper
4409 if (! global_bindings_p () && ! CONTAINS_PLACEHOLDER_P (gnu_operand
))
4410 set_lineno (gnat_node
, 1);
4412 if (TREE_CODE (gnu_operand
) == UNCONSTRAINED_ARRAY_REF
)
4414 tree gnu_result
= build1 (UNCONSTRAINED_ARRAY_REF
,
4415 TREE_TYPE (gnu_operand
),
4416 variable_size (TREE_OPERAND (gnu_operand
, 0)));
4418 TREE_READONLY (gnu_result
) = TREE_STATIC (gnu_result
)
4419 = TYPE_READONLY (TREE_TYPE (TREE_TYPE (gnu_operand
)));
4423 return variable_size (gnu_operand
);
4426 /* Given a GNAT tree GNAT_EXPR, for an expression which is a value within a
4427 type definition (either a bound or a discriminant value) for GNAT_ENTITY,
4428 return the GCC tree to use for that expression. GNU_NAME is the
4429 qualification to use if an external name is appropriate and DEFINITION is
4430 nonzero if this is a definition of GNAT_ENTITY. If NEED_VALUE is nonzero,
4431 we need a result. Otherwise, we are just elaborating this for
4432 side-effects. If NEED_DEBUG is nonzero we need the symbol for debugging
4433 purposes even if it isn't needed for code generation. */
4436 elaborate_expression (Node_Id gnat_expr
,
4437 Entity_Id gnat_entity
,
4445 /* If we already elaborated this expression (e.g., it was involved
4446 in the definition of a private type), use the old value. */
4447 if (present_gnu_tree (gnat_expr
))
4448 return get_gnu_tree (gnat_expr
);
4450 /* If we don't need a value and this is static or a discriment, we
4451 don't need to do anything. */
4452 else if (! need_value
4453 && (Is_OK_Static_Expression (gnat_expr
)
4454 || (Nkind (gnat_expr
) == N_Identifier
4455 && Ekind (Entity (gnat_expr
)) == E_Discriminant
)))
4458 /* Otherwise, convert this tree to its GCC equivalant. */
4460 = elaborate_expression_1 (gnat_expr
, gnat_entity
, gnat_to_gnu (gnat_expr
),
4461 gnu_name
, definition
, need_debug
);
4463 /* Save the expression in case we try to elaborate this entity again.
4464 Since this is not a DECL, don't check it. If this is a constant,
4465 don't save it since GNAT_EXPR might be used more than once. Also,
4466 don't save if it's a discriminant. */
4467 if (! CONTAINS_PLACEHOLDER_P (gnu_expr
))
4468 save_gnu_tree (gnat_expr
, gnu_expr
, 1);
4470 return need_value
? gnu_expr
: error_mark_node
;
4473 /* Similar, but take a GNU expression. */
4476 elaborate_expression_1 (Node_Id gnat_expr
,
4477 Entity_Id gnat_entity
,
4484 /* Strip any conversions to see if the expression is a readonly variable.
4485 ??? This really should remain readonly, but we have to think about
4486 the typing of the tree here. */
4487 tree gnu_inner_expr
= remove_conversions (gnu_expr
, 1);
4488 int expr_global
= Is_Public (gnat_entity
) || global_bindings_p ();
4491 /* In most cases, we won't see a naked FIELD_DECL here because a
4492 discriminant reference will have been replaced with a COMPONENT_REF
4493 when the type is being elaborated. However, there are some cases
4494 involving child types where we will. So convert it to a COMPONENT_REF
4495 here. We have to hope it will be at the highest level of the
4496 expression in these cases. */
4497 if (TREE_CODE (gnu_expr
) == FIELD_DECL
)
4498 gnu_expr
= build (COMPONENT_REF
, TREE_TYPE (gnu_expr
),
4499 build (PLACEHOLDER_EXPR
, DECL_CONTEXT (gnu_expr
)),
4502 /* If GNU_EXPR is neither a placeholder nor a constant, nor a variable
4503 that is a constant, make a variable that is initialized to contain the
4504 bound when the package containing the definition is elaborated. If
4505 this entity is defined at top level and a bound or discriminant value
4506 isn't a constant or a reference to a discriminant, replace the bound
4507 by the variable; otherwise use a SAVE_EXPR if needed. Note that we
4508 rely here on the fact that an expression cannot contain both the
4509 discriminant and some other variable. */
4511 expr_variable
= (TREE_CODE_CLASS (TREE_CODE (gnu_expr
)) != 'c'
4512 && ! (TREE_CODE (gnu_inner_expr
) == VAR_DECL
4513 && TREE_READONLY (gnu_inner_expr
))
4514 && ! CONTAINS_PLACEHOLDER_P (gnu_expr
));
4516 /* If this is a static expression or contains a discriminant, we don't
4517 need the variable for debugging (and can't elaborate anyway if a
4520 && (Is_OK_Static_Expression (gnat_expr
)
4521 || CONTAINS_PLACEHOLDER_P (gnu_expr
)))
4524 /* Now create the variable if we need it. */
4525 if (need_debug
|| (expr_variable
&& expr_global
))
4527 set_lineno (gnat_entity
, ! global_bindings_p ());
4529 = create_var_decl (create_concat_name (gnat_entity
,
4530 IDENTIFIER_POINTER (gnu_name
)),
4531 NULL_TREE
, TREE_TYPE (gnu_expr
), gnu_expr
, 1,
4532 Is_Public (gnat_entity
), ! definition
, 0, 0);
4535 /* We only need to use this variable if we are in global context since GCC
4536 can do the right thing in the local case. */
4537 if (expr_global
&& expr_variable
)
4539 else if (! expr_variable
)
4542 return maybe_variable (gnu_expr
, gnat_expr
);
4545 /* Create a record type that contains a field of TYPE with a starting bit
4546 position so that it is aligned to ALIGN bits and is SIZE bytes long. */
4549 make_aligning_type (tree type
, int align
, tree size
)
4551 tree record_type
= make_node (RECORD_TYPE
);
4552 tree place
= build (PLACEHOLDER_EXPR
, record_type
);
4553 tree size_addr_place
= convert (sizetype
,
4554 build_unary_op (ADDR_EXPR
, NULL_TREE
,
4556 tree name
= TYPE_NAME (type
);
4559 if (TREE_CODE (name
) == TYPE_DECL
)
4560 name
= DECL_NAME (name
);
4562 TYPE_NAME (record_type
) = concat_id_with_name (name
, "_ALIGN");
4564 /* The bit position is obtained by "and"ing the alignment minus 1
4565 with the two's complement of the address and multiplying
4566 by the number of bits per unit. Do all this in sizetype. */
4568 pos
= size_binop (MULT_EXPR
,
4569 convert (bitsizetype
,
4570 size_binop (BIT_AND_EXPR
,
4571 size_diffop (size_zero_node
,
4573 ssize_int ((align
/ BITS_PER_UNIT
)
4577 field
= create_field_decl (get_identifier ("F"), type
, record_type
,
4579 DECL_BIT_FIELD (field
) = 0;
4581 finish_record_type (record_type
, field
, 1, 0);
4582 TYPE_ALIGN (record_type
) = BIGGEST_ALIGNMENT
;
4583 TYPE_SIZE (record_type
)
4584 = size_binop (PLUS_EXPR
,
4585 size_binop (MULT_EXPR
, convert (bitsizetype
, size
),
4587 bitsize_int (align
));
4588 TYPE_SIZE_UNIT (record_type
)
4589 = size_binop (PLUS_EXPR
, size
, size_int (align
/ BITS_PER_UNIT
));
4590 copy_alias_set (record_type
, type
);
4594 /* TYPE is a RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE, with BLKmode that's
4595 being used as the field type of a packed record. See if we can rewrite it
4596 as a record that has a non-BLKmode type, which we can pack tighter. If so,
4597 return the new type. If not, return the original type. */
4600 make_packable_type (tree type
)
4602 tree new_type
= make_node (TREE_CODE (type
));
4603 tree field_list
= NULL_TREE
;
4606 /* Copy the name and flags from the old type to that of the new and set
4607 the alignment to try for an integral type. For QUAL_UNION_TYPE,
4608 also copy the size. */
4609 TYPE_NAME (new_type
) = TYPE_NAME (type
);
4610 TYPE_LEFT_JUSTIFIED_MODULAR_P (new_type
)
4611 = TYPE_LEFT_JUSTIFIED_MODULAR_P (type
);
4612 TYPE_CONTAINS_TEMPLATE_P (new_type
) = TYPE_CONTAINS_TEMPLATE_P (type
);
4614 if (TREE_CODE (type
) == RECORD_TYPE
)
4615 TYPE_IS_PADDING_P (new_type
) = TYPE_IS_PADDING_P (type
);
4616 else if (TREE_CODE (type
) == QUAL_UNION_TYPE
)
4618 TYPE_SIZE (new_type
) = TYPE_SIZE (type
);
4619 TYPE_SIZE_UNIT (new_type
) = TYPE_SIZE_UNIT (type
);
4622 TYPE_ALIGN (new_type
)
4623 = ((HOST_WIDE_INT
) 1
4624 << (floor_log2 (tree_low_cst (TYPE_SIZE (type
), 1) - 1) + 1));
4626 /* Now copy the fields, keeping the position and size. */
4627 for (old_field
= TYPE_FIELDS (type
); old_field
!= 0;
4628 old_field
= TREE_CHAIN (old_field
))
4630 tree new_field_type
= TREE_TYPE (old_field
);
4633 if (TYPE_MODE (new_field_type
) == BLKmode
4634 && (TREE_CODE (new_field_type
) == RECORD_TYPE
4635 || TREE_CODE (new_field_type
) == UNION_TYPE
4636 || TREE_CODE (new_field_type
) == QUAL_UNION_TYPE
)
4637 && host_integerp (TYPE_SIZE (new_field_type
), 1))
4638 new_field_type
= make_packable_type (new_field_type
);
4640 new_field
= create_field_decl (DECL_NAME (old_field
), new_field_type
,
4641 new_type
, TYPE_PACKED (type
),
4642 DECL_SIZE (old_field
),
4643 bit_position (old_field
),
4644 ! DECL_NONADDRESSABLE_P (old_field
));
4646 DECL_INTERNAL_P (new_field
) = DECL_INTERNAL_P (old_field
);
4647 SET_DECL_ORIGINAL_FIELD (new_field
,
4648 (DECL_ORIGINAL_FIELD (old_field
) != 0
4649 ? DECL_ORIGINAL_FIELD (old_field
) : old_field
));
4651 if (TREE_CODE (new_type
) == QUAL_UNION_TYPE
)
4652 DECL_QUALIFIER (new_field
) = DECL_QUALIFIER (old_field
);
4654 TREE_CHAIN (new_field
) = field_list
;
4655 field_list
= new_field
;
4658 finish_record_type (new_type
, nreverse (field_list
), 1, 1);
4659 copy_alias_set (new_type
, type
);
4660 return TYPE_MODE (new_type
) == BLKmode
? type
: new_type
;
4663 /* Ensure that TYPE has SIZE and ALIGN. Make and return a new padded type
4664 if needed. We have already verified that SIZE and TYPE are large enough.
4666 GNAT_ENTITY and NAME_TRAILER are used to name the resulting record and
4669 IS_USER_TYPE is nonzero if we must be sure we complete the original type.
4671 DEFINITION is nonzero if this type is being defined.
4673 SAME_RM_SIZE is nonzero if the RM_Size of the resulting type is to be
4674 set to its TYPE_SIZE; otherwise, it's set to the RM_Size of the original
4678 maybe_pad_type (tree type
,
4681 Entity_Id gnat_entity
,
4682 const char *name_trailer
,
4687 tree orig_size
= TYPE_SIZE (type
);
4691 /* If TYPE is a padded type, see if it agrees with any size and alignment
4692 we were given. If so, return the original type. Otherwise, strip
4693 off the padding, since we will either be returning the inner type
4694 or repadding it. If no size or alignment is specified, use that of
4695 the original padded type. */
4697 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_IS_PADDING_P (type
))
4700 || operand_equal_p (round_up (size
,
4701 MAX (align
, TYPE_ALIGN (type
))),
4702 round_up (TYPE_SIZE (type
),
4703 MAX (align
, TYPE_ALIGN (type
))),
4705 && (align
== 0 || align
== TYPE_ALIGN (type
)))
4709 size
= TYPE_SIZE (type
);
4711 align
= TYPE_ALIGN (type
);
4713 type
= TREE_TYPE (TYPE_FIELDS (type
));
4714 orig_size
= TYPE_SIZE (type
);
4717 /* If the size is either not being changed or is being made smaller (which
4718 is not done here (and is only valid for bitfields anyway), show the size
4719 isn't changing. Likewise, clear the alignment if it isn't being
4720 changed. Then return if we aren't doing anything. */
4723 && (operand_equal_p (size
, orig_size
, 0)
4724 || (TREE_CODE (orig_size
) == INTEGER_CST
4725 && tree_int_cst_lt (size
, orig_size
))))
4728 if (align
== TYPE_ALIGN (type
))
4731 if (align
== 0 && size
== 0)
4734 /* We used to modify the record in place in some cases, but that could
4735 generate incorrect debugging information. So make a new record
4737 record
= make_node (RECORD_TYPE
);
4739 if (Present (gnat_entity
))
4740 TYPE_NAME (record
) = create_concat_name (gnat_entity
, name_trailer
);
4742 /* If we were making a type, complete the original type and give it a
4745 create_type_decl (get_entity_name (gnat_entity
), type
,
4746 0, ! Comes_From_Source (gnat_entity
),
4747 ! (TYPE_NAME (type
) != 0
4748 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
4749 && DECL_IGNORED_P (TYPE_NAME (type
))));
4751 /* If we are changing the alignment and the input type is a record with
4752 BLKmode and a small constant size, try to make a form that has an
4753 integral mode. That might allow this record to have an integral mode,
4754 which will be much more efficient. There is no point in doing this if a
4755 size is specified unless it is also smaller than the biggest alignment
4756 and it is incorrect to do this if the size of the original type is not a
4757 multiple of the alignment. */
4759 && TREE_CODE (type
) == RECORD_TYPE
4760 && TYPE_MODE (type
) == BLKmode
4761 && host_integerp (orig_size
, 1)
4762 && compare_tree_int (orig_size
, BIGGEST_ALIGNMENT
) <= 0
4764 || (TREE_CODE (size
) == INTEGER_CST
4765 && compare_tree_int (size
, BIGGEST_ALIGNMENT
) <= 0))
4766 && tree_low_cst (orig_size
, 1) % align
== 0)
4767 type
= make_packable_type (type
);
4769 field
= create_field_decl (get_identifier ("F"), type
, record
, 0,
4770 NULL_TREE
, bitsize_zero_node
, 1);
4772 DECL_INTERNAL_P (field
) = 1;
4773 TYPE_SIZE (record
) = size
!= 0 ? size
: orig_size
;
4774 TYPE_SIZE_UNIT (record
)
4775 = convert (sizetype
,
4776 size_binop (CEIL_DIV_EXPR
, TYPE_SIZE (record
),
4777 bitsize_unit_node
));
4778 TYPE_ALIGN (record
) = align
;
4779 TYPE_IS_PADDING_P (record
) = 1;
4780 TYPE_VOLATILE (record
)
4781 = Present (gnat_entity
) && Treat_As_Volatile (gnat_entity
);
4782 finish_record_type (record
, field
, 1, 0);
4784 /* Keep the RM_Size of the padded record as that of the old record
4786 SET_TYPE_ADA_SIZE (record
, same_rm_size
? size
: rm_size (type
));
4788 /* Unless debugging information isn't being written for the input type,
4789 write a record that shows what we are a subtype of and also make a
4790 variable that indicates our size, if variable. */
4791 if (TYPE_NAME (record
) != 0
4792 && AGGREGATE_TYPE_P (type
)
4793 && (TREE_CODE (TYPE_NAME (type
)) != TYPE_DECL
4794 || ! DECL_IGNORED_P (TYPE_NAME (type
))))
4796 tree marker
= make_node (RECORD_TYPE
);
4797 tree name
= DECL_NAME (TYPE_NAME (record
));
4798 tree orig_name
= TYPE_NAME (type
);
4800 if (TREE_CODE (orig_name
) == TYPE_DECL
)
4801 orig_name
= DECL_NAME (orig_name
);
4803 TYPE_NAME (marker
) = concat_id_with_name (name
, "XVS");
4804 finish_record_type (marker
,
4805 create_field_decl (orig_name
, integer_type_node
,
4806 marker
, 0, NULL_TREE
, NULL_TREE
,
4810 if (size
!= 0 && TREE_CODE (size
) != INTEGER_CST
&& definition
)
4811 create_var_decl (concat_id_with_name (name
, "XVZ"), NULL_TREE
,
4812 sizetype
, TYPE_SIZE (record
), 0, 0, 0, 0,
4818 if (CONTAINS_PLACEHOLDER_P (orig_size
))
4819 orig_size
= max_size (orig_size
, 1);
4821 /* If the size was widened explicitly, maybe give a warning. */
4822 if (size
!= 0 && Present (gnat_entity
)
4823 && ! operand_equal_p (size
, orig_size
, 0)
4824 && ! (TREE_CODE (size
) == INTEGER_CST
4825 && TREE_CODE (orig_size
) == INTEGER_CST
4826 && tree_int_cst_lt (size
, orig_size
)))
4828 Node_Id gnat_error_node
= Empty
;
4830 if (Is_Packed_Array_Type (gnat_entity
))
4831 gnat_entity
= Associated_Node_For_Itype (gnat_entity
);
4833 if ((Ekind (gnat_entity
) == E_Component
4834 || Ekind (gnat_entity
) == E_Discriminant
)
4835 && Present (Component_Clause (gnat_entity
)))
4836 gnat_error_node
= Last_Bit (Component_Clause (gnat_entity
));
4837 else if (Present (Size_Clause (gnat_entity
)))
4838 gnat_error_node
= Expression (Size_Clause (gnat_entity
));
4840 /* Generate message only for entities that come from source, since
4841 if we have an entity created by expansion, the message will be
4842 generated for some other corresponding source entity. */
4843 if (Comes_From_Source (gnat_entity
) && Present (gnat_error_node
))
4844 post_error_ne_tree ("{^ }bits of & unused?", gnat_error_node
,
4846 size_diffop (size
, orig_size
));
4848 else if (*name_trailer
== 'C' && ! Is_Internal (gnat_entity
))
4849 post_error_ne_tree ("component of& padded{ by ^ bits}?",
4850 gnat_entity
, gnat_entity
,
4851 size_diffop (size
, orig_size
));
4857 /* Given a GNU tree and a GNAT list of choices, generate an expression to test
4858 the value passed against the list of choices. */
4861 choices_to_gnu (tree operand
, Node_Id choices
)
4865 tree result
= integer_zero_node
;
4866 tree this_test
, low
= 0, high
= 0, single
= 0;
4868 for (choice
= First (choices
); Present (choice
); choice
= Next (choice
))
4870 switch (Nkind (choice
))
4873 low
= gnat_to_gnu (Low_Bound (choice
));
4874 high
= gnat_to_gnu (High_Bound (choice
));
4876 /* There's no good type to use here, so we might as well use
4877 integer_type_node. */
4879 = build_binary_op (TRUTH_ANDIF_EXPR
, integer_type_node
,
4880 build_binary_op (GE_EXPR
, integer_type_node
,
4882 build_binary_op (LE_EXPR
, integer_type_node
,
4887 case N_Subtype_Indication
:
4888 gnat_temp
= Range_Expression (Constraint (choice
));
4889 low
= gnat_to_gnu (Low_Bound (gnat_temp
));
4890 high
= gnat_to_gnu (High_Bound (gnat_temp
));
4893 = build_binary_op (TRUTH_ANDIF_EXPR
, integer_type_node
,
4894 build_binary_op (GE_EXPR
, integer_type_node
,
4896 build_binary_op (LE_EXPR
, integer_type_node
,
4901 case N_Expanded_Name
:
4902 /* This represents either a subtype range, an enumeration
4903 literal, or a constant Ekind says which. If an enumeration
4904 literal or constant, fall through to the next case. */
4905 if (Ekind (Entity (choice
)) != E_Enumeration_Literal
4906 && Ekind (Entity (choice
)) != E_Constant
)
4908 tree type
= gnat_to_gnu_type (Entity (choice
));
4910 low
= TYPE_MIN_VALUE (type
);
4911 high
= TYPE_MAX_VALUE (type
);
4914 = build_binary_op (TRUTH_ANDIF_EXPR
, integer_type_node
,
4915 build_binary_op (GE_EXPR
, integer_type_node
,
4917 build_binary_op (LE_EXPR
, integer_type_node
,
4921 /* ... fall through ... */
4922 case N_Character_Literal
:
4923 case N_Integer_Literal
:
4924 single
= gnat_to_gnu (choice
);
4925 this_test
= build_binary_op (EQ_EXPR
, integer_type_node
, operand
,
4929 case N_Others_Choice
:
4930 this_test
= integer_one_node
;
4937 result
= build_binary_op (TRUTH_ORIF_EXPR
, integer_type_node
,
4944 /* Return a GCC tree for a field corresponding to GNAT_FIELD to be
4945 placed in GNU_RECORD_TYPE.
4947 PACKED is 1 if the enclosing record is packed and -1 if the enclosing
4948 record has a Component_Alignment of Storage_Unit.
4950 DEFINITION is nonzero if this field is for a record being defined. */
4953 gnat_to_gnu_field (Entity_Id gnat_field
,
4954 tree gnu_record_type
,
4958 tree gnu_field_id
= get_entity_name (gnat_field
);
4959 tree gnu_field_type
= gnat_to_gnu_type (Etype (gnat_field
));
4960 tree gnu_orig_field_type
= gnu_field_type
;
4964 int needs_strict_alignment
4965 = (Is_Aliased (gnat_field
) || Strict_Alignment (Etype (gnat_field
))
4966 || Treat_As_Volatile (gnat_field
));
4968 /* If this field requires strict alignment or contains an item of
4969 variable sized, pretend it isn't packed. */
4970 if (needs_strict_alignment
|| is_variable_size (gnu_field_type
))
4973 /* For packed records, this is one of the few occasions on which we use
4974 the official RM size for discrete or fixed-point components, instead
4975 of the normal GNAT size stored in Esize. See description in Einfo:
4976 "Handling of Type'Size Values" for further details. */
4979 gnu_size
= validate_size (RM_Size (Etype (gnat_field
)), gnu_field_type
,
4980 gnat_field
, FIELD_DECL
, 0, 1);
4982 if (Known_Static_Esize (gnat_field
))
4983 gnu_size
= validate_size (Esize (gnat_field
), gnu_field_type
,
4984 gnat_field
, FIELD_DECL
, 0, 1);
4986 /* If the field's type is left-justified modular, the wrapper can prevent
4987 packing so we make the field the type of the inner object unless the
4988 situation forbids it. We may not do that when the field is addressable_p,
4989 typically because in that case this field may later be passed by-ref for
4990 a formal argument expecting the left justification. The condition below
4991 is then matching the addressable_p code for COMPONENT_REF. */
4992 if (! Is_Aliased (gnat_field
) && flag_strict_aliasing
4993 && TREE_CODE (gnu_field_type
) == RECORD_TYPE
4994 && TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_field_type
))
4995 gnu_field_type
= TREE_TYPE (TYPE_FIELDS (gnu_field_type
));
4997 /* If we are packing this record or we have a specified size that's
4998 smaller than that of the field type and the field type is also a record
4999 that's BLKmode and with a small constant size, see if we can get a
5000 better form of the type that allows more packing. If we can, show
5001 a size was specified for it if there wasn't one so we know to
5002 make this a bitfield and avoid making things wider. */
5003 if (TREE_CODE (gnu_field_type
) == RECORD_TYPE
5004 && TYPE_MODE (gnu_field_type
) == BLKmode
5005 && host_integerp (TYPE_SIZE (gnu_field_type
), 1)
5006 && compare_tree_int (TYPE_SIZE (gnu_field_type
), BIGGEST_ALIGNMENT
) <= 0
5008 || (gnu_size
!= 0 && tree_int_cst_lt (gnu_size
,
5009 TYPE_SIZE (gnu_field_type
)))))
5011 gnu_field_type
= make_packable_type (gnu_field_type
);
5013 if (gnu_field_type
!= gnu_orig_field_type
&& gnu_size
== 0)
5014 gnu_size
= rm_size (gnu_field_type
);
5017 /* If we are packing the record and the field is BLKmode, round the
5018 size up to a byte boundary. */
5019 if (packed
&& TYPE_MODE (gnu_field_type
) == BLKmode
&& gnu_size
!= 0)
5020 gnu_size
= round_up (gnu_size
, BITS_PER_UNIT
);
5022 if (Present (Component_Clause (gnat_field
)))
5024 gnu_pos
= UI_To_gnu (Component_Bit_Offset (gnat_field
), bitsizetype
);
5025 gnu_size
= validate_size (Esize (gnat_field
), gnu_field_type
,
5026 gnat_field
, FIELD_DECL
, 0, 1);
5028 /* Ensure the position does not overlap with the parent subtype,
5030 if (Present (Parent_Subtype (Underlying_Type (Scope (gnat_field
)))))
5033 = gnat_to_gnu_type (Parent_Subtype
5034 (Underlying_Type (Scope (gnat_field
))));
5036 if (TREE_CODE (TYPE_SIZE (gnu_parent
)) == INTEGER_CST
5037 && tree_int_cst_lt (gnu_pos
, TYPE_SIZE (gnu_parent
)))
5040 ("offset of& must be beyond parent{, minimum allowed is ^}",
5041 First_Bit (Component_Clause (gnat_field
)), gnat_field
,
5042 TYPE_SIZE_UNIT (gnu_parent
));
5046 /* If this field needs strict alignment, ensure the record is
5047 sufficiently aligned and that that position and size are
5048 consistent with the alignment. */
5049 if (needs_strict_alignment
)
5051 tree gnu_min_size
= round_up (rm_size (gnu_field_type
),
5052 TYPE_ALIGN (gnu_field_type
));
5054 TYPE_ALIGN (gnu_record_type
)
5055 = MAX (TYPE_ALIGN (gnu_record_type
), TYPE_ALIGN (gnu_field_type
));
5057 /* If Atomic, the size must match exactly and if aliased, the size
5058 must not be less than the rounded size. */
5059 if ((Is_Atomic (gnat_field
) || Is_Atomic (Etype (gnat_field
)))
5060 && ! operand_equal_p (gnu_size
, TYPE_SIZE (gnu_field_type
), 0))
5063 ("atomic field& must be natural size of type{ (^)}",
5064 Last_Bit (Component_Clause (gnat_field
)), gnat_field
,
5065 TYPE_SIZE (gnu_field_type
));
5070 else if (Is_Aliased (gnat_field
)
5072 && tree_int_cst_lt (gnu_size
, gnu_min_size
))
5075 ("size of aliased field& too small{, minimum required is ^}",
5076 Last_Bit (Component_Clause (gnat_field
)), gnat_field
,
5081 if (! integer_zerop (size_binop
5082 (TRUNC_MOD_EXPR
, gnu_pos
,
5083 bitsize_int (TYPE_ALIGN (gnu_field_type
)))))
5085 if (Is_Aliased (gnat_field
))
5087 ("position of aliased field& must be multiple of ^ bits",
5088 First_Bit (Component_Clause (gnat_field
)), gnat_field
,
5089 TYPE_ALIGN (gnu_field_type
));
5091 else if (Treat_As_Volatile (gnat_field
))
5093 ("position of volatile field& must be multiple of ^ bits",
5094 First_Bit (Component_Clause (gnat_field
)), gnat_field
,
5095 TYPE_ALIGN (gnu_field_type
));
5097 else if (Strict_Alignment (Etype (gnat_field
)))
5099 ("position of & with aliased or tagged components not multiple of ^ bits",
5100 First_Bit (Component_Clause (gnat_field
)), gnat_field
,
5101 TYPE_ALIGN (gnu_field_type
));
5108 /* If an error set the size to zero, show we have no position
5114 if (Is_Atomic (gnat_field
))
5115 check_ok_for_atomic (gnu_field_type
, gnat_field
, 0);
5118 /* If the record has rep clauses and this is the tag field, make a rep
5119 clause for it as well. */
5120 else if (Has_Specified_Layout (Scope (gnat_field
))
5121 && Chars (gnat_field
) == Name_uTag
)
5123 gnu_pos
= bitsize_zero_node
;
5124 gnu_size
= TYPE_SIZE (gnu_field_type
);
5127 /* We need to make the size the maximum for the type if it is
5128 self-referential and an unconstrained type. In that case, we can't
5129 pack the field since we can't make a copy to align it. */
5130 if (TREE_CODE (gnu_field_type
) == RECORD_TYPE
5132 && CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_field_type
))
5133 && ! Is_Constrained (Underlying_Type (Etype (gnat_field
))))
5135 gnu_size
= max_size (TYPE_SIZE (gnu_field_type
), 1);
5139 /* If no size is specified (or if there was an error), don't specify a
5145 /* Unless this field is aliased, we can remove any left-justified
5146 modular type since it's only needed in the unchecked conversion
5147 case, which doesn't apply here. */
5148 if (! needs_strict_alignment
5149 && TREE_CODE (gnu_field_type
) == RECORD_TYPE
5150 && TYPE_LEFT_JUSTIFIED_MODULAR_P (gnu_field_type
))
5151 gnu_field_type
= TREE_TYPE (TYPE_FIELDS (gnu_field_type
));
5154 = make_type_from_size (gnu_field_type
, gnu_size
,
5155 Has_Biased_Representation (gnat_field
));
5156 gnu_field_type
= maybe_pad_type (gnu_field_type
, gnu_size
, 0,
5157 gnat_field
, "PAD", 0, definition
, 1);
5160 if (TREE_CODE (gnu_field_type
) == RECORD_TYPE
5161 && TYPE_CONTAINS_TEMPLATE_P (gnu_field_type
))
5164 /* Now create the decl for the field. */
5165 set_lineno (gnat_field
, 0);
5166 gnu_field
= create_field_decl (gnu_field_id
, gnu_field_type
, gnu_record_type
,
5167 packed
, gnu_size
, gnu_pos
,
5168 Is_Aliased (gnat_field
));
5170 TREE_THIS_VOLATILE (gnu_field
) = Treat_As_Volatile (gnat_field
);
5172 if (Ekind (gnat_field
) == E_Discriminant
)
5173 DECL_DISCRIMINANT_NUMBER (gnu_field
)
5174 = UI_To_gnu (Discriminant_Number (gnat_field
), sizetype
);
5179 /* Return 1 if TYPE is a type with variable size, a padding type with a field
5180 of variable size or is a record that has a field such a field. */
5183 is_variable_size (tree type
)
5187 /* We need not be concerned about this at all if we don't have
5188 strict alignment. */
5189 if (! STRICT_ALIGNMENT
)
5191 else if (! TREE_CONSTANT (TYPE_SIZE (type
)))
5193 else if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_IS_PADDING_P (type
)
5194 && ! TREE_CONSTANT (DECL_SIZE (TYPE_FIELDS (type
))))
5196 else if (TREE_CODE (type
) != RECORD_TYPE
5197 && TREE_CODE (type
) != UNION_TYPE
5198 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
5201 for (field
= TYPE_FIELDS (type
); field
!= 0; field
= TREE_CHAIN (field
))
5202 if (is_variable_size (TREE_TYPE (field
)))
5208 /* Return a GCC tree for a record type given a GNAT Component_List and a chain
5209 of GCC trees for fields that are in the record and have already been
5210 processed. When called from gnat_to_gnu_entity during the processing of a
5211 record type definition, the GCC nodes for the discriminants will be on
5212 the chain. The other calls to this function are recursive calls from
5213 itself for the Component_List of a variant and the chain is empty.
5215 PACKED is 1 if this is for a record with "pragma pack" and -1 is this is
5216 for a record type with "pragma component_alignment (storage_unit)".
5218 FINISH_RECORD is nonzero if this call will supply all of the remaining
5219 fields of the record.
5221 P_GNU_REP_LIST, if nonzero, is a pointer to a list to which each field
5222 with a rep clause is to be added. If it is nonzero, that is all that
5223 should be done with such fields.
5225 CANCEL_ALIGNMENT, if nonzero, means the alignment should be zeroed
5226 before laying out the record. This means the alignment only serves
5227 to force fields to be bitfields, but not require the record to be
5228 that aligned. This is used for variants.
5230 ALL_REP, if nonzero, means that a rep clause was found for all the
5231 fields. This simplifies the logic since we know we're not in the mixed
5234 The processing of the component list fills in the chain with all of the
5235 fields of the record and then the record type is finished. */
5238 components_to_record (tree gnu_record_type
,
5239 Node_Id component_list
,
5240 tree gnu_field_list
,
5243 tree
*p_gnu_rep_list
,
5244 int cancel_alignment
,
5247 Node_Id component_decl
;
5248 Entity_Id gnat_field
;
5249 Node_Id variant_part
;
5251 tree gnu_our_rep_list
= NULL_TREE
;
5252 tree gnu_field
, gnu_last
;
5253 int layout_with_rep
= 0;
5254 int all_rep_and_size
= all_rep
&& TYPE_SIZE (gnu_record_type
) != 0;
5256 /* For each variable within each component declaration create a GCC field
5257 and add it to the list, skipping any pragmas in the list. */
5259 if (Present (Component_Items (component_list
)))
5260 for (component_decl
= First_Non_Pragma (Component_Items (component_list
));
5261 Present (component_decl
);
5262 component_decl
= Next_Non_Pragma (component_decl
))
5264 gnat_field
= Defining_Entity (component_decl
);
5266 if (Chars (gnat_field
) == Name_uParent
)
5267 gnu_field
= tree_last (TYPE_FIELDS (gnu_record_type
));
5270 gnu_field
= gnat_to_gnu_field (gnat_field
, gnu_record_type
,
5271 packed
, definition
);
5273 /* If this is the _Tag field, put it before any discriminants,
5274 instead of after them as is the case for all other fields.
5275 Ignore field of void type if only annotating. */
5276 if (Chars (gnat_field
) == Name_uTag
)
5277 gnu_field_list
= chainon (gnu_field_list
, gnu_field
);
5280 TREE_CHAIN (gnu_field
) = gnu_field_list
;
5281 gnu_field_list
= gnu_field
;
5285 save_gnu_tree (gnat_field
, gnu_field
, 0);
5288 /* At the end of the component list there may be a variant part. */
5289 variant_part
= Variant_Part (component_list
);
5291 /* If this is an unchecked union, each variant must have exactly one
5292 component, each of which becomes one component of this union. */
5293 if (TREE_CODE (gnu_record_type
) == UNION_TYPE
&& Present (variant_part
))
5294 for (variant
= First_Non_Pragma (Variants (variant_part
));
5296 variant
= Next_Non_Pragma (variant
))
5299 = First_Non_Pragma (Component_Items (Component_List (variant
)));
5300 gnat_field
= Defining_Entity (component_decl
);
5301 gnu_field
= gnat_to_gnu_field (gnat_field
, gnu_record_type
, packed
,
5303 TREE_CHAIN (gnu_field
) = gnu_field_list
;
5304 gnu_field_list
= gnu_field
;
5305 save_gnu_tree (gnat_field
, gnu_field
, 0);
5308 /* We create a QUAL_UNION_TYPE for the variant part since the variants are
5309 mutually exclusive and should go in the same memory. To do this we need
5310 to treat each variant as a record whose elements are created from the
5311 component list for the variant. So here we create the records from the
5312 lists for the variants and put them all into the QUAL_UNION_TYPE. */
5313 else if (Present (variant_part
))
5315 tree gnu_discriminant
= gnat_to_gnu (Name (variant_part
));
5317 tree gnu_union_type
= make_node (QUAL_UNION_TYPE
);
5318 tree gnu_union_field
;
5319 tree gnu_variant_list
= NULL_TREE
;
5320 tree gnu_name
= TYPE_NAME (gnu_record_type
);
5322 = concat_id_with_name
5323 (get_identifier (Get_Name_String (Chars (Name (variant_part
)))),
5326 if (TREE_CODE (gnu_name
) == TYPE_DECL
)
5327 gnu_name
= DECL_NAME (gnu_name
);
5329 TYPE_NAME (gnu_union_type
)
5330 = concat_id_with_name (gnu_name
, IDENTIFIER_POINTER (gnu_var_name
));
5331 TYPE_PACKED (gnu_union_type
) = TYPE_PACKED (gnu_record_type
);
5333 for (variant
= First_Non_Pragma (Variants (variant_part
));
5335 variant
= Next_Non_Pragma (variant
))
5337 tree gnu_variant_type
= make_node (RECORD_TYPE
);
5338 tree gnu_inner_name
;
5341 Get_Variant_Encoding (variant
);
5342 gnu_inner_name
= get_identifier (Name_Buffer
);
5343 TYPE_NAME (gnu_variant_type
)
5344 = concat_id_with_name (TYPE_NAME (gnu_union_type
),
5345 IDENTIFIER_POINTER (gnu_inner_name
));
5347 /* Set the alignment of the inner type in case we need to make
5348 inner objects into bitfields, but then clear it out
5349 so the record actually gets only the alignment required. */
5350 TYPE_ALIGN (gnu_variant_type
) = TYPE_ALIGN (gnu_record_type
);
5351 TYPE_PACKED (gnu_variant_type
) = TYPE_PACKED (gnu_record_type
);
5353 /* Similarly, if the outer record has a size specified and all fields
5354 have record rep clauses, we can propagate the size into the
5356 if (all_rep_and_size
)
5358 TYPE_SIZE (gnu_variant_type
) = TYPE_SIZE (gnu_record_type
);
5359 TYPE_SIZE_UNIT (gnu_variant_type
)
5360 = TYPE_SIZE_UNIT (gnu_record_type
);
5363 components_to_record (gnu_variant_type
, Component_List (variant
),
5364 NULL_TREE
, packed
, definition
,
5365 &gnu_our_rep_list
, !all_rep_and_size
, all_rep
);
5367 gnu_qual
= choices_to_gnu (gnu_discriminant
,
5368 Discrete_Choices (variant
));
5370 Set_Present_Expr (variant
, annotate_value (gnu_qual
));
5371 gnu_field
= create_field_decl (gnu_inner_name
, gnu_variant_type
,
5374 ? TYPE_SIZE (gnu_record_type
) : 0),
5376 ? bitsize_zero_node
: 0),
5379 DECL_INTERNAL_P (gnu_field
) = 1;
5380 DECL_QUALIFIER (gnu_field
) = gnu_qual
;
5381 TREE_CHAIN (gnu_field
) = gnu_variant_list
;
5382 gnu_variant_list
= gnu_field
;
5385 /* We use to delete the empty variants from the end. However,
5386 we no longer do that because we need them to generate complete
5387 debugging information for the variant record. Otherwise,
5388 the union type definition will be missing the fields associated
5389 to these empty variants. */
5391 /* Only make the QUAL_UNION_TYPE if there are any non-empty variants. */
5392 if (gnu_variant_list
!= 0)
5394 if (all_rep_and_size
)
5396 TYPE_SIZE (gnu_union_type
) = TYPE_SIZE (gnu_record_type
);
5397 TYPE_SIZE_UNIT (gnu_union_type
)
5398 = TYPE_SIZE_UNIT (gnu_record_type
);
5401 finish_record_type (gnu_union_type
, nreverse (gnu_variant_list
),
5402 all_rep_and_size
, 0);
5405 = create_field_decl (gnu_var_name
, gnu_union_type
, gnu_record_type
,
5407 all_rep
? TYPE_SIZE (gnu_union_type
) : 0,
5408 all_rep
? bitsize_zero_node
: 0, 0);
5410 DECL_INTERNAL_P (gnu_union_field
) = 1;
5411 TREE_CHAIN (gnu_union_field
) = gnu_field_list
;
5412 gnu_field_list
= gnu_union_field
;
5416 /* Scan GNU_FIELD_LIST and see if any fields have rep clauses. If they
5417 do, pull them out and put them into GNU_OUR_REP_LIST. We have to do this
5418 in a separate pass since we want to handle the discriminants but can't
5419 play with them until we've used them in debugging data above.
5421 ??? Note: if we then reorder them, debugging information will be wrong,
5422 but there's nothing that can be done about this at the moment. */
5424 for (gnu_field
= gnu_field_list
, gnu_last
= 0; gnu_field
; )
5426 if (DECL_FIELD_OFFSET (gnu_field
) != 0)
5428 tree gnu_next
= TREE_CHAIN (gnu_field
);
5431 gnu_field_list
= gnu_next
;
5433 TREE_CHAIN (gnu_last
) = gnu_next
;
5435 TREE_CHAIN (gnu_field
) = gnu_our_rep_list
;
5436 gnu_our_rep_list
= gnu_field
;
5437 gnu_field
= gnu_next
;
5441 gnu_last
= gnu_field
;
5442 gnu_field
= TREE_CHAIN (gnu_field
);
5446 /* If we have any items in our rep'ed field list, it is not the case that all
5447 the fields in the record have rep clauses, and P_REP_LIST is nonzero,
5448 set it and ignore the items. Otherwise, sort the fields by bit position
5449 and put them into their own record if we have any fields without
5451 if (gnu_our_rep_list
!= 0 && p_gnu_rep_list
!= 0 && ! all_rep
)
5452 *p_gnu_rep_list
= chainon (*p_gnu_rep_list
, gnu_our_rep_list
);
5453 else if (gnu_our_rep_list
!= 0)
5456 = gnu_field_list
== 0 ? gnu_record_type
: make_node (RECORD_TYPE
);
5457 int len
= list_length (gnu_our_rep_list
);
5458 tree
*gnu_arr
= (tree
*) alloca (sizeof (tree
) * len
);
5461 /* Set DECL_SECTION_NAME to increasing integers so we have a
5463 for (i
= 0, gnu_field
= gnu_our_rep_list
; gnu_field
;
5464 gnu_field
= TREE_CHAIN (gnu_field
), i
++)
5466 gnu_arr
[i
] = gnu_field
;
5467 DECL_SECTION_NAME (gnu_field
) = size_int (i
);
5470 qsort (gnu_arr
, len
, sizeof (tree
), compare_field_bitpos
);
5472 /* Put the fields in the list in order of increasing position, which
5473 means we start from the end. */
5474 gnu_our_rep_list
= NULL_TREE
;
5475 for (i
= len
- 1; i
>= 0; i
--)
5477 TREE_CHAIN (gnu_arr
[i
]) = gnu_our_rep_list
;
5478 gnu_our_rep_list
= gnu_arr
[i
];
5479 DECL_CONTEXT (gnu_arr
[i
]) = gnu_rep_type
;
5480 DECL_SECTION_NAME (gnu_arr
[i
]) = 0;
5483 if (gnu_field_list
!= 0)
5485 finish_record_type (gnu_rep_type
, gnu_our_rep_list
, 1, 0);
5486 gnu_field
= create_field_decl (get_identifier ("REP"), gnu_rep_type
,
5487 gnu_record_type
, 0, 0, 0, 1);
5488 DECL_INTERNAL_P (gnu_field
) = 1;
5489 gnu_field_list
= chainon (gnu_field_list
, gnu_field
);
5493 layout_with_rep
= 1;
5494 gnu_field_list
= nreverse (gnu_our_rep_list
);
5498 if (cancel_alignment
)
5499 TYPE_ALIGN (gnu_record_type
) = 0;
5501 finish_record_type (gnu_record_type
, nreverse (gnu_field_list
),
5502 layout_with_rep
, 0);
5505 /* Called via qsort from the above. Returns -1, 1, depending on the
5506 bit positions and ordinals of the two fields. */
5509 compare_field_bitpos (const PTR rt1
, const PTR rt2
)
5511 tree
*t1
= (tree
*) rt1
;
5512 tree
*t2
= (tree
*) rt2
;
5514 if (tree_int_cst_equal (bit_position (*t1
), bit_position (*t2
)))
5516 (tree_int_cst_lt (DECL_SECTION_NAME (*t1
), DECL_SECTION_NAME (*t2
))
5518 else if (tree_int_cst_lt (bit_position (*t1
), bit_position (*t2
)))
5524 /* Given GNU_SIZE, a GCC tree representing a size, return a Uint to be
5525 placed into an Esize, Component_Bit_Offset, or Component_Size value
5526 in the GNAT tree. */
5529 annotate_value (tree gnu_size
)
5531 int len
= TREE_CODE_LENGTH (TREE_CODE (gnu_size
));
5533 Node_Ref_Or_Val ops
[3], ret
;
5537 /* If back annotation is suppressed by the front end, return No_Uint */
5538 if (!Back_Annotate_Rep_Info
)
5541 /* See if we've already saved the value for this node. */
5542 if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (gnu_size
)))
5543 && TREE_COMPLEXITY (gnu_size
) != 0)
5544 return (Node_Ref_Or_Val
) TREE_COMPLEXITY (gnu_size
);
5546 /* If we do not return inside this switch, TCODE will be set to the
5547 code to use for a Create_Node operand and LEN (set above) will be
5548 the number of recursive calls for us to make. */
5550 switch (TREE_CODE (gnu_size
))
5553 if (TREE_OVERFLOW (gnu_size
))
5556 /* This may have come from a conversion from some smaller type,
5557 so ensure this is in bitsizetype. */
5558 gnu_size
= convert (bitsizetype
, gnu_size
);
5560 /* For negative values, use NEGATE_EXPR of the supplied value. */
5561 if (tree_int_cst_sgn (gnu_size
) < 0)
5563 /* The rediculous code below is to handle the case of the largest
5564 negative integer. */
5565 tree negative_size
= size_diffop (bitsize_zero_node
, gnu_size
);
5569 if (TREE_CONSTANT_OVERFLOW (negative_size
))
5572 = size_binop (MINUS_EXPR
, bitsize_zero_node
,
5573 size_binop (PLUS_EXPR
, gnu_size
,
5578 temp
= build1 (NEGATE_EXPR
, bitsizetype
, negative_size
);
5580 temp
= build (MINUS_EXPR
, bitsizetype
, temp
, bitsize_one_node
);
5582 return annotate_value (temp
);
5585 if (! host_integerp (gnu_size
, 1))
5588 size
= tree_low_cst (gnu_size
, 1);
5590 /* This peculiar test is to make sure that the size fits in an int
5591 on machines where HOST_WIDE_INT is not "int". */
5592 if (tree_low_cst (gnu_size
, 1) == size
)
5593 return UI_From_Int (size
);
5598 /* The only case we handle here is a simple discriminant reference. */
5599 if (TREE_CODE (TREE_OPERAND (gnu_size
, 0)) == PLACEHOLDER_EXPR
5600 && TREE_CODE (TREE_OPERAND (gnu_size
, 1)) == FIELD_DECL
5601 && DECL_DISCRIMINANT_NUMBER (TREE_OPERAND (gnu_size
, 1)) != 0)
5602 return Create_Node (Discrim_Val
,
5603 annotate_value (DECL_DISCRIMINANT_NUMBER
5604 (TREE_OPERAND (gnu_size
, 1))),
5609 case NOP_EXPR
: case CONVERT_EXPR
: case NON_LVALUE_EXPR
:
5610 return annotate_value (TREE_OPERAND (gnu_size
, 0));
5612 /* Now just list the operations we handle. */
5613 case COND_EXPR
: tcode
= Cond_Expr
; break;
5614 case PLUS_EXPR
: tcode
= Plus_Expr
; break;
5615 case MINUS_EXPR
: tcode
= Minus_Expr
; break;
5616 case MULT_EXPR
: tcode
= Mult_Expr
; break;
5617 case TRUNC_DIV_EXPR
: tcode
= Trunc_Div_Expr
; break;
5618 case CEIL_DIV_EXPR
: tcode
= Ceil_Div_Expr
; break;
5619 case FLOOR_DIV_EXPR
: tcode
= Floor_Div_Expr
; break;
5620 case TRUNC_MOD_EXPR
: tcode
= Trunc_Mod_Expr
; break;
5621 case CEIL_MOD_EXPR
: tcode
= Ceil_Mod_Expr
; break;
5622 case FLOOR_MOD_EXPR
: tcode
= Floor_Mod_Expr
; break;
5623 case EXACT_DIV_EXPR
: tcode
= Exact_Div_Expr
; break;
5624 case NEGATE_EXPR
: tcode
= Negate_Expr
; break;
5625 case MIN_EXPR
: tcode
= Min_Expr
; break;
5626 case MAX_EXPR
: tcode
= Max_Expr
; break;
5627 case ABS_EXPR
: tcode
= Abs_Expr
; break;
5628 case TRUTH_ANDIF_EXPR
: tcode
= Truth_Andif_Expr
; break;
5629 case TRUTH_ORIF_EXPR
: tcode
= Truth_Orif_Expr
; break;
5630 case TRUTH_AND_EXPR
: tcode
= Truth_And_Expr
; break;
5631 case TRUTH_OR_EXPR
: tcode
= Truth_Or_Expr
; break;
5632 case TRUTH_XOR_EXPR
: tcode
= Truth_Xor_Expr
; break;
5633 case TRUTH_NOT_EXPR
: tcode
= Truth_Not_Expr
; break;
5634 case LT_EXPR
: tcode
= Lt_Expr
; break;
5635 case LE_EXPR
: tcode
= Le_Expr
; break;
5636 case GT_EXPR
: tcode
= Gt_Expr
; break;
5637 case GE_EXPR
: tcode
= Ge_Expr
; break;
5638 case EQ_EXPR
: tcode
= Eq_Expr
; break;
5639 case NE_EXPR
: tcode
= Ne_Expr
; break;
5645 /* Now get each of the operands that's relevant for this code. If any
5646 cannot be expressed as a repinfo node, say we can't. */
5647 for (i
= 0; i
< 3; i
++)
5650 for (i
= 0; i
< len
; i
++)
5652 ops
[i
] = annotate_value (TREE_OPERAND (gnu_size
, i
));
5653 if (ops
[i
] == No_Uint
)
5657 ret
= Create_Node (tcode
, ops
[0], ops
[1], ops
[2]);
5658 TREE_COMPLEXITY (gnu_size
) = ret
;
5662 /* Given GNAT_ENTITY, a record type, and GNU_TYPE, its corresponding
5663 GCC type, set Component_Bit_Offset and Esize to the position and size
5667 annotate_rep (Entity_Id gnat_entity
, tree gnu_type
)
5671 Entity_Id gnat_field
;
5673 /* We operate by first making a list of all field and their positions
5674 (we can get the sizes easily at any time) by a recursive call
5675 and then update all the sizes into the tree. */
5676 gnu_list
= compute_field_positions (gnu_type
, NULL_TREE
,
5677 size_zero_node
, bitsize_zero_node
,
5680 for (gnat_field
= First_Entity (gnat_entity
); Present (gnat_field
);
5681 gnat_field
= Next_Entity (gnat_field
))
5682 if ((Ekind (gnat_field
) == E_Component
5683 || (Ekind (gnat_field
) == E_Discriminant
5684 && ! Is_Unchecked_Union (Scope (gnat_field
)))))
5686 tree parent_offset
= bitsize_zero_node
;
5689 = purpose_member (gnat_to_gnu_entity (gnat_field
, NULL_TREE
, 0),
5694 if (type_annotate_only
&& Is_Tagged_Type (gnat_entity
))
5696 /* In this mode the tag and parent components have not been
5697 generated, so we add the appropriate offset to each
5698 component. For a component appearing in the current
5699 extension, the offset is the size of the parent. */
5700 if (Is_Derived_Type (gnat_entity
)
5701 && Original_Record_Component (gnat_field
) == gnat_field
)
5703 = UI_To_gnu (Esize (Etype (Base_Type (gnat_entity
))),
5706 parent_offset
= bitsize_int (POINTER_SIZE
);
5709 Set_Component_Bit_Offset
5712 (size_binop (PLUS_EXPR
,
5713 bit_from_pos (TREE_PURPOSE (TREE_VALUE (gnu_entry
)),
5714 TREE_VALUE (TREE_VALUE
5715 (TREE_VALUE (gnu_entry
)))),
5718 Set_Esize (gnat_field
,
5719 annotate_value (DECL_SIZE (TREE_PURPOSE (gnu_entry
))));
5721 else if (type_annotate_only
5722 && Is_Tagged_Type (gnat_entity
)
5723 && Is_Derived_Type (gnat_entity
))
5725 /* If there is no gnu_entry, this is an inherited component whose
5726 position is the same as in the parent type. */
5727 Set_Component_Bit_Offset
5729 Component_Bit_Offset (Original_Record_Component (gnat_field
)));
5730 Set_Esize (gnat_field
,
5731 Esize (Original_Record_Component (gnat_field
)));
5736 /* Scan all fields in GNU_TYPE and build entries where TREE_PURPOSE is the
5737 FIELD_DECL and TREE_VALUE a TREE_LIST with TREE_PURPOSE being the byte
5738 position and TREE_VALUE being a TREE_LIST with TREE_PURPOSE the value to be
5739 placed into DECL_OFFSET_ALIGN and TREE_VALUE the bit position. GNU_POS is
5740 to be added to the position, GNU_BITPOS to the bit position, OFFSET_ALIGN is
5741 the present value of DECL_OFFSET_ALIGN and GNU_LIST is a list of the entries
5745 compute_field_positions (tree gnu_type
,
5749 unsigned int offset_align
)
5752 tree gnu_result
= gnu_list
;
5754 for (gnu_field
= TYPE_FIELDS (gnu_type
); gnu_field
;
5755 gnu_field
= TREE_CHAIN (gnu_field
))
5757 tree gnu_our_bitpos
= size_binop (PLUS_EXPR
, gnu_bitpos
,
5758 DECL_FIELD_BIT_OFFSET (gnu_field
));
5759 tree gnu_our_offset
= size_binop (PLUS_EXPR
, gnu_pos
,
5760 DECL_FIELD_OFFSET (gnu_field
));
5761 unsigned int our_offset_align
5762 = MIN (offset_align
, DECL_OFFSET_ALIGN (gnu_field
));
5765 = tree_cons (gnu_field
,
5766 tree_cons (gnu_our_offset
,
5767 tree_cons (size_int (our_offset_align
),
5768 gnu_our_bitpos
, NULL_TREE
),
5772 if (DECL_INTERNAL_P (gnu_field
))
5774 = compute_field_positions (TREE_TYPE (gnu_field
), gnu_result
,
5775 gnu_our_offset
, gnu_our_bitpos
,
5782 /* UINT_SIZE is a Uint giving the specified size for an object of GNU_TYPE
5783 corresponding to GNAT_OBJECT. If size is valid, return a tree corresponding
5784 to its value. Otherwise return 0. KIND is VAR_DECL is we are specifying
5785 the size for an object, TYPE_DECL for the size of a type, and FIELD_DECL
5786 for the size of a field. COMPONENT_P is true if we are being called
5787 to process the Component_Size of GNAT_OBJECT. This is used for error
5788 message handling and to indicate to use the object size of GNU_TYPE.
5789 ZERO_OK is nonzero if a size of zero is permitted; if ZERO_OK is zero,
5790 it means that a size of zero should be treated as an unspecified size. */
5793 validate_size (Uint uint_size
, tree gnu_type
, Entity_Id gnat_object
,
5794 enum tree_code kind
, int component_p
, int zero_ok
)
5796 Node_Id gnat_error_node
;
5798 = kind
== VAR_DECL
? TYPE_SIZE (gnu_type
) : rm_size (gnu_type
);
5801 /* Find the node to use for errors. */
5802 if ((Ekind (gnat_object
) == E_Component
5803 || Ekind (gnat_object
) == E_Discriminant
)
5804 && Present (Component_Clause (gnat_object
)))
5805 gnat_error_node
= Last_Bit (Component_Clause (gnat_object
));
5806 else if (Present (Size_Clause (gnat_object
)))
5807 gnat_error_node
= Expression (Size_Clause (gnat_object
));
5809 gnat_error_node
= gnat_object
;
5811 /* Return 0 if no size was specified, either because Esize was not Present or
5812 the specified size was zero. */
5813 if (No (uint_size
) || uint_size
== No_Uint
)
5816 /* Get the size as a tree. Give an error if a size was specified, but cannot
5817 be represented as in sizetype. */
5818 size
= UI_To_gnu (uint_size
, bitsizetype
);
5819 if (TREE_OVERFLOW (size
))
5821 post_error_ne (component_p
? "component size of & is too large"
5822 : "size of & is too large",
5823 gnat_error_node
, gnat_object
);
5826 /* Ignore a negative size since that corresponds to our back-annotation.
5827 Also ignore a zero size unless a size clause exists. */
5828 else if (tree_int_cst_sgn (size
) < 0 || (integer_zerop (size
) && ! zero_ok
))
5831 /* The size of objects is always a multiple of a byte. */
5832 if (kind
== VAR_DECL
5833 && ! integer_zerop (size_binop (TRUNC_MOD_EXPR
, size
,
5834 bitsize_unit_node
)))
5837 post_error_ne ("component size for& is not a multiple of Storage_Unit",
5838 gnat_error_node
, gnat_object
);
5840 post_error_ne ("size for& is not a multiple of Storage_Unit",
5841 gnat_error_node
, gnat_object
);
5845 /* If this is an integral type or a packed array type, the front-end has
5846 verified the size, so we need not do it here (which would entail
5847 checking against the bounds). However, if this is an aliased object, it
5848 may not be smaller than the type of the object. */
5849 if ((INTEGRAL_TYPE_P (gnu_type
) || TYPE_IS_PACKED_ARRAY_TYPE_P (gnu_type
))
5850 && ! (kind
== VAR_DECL
&& Is_Aliased (gnat_object
)))
5853 /* If the object is a record that contains a template, add the size of
5854 the template to the specified size. */
5855 if (TREE_CODE (gnu_type
) == RECORD_TYPE
5856 && TYPE_CONTAINS_TEMPLATE_P (gnu_type
))
5857 size
= size_binop (PLUS_EXPR
, DECL_SIZE (TYPE_FIELDS (gnu_type
)), size
);
5859 /* Modify the size of the type to be that of the maximum size if it has a
5860 discriminant or the size of a thin pointer if this is a fat pointer. */
5861 if (type_size
!= 0 && CONTAINS_PLACEHOLDER_P (type_size
))
5862 type_size
= max_size (type_size
, 1);
5863 else if (TYPE_FAT_POINTER_P (gnu_type
))
5864 type_size
= bitsize_int (POINTER_SIZE
);
5866 /* If this is an access type, the minimum size is that given by the smallest
5867 integral mode that's valid for pointers. */
5868 if (TREE_CODE (gnu_type
) == POINTER_TYPE
)
5870 enum machine_mode p_mode
;
5872 for (p_mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
5873 !targetm
.valid_pointer_mode (p_mode
);
5874 p_mode
= GET_MODE_WIDER_MODE (p_mode
))
5877 type_size
= bitsize_int (GET_MODE_BITSIZE (p_mode
));
5880 /* If the size of the object is a constant, the new size must not be
5882 if (TREE_CODE (type_size
) != INTEGER_CST
5883 || TREE_OVERFLOW (type_size
)
5884 || tree_int_cst_lt (size
, type_size
))
5888 ("component size for& too small{, minimum allowed is ^}",
5889 gnat_error_node
, gnat_object
, type_size
);
5891 post_error_ne_tree ("size for& too small{, minimum allowed is ^}",
5892 gnat_error_node
, gnat_object
, type_size
);
5894 if (kind
== VAR_DECL
&& ! component_p
5895 && TREE_CODE (rm_size (gnu_type
)) == INTEGER_CST
5896 && ! tree_int_cst_lt (size
, rm_size (gnu_type
)))
5897 post_error_ne_tree_2
5898 ("\\size of ^ is not a multiple of alignment (^ bits)",
5899 gnat_error_node
, gnat_object
, rm_size (gnu_type
),
5900 TYPE_ALIGN (gnu_type
));
5902 else if (INTEGRAL_TYPE_P (gnu_type
))
5903 post_error_ne ("\\size would be legal if & were not aliased!",
5904 gnat_error_node
, gnat_object
);
5912 /* Similarly, but both validate and process a value of RM_Size. This
5913 routine is only called for types. */
5916 set_rm_size (Uint uint_size
, tree gnu_type
, Entity_Id gnat_entity
)
5918 /* Only give an error if a Value_Size clause was explicitly given.
5919 Otherwise, we'd be duplicating an error on the Size clause. */
5920 Node_Id gnat_attr_node
5921 = Get_Attribute_Definition_Clause (gnat_entity
, Attr_Value_Size
);
5922 tree old_size
= rm_size (gnu_type
);
5925 /* Get the size as a tree. Do nothing if none was specified, either
5926 because RM_Size was not Present or if the specified size was zero.
5927 Give an error if a size was specified, but cannot be represented as
5929 if (No (uint_size
) || uint_size
== No_Uint
)
5932 size
= UI_To_gnu (uint_size
, bitsizetype
);
5933 if (TREE_OVERFLOW (size
))
5935 if (Present (gnat_attr_node
))
5936 post_error_ne ("Value_Size of & is too large", gnat_attr_node
,
5942 /* Ignore a negative size since that corresponds to our back-annotation.
5943 Also ignore a zero size unless a size clause exists, a Value_Size
5944 clause exists, or this is an integer type, in which case the
5945 front end will have always set it. */
5946 else if (tree_int_cst_sgn (size
) < 0
5947 || (integer_zerop (size
) && No (gnat_attr_node
)
5948 && ! Has_Size_Clause (gnat_entity
)
5949 && ! Is_Discrete_Or_Fixed_Point_Type (gnat_entity
)))
5952 /* If the old size is self-referential, get the maximum size. */
5953 if (CONTAINS_PLACEHOLDER_P (old_size
))
5954 old_size
= max_size (old_size
, 1);
5956 /* If the size of the object is a constant, the new size must not be
5957 smaller (the front end checks this for scalar types). */
5958 if (TREE_CODE (old_size
) != INTEGER_CST
5959 || TREE_OVERFLOW (old_size
)
5960 || (AGGREGATE_TYPE_P (gnu_type
)
5961 && tree_int_cst_lt (size
, old_size
)))
5963 if (Present (gnat_attr_node
))
5965 ("Value_Size for& too small{, minimum allowed is ^}",
5966 gnat_attr_node
, gnat_entity
, old_size
);
5971 /* Otherwise, set the RM_Size. */
5972 if (TREE_CODE (gnu_type
) == INTEGER_TYPE
5973 && Is_Discrete_Or_Fixed_Point_Type (gnat_entity
))
5974 TYPE_RM_SIZE_INT (gnu_type
) = size
;
5975 else if (TREE_CODE (gnu_type
) == ENUMERAL_TYPE
)
5976 SET_TYPE_RM_SIZE_ENUM (gnu_type
, size
);
5977 else if ((TREE_CODE (gnu_type
) == RECORD_TYPE
5978 || TREE_CODE (gnu_type
) == UNION_TYPE
5979 || TREE_CODE (gnu_type
) == QUAL_UNION_TYPE
)
5980 && ! TYPE_IS_FAT_POINTER_P (gnu_type
))
5981 SET_TYPE_ADA_SIZE (gnu_type
, size
);
5984 /* Given a type TYPE, return a new type whose size is appropriate for SIZE.
5985 If TYPE is the best type, return it. Otherwise, make a new type. We
5986 only support new integral and pointer types. BIASED_P is nonzero if
5987 we are making a biased type. */
5990 make_type_from_size (tree type
, tree size_tree
, int biased_p
)
5993 unsigned HOST_WIDE_INT size
;
5995 /* If size indicates an error, just return TYPE to avoid propagating the
5996 error. Likewise if it's too large to represent. */
5997 if (size_tree
== 0 || ! host_integerp (size_tree
, 1))
6000 size
= tree_low_cst (size_tree
, 1);
6001 switch (TREE_CODE (type
))
6005 /* Only do something if the type is not already the proper size and is
6006 not a packed array type. */
6007 if (TYPE_PACKED_ARRAY_TYPE_P (type
)
6008 || (TYPE_PRECISION (type
) == size
6009 && biased_p
== (TREE_CODE (type
) == INTEGER_CST
6010 && TYPE_BIASED_REPRESENTATION_P (type
))))
6013 size
= MIN (size
, LONG_LONG_TYPE_SIZE
);
6014 new_type
= make_signed_type (size
);
6015 TREE_TYPE (new_type
)
6016 = TREE_TYPE (type
) != 0 ? TREE_TYPE (type
) : type
;
6017 TYPE_MIN_VALUE (new_type
)
6018 = convert (TREE_TYPE (new_type
), TYPE_MIN_VALUE (type
));
6019 TYPE_MAX_VALUE (new_type
)
6020 = convert (TREE_TYPE (new_type
), TYPE_MAX_VALUE (type
));
6021 TYPE_BIASED_REPRESENTATION_P (new_type
)
6022 = ((TREE_CODE (type
) == INTEGER_TYPE
6023 && TYPE_BIASED_REPRESENTATION_P (type
))
6025 TYPE_UNSIGNED (new_type
)
6026 = TYPE_UNSIGNED (type
) | TYPE_BIASED_REPRESENTATION_P (new_type
);
6027 TYPE_RM_SIZE_INT (new_type
) = bitsize_int (size
);
6031 /* Do something if this is a fat pointer, in which case we
6032 may need to return the thin pointer. */
6033 if (TYPE_IS_FAT_POINTER_P (type
) && size
< POINTER_SIZE
* 2)
6036 (TYPE_OBJECT_RECORD_TYPE (TYPE_UNCONSTRAINED_ARRAY (type
)));
6040 /* Only do something if this is a thin pointer, in which case we
6041 may need to return the fat pointer. */
6042 if (TYPE_THIN_POINTER_P (type
) && size
>= POINTER_SIZE
* 2)
6044 build_pointer_type (TYPE_UNCONSTRAINED_ARRAY (TREE_TYPE (type
)));
6055 /* ALIGNMENT is a Uint giving the alignment specified for GNAT_ENTITY,
6056 a type or object whose present alignment is ALIGN. If this alignment is
6057 valid, return it. Otherwise, give an error and return ALIGN. */
6060 validate_alignment (Uint alignment
, Entity_Id gnat_entity
, unsigned int align
)
6062 Node_Id gnat_error_node
= gnat_entity
;
6063 unsigned int new_align
;
6065 #ifndef MAX_OFILE_ALIGNMENT
6066 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
6069 if (Present (Alignment_Clause (gnat_entity
)))
6070 gnat_error_node
= Expression (Alignment_Clause (gnat_entity
));
6072 /* Don't worry about checking alignment if alignment was not specified
6073 by the source program and we already posted an error for this entity. */
6075 if (Error_Posted (gnat_entity
) && !Has_Alignment_Clause (gnat_entity
))
6078 /* Within GCC, an alignment is an integer, so we must make sure a
6079 value is specified that fits in that range. Also, alignments of
6080 more than MAX_OFILE_ALIGNMENT can't be supported. */
6082 if (! UI_Is_In_Int_Range (alignment
)
6083 || ((new_align
= UI_To_Int (alignment
))
6084 > MAX_OFILE_ALIGNMENT
/ BITS_PER_UNIT
))
6085 post_error_ne_num ("largest supported alignment for& is ^",
6086 gnat_error_node
, gnat_entity
,
6087 MAX_OFILE_ALIGNMENT
/ BITS_PER_UNIT
);
6088 else if (! (Present (Alignment_Clause (gnat_entity
))
6089 && From_At_Mod (Alignment_Clause (gnat_entity
)))
6090 && new_align
* BITS_PER_UNIT
< align
)
6091 post_error_ne_num ("alignment for& must be at least ^",
6092 gnat_error_node
, gnat_entity
,
6093 align
/ BITS_PER_UNIT
);
6095 align
= MAX (align
, new_align
== 0 ? 1 : new_align
* BITS_PER_UNIT
);
6100 /* Verify that OBJECT, a type or decl, is something we can implement
6101 atomically. If not, give an error for GNAT_ENTITY. COMP_P is nonzero
6102 if we require atomic components. */
6105 check_ok_for_atomic (tree object
, Entity_Id gnat_entity
, int comp_p
)
6107 Node_Id gnat_error_point
= gnat_entity
;
6109 enum machine_mode mode
;
6113 /* There are three case of what OBJECT can be. It can be a type, in which
6114 case we take the size, alignment and mode from the type. It can be a
6115 declaration that was indirect, in which case the relevant values are
6116 that of the type being pointed to, or it can be a normal declaration,
6117 in which case the values are of the decl. The code below assumes that
6118 OBJECT is either a type or a decl. */
6119 if (TYPE_P (object
))
6121 mode
= TYPE_MODE (object
);
6122 align
= TYPE_ALIGN (object
);
6123 size
= TYPE_SIZE (object
);
6125 else if (DECL_BY_REF_P (object
))
6127 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (object
)));
6128 align
= TYPE_ALIGN (TREE_TYPE (TREE_TYPE (object
)));
6129 size
= TYPE_SIZE (TREE_TYPE (TREE_TYPE (object
)));
6133 mode
= DECL_MODE (object
);
6134 align
= DECL_ALIGN (object
);
6135 size
= DECL_SIZE (object
);
6138 /* Consider all floating-point types atomic and any types that that are
6139 represented by integers no wider than a machine word. */
6140 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
6141 || ((GET_MODE_CLASS (mode
) == MODE_INT
6142 || GET_MODE_CLASS (mode
) == MODE_PARTIAL_INT
)
6143 && GET_MODE_BITSIZE (mode
) <= BITS_PER_WORD
))
6146 /* For the moment, also allow anything that has an alignment equal
6147 to its size and which is smaller than a word. */
6148 if (size
!= 0 && TREE_CODE (size
) == INTEGER_CST
6149 && compare_tree_int (size
, align
) == 0
6150 && align
<= BITS_PER_WORD
)
6153 for (gnat_node
= First_Rep_Item (gnat_entity
); Present (gnat_node
);
6154 gnat_node
= Next_Rep_Item (gnat_node
))
6156 if (! comp_p
&& Nkind (gnat_node
) == N_Pragma
6157 && Get_Pragma_Id (Chars (gnat_node
)) == Pragma_Atomic
)
6158 gnat_error_point
= First (Pragma_Argument_Associations (gnat_node
));
6159 else if (comp_p
&& Nkind (gnat_node
) == N_Pragma
6160 && (Get_Pragma_Id (Chars (gnat_node
))
6161 == Pragma_Atomic_Components
))
6162 gnat_error_point
= First (Pragma_Argument_Associations (gnat_node
));
6166 post_error_ne ("atomic access to component of & cannot be guaranteed",
6167 gnat_error_point
, gnat_entity
);
6169 post_error_ne ("atomic access to & cannot be guaranteed",
6170 gnat_error_point
, gnat_entity
);
6173 /* Given a type T, a FIELD_DECL F, and a replacement value R,
6174 return a new type with all size expressions that contain F
6175 updated by replacing F with R. This is identical to GCC's
6176 substitute_in_type except that it knows about TYPE_INDEX_TYPE.
6177 If F is NULL_TREE, always make a new RECORD_TYPE, even if nothing has
6181 gnat_substitute_in_type (tree t
, tree f
, tree r
)
6186 switch (TREE_CODE (t
))
6192 if (CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (t
))
6193 || CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (t
)))
6195 tree low
= substitute_in_expr (TYPE_MIN_VALUE (t
), f
, r
);
6196 tree high
= substitute_in_expr (TYPE_MAX_VALUE (t
), f
, r
);
6198 if (low
== TYPE_MIN_VALUE (t
) && high
== TYPE_MAX_VALUE (t
))
6201 new = build_range_type (TREE_TYPE (t
), low
, high
);
6202 if (TYPE_INDEX_TYPE (t
))
6203 SET_TYPE_INDEX_TYPE (new,
6204 gnat_substitute_in_type (TYPE_INDEX_TYPE (t
), f
, r
));
6211 if ((TYPE_MIN_VALUE (t
) != 0
6212 && CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (t
)))
6213 || (TYPE_MAX_VALUE (t
) != 0
6214 && CONTAINS_PLACEHOLDER_P (TYPE_MAX_VALUE (t
))))
6216 tree low
= 0, high
= 0;
6218 if (TYPE_MIN_VALUE (t
))
6219 low
= substitute_in_expr (TYPE_MIN_VALUE (t
), f
, r
);
6220 if (TYPE_MAX_VALUE (t
))
6221 high
= substitute_in_expr (TYPE_MAX_VALUE (t
), f
, r
);
6223 if (low
== TYPE_MIN_VALUE (t
) && high
== TYPE_MAX_VALUE (t
))
6227 TYPE_MIN_VALUE (t
) = low
;
6228 TYPE_MAX_VALUE (t
) = high
;
6233 tem
= gnat_substitute_in_type (TREE_TYPE (t
), f
, r
);
6234 if (tem
== TREE_TYPE (t
))
6237 return build_complex_type (tem
);
6245 /* Don't know how to do these yet. */
6250 tree component
= gnat_substitute_in_type (TREE_TYPE (t
), f
, r
);
6251 tree domain
= gnat_substitute_in_type (TYPE_DOMAIN (t
), f
, r
);
6253 if (component
== TREE_TYPE (t
) && domain
== TYPE_DOMAIN (t
))
6256 new = build_array_type (component
, domain
);
6257 TYPE_SIZE (new) = 0;
6258 TYPE_MULTI_ARRAY_P (new) = TYPE_MULTI_ARRAY_P (t
);
6259 TYPE_CONVENTION_FORTRAN_P (new) = TYPE_CONVENTION_FORTRAN_P (t
);
6261 TYPE_ALIGN (new) = TYPE_ALIGN (t
);
6267 case QUAL_UNION_TYPE
:
6271 = (f
== NULL_TREE
&& ! TREE_CONSTANT (TYPE_SIZE (t
)));
6272 int field_has_rep
= 0;
6273 tree last_field
= 0;
6275 tree
new = copy_type (t
);
6277 /* Start out with no fields, make new fields, and chain them
6278 in. If we haven't actually changed the type of any field,
6279 discard everything we've done and return the old type. */
6281 TYPE_FIELDS (new) = 0;
6282 TYPE_SIZE (new) = 0;
6284 for (field
= TYPE_FIELDS (t
); field
;
6285 field
= TREE_CHAIN (field
))
6287 tree new_field
= copy_node (field
);
6289 TREE_TYPE (new_field
)
6290 = gnat_substitute_in_type (TREE_TYPE (new_field
), f
, r
);
6292 if (DECL_HAS_REP_P (field
) && ! DECL_INTERNAL_P (field
))
6294 else if (TREE_TYPE (new_field
) != TREE_TYPE (field
))
6297 /* If this is an internal field and the type of this field is
6298 a UNION_TYPE or RECORD_TYPE with no elements, ignore it. If
6299 the type just has one element, treat that as the field.
6300 But don't do this if we are processing a QUAL_UNION_TYPE. */
6301 if (TREE_CODE (t
) != QUAL_UNION_TYPE
6302 && DECL_INTERNAL_P (new_field
)
6303 && (TREE_CODE (TREE_TYPE (new_field
)) == UNION_TYPE
6304 || TREE_CODE (TREE_TYPE (new_field
)) == RECORD_TYPE
))
6306 if (TYPE_FIELDS (TREE_TYPE (new_field
)) == 0)
6309 if (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (new_field
))) == 0)
6312 = copy_node (TYPE_FIELDS (TREE_TYPE (new_field
)));
6314 /* Make sure omitting the union doesn't change
6316 DECL_ALIGN (next_new_field
) = DECL_ALIGN (new_field
);
6317 new_field
= next_new_field
;
6321 DECL_CONTEXT (new_field
) = new;
6322 SET_DECL_ORIGINAL_FIELD (new_field
,
6323 (DECL_ORIGINAL_FIELD (field
) != 0
6324 ? DECL_ORIGINAL_FIELD (field
) : field
));
6326 /* If the size of the old field was set at a constant,
6327 propagate the size in case the type's size was variable.
6328 (This occurs in the case of a variant or discriminated
6329 record with a default size used as a field of another
6331 DECL_SIZE (new_field
)
6332 = TREE_CODE (DECL_SIZE (field
)) == INTEGER_CST
6333 ? DECL_SIZE (field
) : 0;
6334 DECL_SIZE_UNIT (new_field
)
6335 = TREE_CODE (DECL_SIZE_UNIT (field
)) == INTEGER_CST
6336 ? DECL_SIZE_UNIT (field
) : 0;
6338 if (TREE_CODE (t
) == QUAL_UNION_TYPE
)
6340 tree new_q
= substitute_in_expr (DECL_QUALIFIER (field
), f
, r
);
6342 if (new_q
!= DECL_QUALIFIER (new_field
))
6345 /* Do the substitution inside the qualifier and if we find
6346 that this field will not be present, omit it. */
6347 DECL_QUALIFIER (new_field
) = new_q
;
6349 if (integer_zerop (DECL_QUALIFIER (new_field
)))
6353 if (last_field
== 0)
6354 TYPE_FIELDS (new) = new_field
;
6356 TREE_CHAIN (last_field
) = new_field
;
6358 last_field
= new_field
;
6360 /* If this is a qualified type and this field will always be
6361 present, we are done. */
6362 if (TREE_CODE (t
) == QUAL_UNION_TYPE
6363 && integer_onep (DECL_QUALIFIER (new_field
)))
6367 /* If this used to be a qualified union type, but we now know what
6368 field will be present, make this a normal union. */
6369 if (changed_field
&& TREE_CODE (new) == QUAL_UNION_TYPE
6370 && (TYPE_FIELDS (new) == 0
6371 || integer_onep (DECL_QUALIFIER (TYPE_FIELDS (new)))))
6372 TREE_SET_CODE (new, UNION_TYPE
);
6373 else if (! changed_field
)
6381 /* If the size was originally a constant use it. */
6382 if (TYPE_SIZE (t
) != 0 && TREE_CODE (TYPE_SIZE (t
)) == INTEGER_CST
6383 && TREE_CODE (TYPE_SIZE (new)) != INTEGER_CST
)
6385 TYPE_SIZE (new) = TYPE_SIZE (t
);
6386 TYPE_SIZE_UNIT (new) = TYPE_SIZE_UNIT (t
);
6387 SET_TYPE_ADA_SIZE (new, TYPE_ADA_SIZE (t
));
6398 /* Return the "RM size" of GNU_TYPE. This is the actual number of bits
6399 needed to represent the object. */
6402 rm_size (tree gnu_type
)
6404 /* For integer types, this is the precision. For record types, we store
6405 the size explicitly. For other types, this is just the size. */
6407 if (INTEGRAL_TYPE_P (gnu_type
) && TYPE_RM_SIZE (gnu_type
) != 0)
6408 return TYPE_RM_SIZE (gnu_type
);
6409 else if (TREE_CODE (gnu_type
) == RECORD_TYPE
6410 && TYPE_CONTAINS_TEMPLATE_P (gnu_type
))
6411 /* Return the rm_size of the actual data plus the size of the template. */
6413 size_binop (PLUS_EXPR
,
6414 rm_size (TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (gnu_type
)))),
6415 DECL_SIZE (TYPE_FIELDS (gnu_type
)));
6416 else if ((TREE_CODE (gnu_type
) == RECORD_TYPE
6417 || TREE_CODE (gnu_type
) == UNION_TYPE
6418 || TREE_CODE (gnu_type
) == QUAL_UNION_TYPE
)
6419 && ! TYPE_IS_FAT_POINTER_P (gnu_type
)
6420 && TYPE_ADA_SIZE (gnu_type
) != 0)
6421 return TYPE_ADA_SIZE (gnu_type
);
6423 return TYPE_SIZE (gnu_type
);
6426 /* Return an identifier representing the external name to be used for
6427 GNAT_ENTITY. If SUFFIX is specified, the name is followed by "___"
6428 and the specified suffix. */
6431 create_concat_name (Entity_Id gnat_entity
, const char *suffix
)
6433 const char *str
= (suffix
== 0 ? "" : suffix
);
6434 String_Template temp
= {1, strlen (str
)};
6435 Fat_Pointer fp
= {str
, &temp
};
6437 Get_External_Name_With_Suffix (gnat_entity
, fp
);
6440 /* A variable using the Stdcall convention (meaning we are running
6441 on a Windows box) live in a DLL. Here we adjust its name to use
6442 the jump-table, the _imp__NAME contains the address for the NAME
6446 Entity_Kind kind
= Ekind (gnat_entity
);
6447 const char *prefix
= "_imp__";
6448 int plen
= strlen (prefix
);
6450 if ((kind
== E_Variable
|| kind
== E_Constant
)
6451 && Convention (gnat_entity
) == Convention_Stdcall
)
6454 for (k
= 0; k
<= Name_Len
; k
++)
6455 Name_Buffer
[Name_Len
- k
+ plen
] = Name_Buffer
[Name_Len
- k
];
6456 strncpy (Name_Buffer
, prefix
, plen
);
6461 return get_identifier (Name_Buffer
);
6464 /* Return the name to be used for GNAT_ENTITY. If a type, create a
6465 fully-qualified name, possibly with type information encoding.
6466 Otherwise, return the name. */
6469 get_entity_name (Entity_Id gnat_entity
)
6471 Get_Encoded_Name (gnat_entity
);
6472 return get_identifier (Name_Buffer
);
6475 /* Given GNU_ID, an IDENTIFIER_NODE containing a name and SUFFIX, a
6476 string, return a new IDENTIFIER_NODE that is the concatenation of
6477 the name in GNU_ID and SUFFIX. */
6480 concat_id_with_name (tree gnu_id
, const char *suffix
)
6482 int len
= IDENTIFIER_LENGTH (gnu_id
);
6484 strncpy (Name_Buffer
, IDENTIFIER_POINTER (gnu_id
),
6485 IDENTIFIER_LENGTH (gnu_id
));
6486 strncpy (Name_Buffer
+ len
, "___", 3);
6488 strcpy (Name_Buffer
+ len
, suffix
);
6489 return get_identifier (Name_Buffer
);
6492 #include "gt-ada-decl.h"