Mercurial > hg > CbC > CbC_gcc
comparison gcc/ada/gcc-interface/decl.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
4 * * | 4 * * |
5 * D E C L * | 5 * D E C L * |
6 * * | 6 * * |
7 * C Implementation File * | 7 * C Implementation File * |
8 * * | 8 * * |
9 * Copyright (C) 1992-2018, Free Software Foundation, Inc. * | 9 * Copyright (C) 1992-2019, Free Software Foundation, Inc. * |
10 * * | 10 * * |
11 * GNAT is free software; you can redistribute it and/or modify it under * | 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- * | 12 * terms of the GNU General Public License as published by the Free Soft- * |
13 * ware Foundation; either version 3, or (at your option) any later ver- * | 13 * ware Foundation; either version 3, or (at your option) any later ver- * |
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- * | 14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- * |
83 (MAIN_STACK_BOUNDARY < PREFERRED_STACK_BOUNDARY) | 83 (MAIN_STACK_BOUNDARY < PREFERRED_STACK_BOUNDARY) |
84 #else | 84 #else |
85 #define FOREIGN_FORCE_REALIGN_STACK 0 | 85 #define FOREIGN_FORCE_REALIGN_STACK 0 |
86 #endif | 86 #endif |
87 | 87 |
88 /* The largest TYPE_ARRAY_MAX_SIZE value we set on an array type. | |
89 It's an artibrary limit (256 MB) above which we consider that | |
90 the allocation is essentially unbounded. */ | |
91 | |
92 #define TYPE_ARRAY_SIZE_LIMIT (1 << 28) | |
93 | |
88 struct incomplete | 94 struct incomplete |
89 { | 95 { |
90 struct incomplete *next; | 96 struct incomplete *next; |
91 tree old_type; | 97 tree old_type; |
92 Entity_Id full_type; | 98 Entity_Id full_type; |
194 enum attrib_type, tree, tree, Node_Id); | 200 enum attrib_type, tree, tree, Node_Id); |
195 static void prepend_one_attribute_pragma (struct attrib **, Node_Id); | 201 static void prepend_one_attribute_pragma (struct attrib **, Node_Id); |
196 static void prepend_attributes (struct attrib **, Entity_Id); | 202 static void prepend_attributes (struct attrib **, Entity_Id); |
197 static tree elaborate_expression (Node_Id, Entity_Id, const char *, bool, bool, | 203 static tree elaborate_expression (Node_Id, Entity_Id, const char *, bool, bool, |
198 bool); | 204 bool); |
199 static bool type_has_variable_size (tree); | |
200 static tree elaborate_expression_1 (tree, Entity_Id, const char *, bool, bool); | 205 static tree elaborate_expression_1 (tree, Entity_Id, const char *, bool, bool); |
201 static tree elaborate_expression_2 (tree, Entity_Id, const char *, bool, bool, | 206 static tree elaborate_expression_2 (tree, Entity_Id, const char *, bool, bool, |
202 unsigned int); | 207 unsigned int); |
203 static tree elaborate_reference (tree, Entity_Id, bool, tree *); | 208 static tree elaborate_reference (tree, Entity_Id, bool, tree *); |
204 static tree gnat_to_gnu_component_type (Entity_Id, bool, bool); | 209 static tree gnat_to_gnu_component_type (Entity_Id, bool, bool); |
205 static tree gnat_to_gnu_subprog_type (Entity_Id, bool, bool, tree *); | 210 static tree gnat_to_gnu_subprog_type (Entity_Id, bool, bool, tree *); |
206 static int adjust_packed (tree, tree, int); | 211 static int adjust_packed (tree, tree, int); |
207 static tree gnat_to_gnu_field (Entity_Id, tree, int, bool, bool); | 212 static tree gnat_to_gnu_field (Entity_Id, tree, int, bool, bool); |
213 static enum inline_status_t inline_status_for_subprog (Entity_Id); | |
208 static tree gnu_ext_name_for_subprog (Entity_Id, tree); | 214 static tree gnu_ext_name_for_subprog (Entity_Id, tree); |
209 static void set_nonaliased_component_on_array_type (tree); | 215 static void set_nonaliased_component_on_array_type (tree); |
210 static void set_reverse_storage_order_on_array_type (tree); | 216 static void set_reverse_storage_order_on_array_type (tree); |
211 static bool same_discriminant_p (Entity_Id, Entity_Id); | 217 static bool same_discriminant_p (Entity_Id, Entity_Id); |
212 static bool array_type_has_nonaliased_component (tree, Entity_Id); | 218 static bool array_type_has_nonaliased_component (tree, Entity_Id); |
213 static bool compile_time_known_address_p (Node_Id); | 219 static bool compile_time_known_address_p (Node_Id); |
214 static bool cannot_be_superflat (Node_Id); | 220 static bool cannot_be_superflat (Node_Id); |
215 static bool constructor_address_p (tree); | 221 static bool constructor_address_p (tree); |
216 static bool allocatable_size_p (tree, bool); | 222 static bool allocatable_size_p (tree, bool); |
217 static bool initial_value_needs_conversion (tree, tree); | 223 static bool initial_value_needs_conversion (tree, tree); |
224 static tree update_n_elem (tree, tree, tree); | |
218 static int compare_field_bitpos (const PTR, const PTR); | 225 static int compare_field_bitpos (const PTR, const PTR); |
219 static bool components_to_record (Node_Id, Entity_Id, tree, tree, int, bool, | 226 static bool components_to_record (Node_Id, Entity_Id, tree, tree, int, bool, |
220 bool, bool, bool, bool, bool, bool, tree, | 227 bool, bool, bool, bool, bool, bool, tree, |
221 tree *); | 228 tree *); |
222 static Uint annotate_value (tree); | 229 static Uint annotate_value (tree); |
223 static void annotate_rep (Entity_Id, tree); | 230 static void annotate_rep (Entity_Id, tree); |
224 static tree build_position_list (tree, bool, tree, tree, unsigned int, tree); | 231 static tree build_position_list (tree, bool, tree, tree, unsigned int, tree); |
225 static vec<subst_pair> build_subst_list (Entity_Id, Entity_Id, bool); | 232 static vec<subst_pair> build_subst_list (Entity_Id, Entity_Id, bool); |
226 static vec<variant_desc> build_variant_list (tree, vec<subst_pair>, | 233 static vec<variant_desc> build_variant_list (tree, vec<subst_pair>, |
227 vec<variant_desc>); | 234 vec<variant_desc>); |
228 static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool); | 235 static tree maybe_saturate_size (tree); |
236 static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool, | |
237 const char *, const char *); | |
229 static void set_rm_size (Uint, tree, Entity_Id); | 238 static void set_rm_size (Uint, tree, Entity_Id); |
230 static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); | 239 static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); |
231 static unsigned int promote_object_alignment (tree, Entity_Id); | 240 static unsigned int promote_object_alignment (tree, Entity_Id); |
232 static void check_ok_for_atomic_type (tree, Entity_Id, bool); | 241 static void check_ok_for_atomic_type (tree, Entity_Id, bool); |
233 static tree create_field_decl_from (tree, tree, tree, tree, tree, | 242 static tree create_field_decl_from (tree, tree, tree, tree, tree, |
284 = (Is_Imported (gnat_entity) && No (Address_Clause (gnat_entity))); | 293 = (Is_Imported (gnat_entity) && No (Address_Clause (gnat_entity))); |
285 /* True if this entity has a foreign convention. */ | 294 /* True if this entity has a foreign convention. */ |
286 const bool foreign = Has_Foreign_Convention (gnat_entity); | 295 const bool foreign = Has_Foreign_Convention (gnat_entity); |
287 /* For a type, contains the equivalent GNAT node to be used in gigi. */ | 296 /* For a type, contains the equivalent GNAT node to be used in gigi. */ |
288 Entity_Id gnat_equiv_type = Empty; | 297 Entity_Id gnat_equiv_type = Empty; |
298 /* For a type, contains the GNAT node to be used for back-annotation. */ | |
299 Entity_Id gnat_annotate_type = Empty; | |
289 /* Temporary used to walk the GNAT tree. */ | 300 /* Temporary used to walk the GNAT tree. */ |
290 Entity_Id gnat_temp; | 301 Entity_Id gnat_temp; |
291 /* Contains the GCC DECL node which is equivalent to the input GNAT node. | 302 /* Contains the GCC DECL node which is equivalent to the input GNAT node. |
292 This node will be associated with the GNAT node by calling at the end | 303 This node will be associated with the GNAT node by calling at the end |
293 of the `switch' statement. */ | 304 of the `switch' statement. */ |
296 tree gnu_type = NULL_TREE; | 307 tree gnu_type = NULL_TREE; |
297 /* Contains the GCC size tree to be used for the GCC node. */ | 308 /* Contains the GCC size tree to be used for the GCC node. */ |
298 tree gnu_size = NULL_TREE; | 309 tree gnu_size = NULL_TREE; |
299 /* Contains the GCC name to be used for the GCC node. */ | 310 /* Contains the GCC name to be used for the GCC node. */ |
300 tree gnu_entity_name; | 311 tree gnu_entity_name; |
301 /* True if we have already saved gnu_decl as a GNAT association. */ | 312 /* True if we have already saved gnu_decl as a GNAT association. This can |
313 also be used to purposely avoid making such an association but this use | |
314 case ought not to be applied to types because it can break the deferral | |
315 mechanism implemented for access types. */ | |
302 bool saved = false; | 316 bool saved = false; |
303 /* True if we incremented defer_incomplete_level. */ | 317 /* True if we incremented defer_incomplete_level. */ |
304 bool this_deferred = false; | 318 bool this_deferred = false; |
305 /* True if we incremented force_global. */ | 319 /* True if we incremented force_global. */ |
306 bool this_global = false; | 320 bool this_global = false; |
313 /* Contains the list of attributes directly attached to the entity. */ | 327 /* Contains the list of attributes directly attached to the entity. */ |
314 struct attrib *attr_list = NULL; | 328 struct attrib *attr_list = NULL; |
315 | 329 |
316 /* Since a use of an Itype is a definition, process it as such if it is in | 330 /* Since a use of an Itype is a definition, process it as such if it is in |
317 the main unit, except for E_Access_Subtype because it's actually a use | 331 the main unit, except for E_Access_Subtype because it's actually a use |
318 of its base type, and for E_Record_Subtype with cloned subtype because | 332 of its base type, see below. */ |
319 it's actually a use of the cloned subtype, see below. */ | |
320 if (!definition | 333 if (!definition |
321 && is_type | 334 && is_type |
322 && Is_Itype (gnat_entity) | 335 && Is_Itype (gnat_entity) |
323 && !(kind == E_Access_Subtype | 336 && Ekind (gnat_entity) != E_Access_Subtype |
324 || (kind == E_Record_Subtype | |
325 && Present (Cloned_Subtype (gnat_entity)))) | |
326 && !present_gnu_tree (gnat_entity) | 337 && !present_gnu_tree (gnat_entity) |
327 && In_Extended_Main_Code_Unit (gnat_entity)) | 338 && In_Extended_Main_Code_Unit (gnat_entity)) |
328 { | 339 { |
329 /* Ensure that we are in a subprogram mentioned in the Scope chain of | 340 /* Ensure that we are in a subprogram mentioned in the Scope chain of |
330 this entity, our current scope is global, or we encountered a task | 341 this entity, our current scope is global, or we encountered a task |
363 return get_gnu_tree (gnat_entity); | 374 return get_gnu_tree (gnat_entity); |
364 } | 375 } |
365 } | 376 } |
366 | 377 |
367 /* This abort means the Itype has an incorrect scope, i.e. that its | 378 /* This abort means the Itype has an incorrect scope, i.e. that its |
368 scope does not correspond to the subprogram it is declared in. */ | 379 scope does not correspond to the subprogram it is first used in. */ |
369 gcc_unreachable (); | 380 gcc_unreachable (); |
370 } | 381 } |
371 | 382 |
372 /* If we've already processed this entity, return what we got last time. | 383 /* If we've already processed this entity, return what we got last time. |
373 If we are defining the node, we should not have already processed it. | 384 If we are defining the node, we should not have already processed it. |
374 In that case, we will abort below when we try to save a new GCC tree | 385 In that case, we will abort below when we try to save a new GCC tree |
375 for this object. We also need to handle the case of getting a dummy | 386 for this object. We also need to handle the case of getting a dummy |
376 type when a Full_View exists but be careful so as not to trigger its | 387 type when a Full_View exists but be careful so as not to trigger its |
377 premature elaboration. */ | 388 premature elaboration. Likewise for a cloned subtype without its own |
389 freeze node, which typically happens when a generic gets instantiated | |
390 on an incomplete or private type. */ | |
378 if ((!definition || (is_type && imported_p)) | 391 if ((!definition || (is_type && imported_p)) |
379 && present_gnu_tree (gnat_entity)) | 392 && present_gnu_tree (gnat_entity)) |
380 { | 393 { |
381 gnu_decl = get_gnu_tree (gnat_entity); | 394 gnu_decl = get_gnu_tree (gnat_entity); |
382 | 395 |
386 && Present (Full_View (gnat_entity)) | 399 && Present (Full_View (gnat_entity)) |
387 && (present_gnu_tree (Full_View (gnat_entity)) | 400 && (present_gnu_tree (Full_View (gnat_entity)) |
388 || No (Freeze_Node (Full_View (gnat_entity))))) | 401 || No (Freeze_Node (Full_View (gnat_entity))))) |
389 { | 402 { |
390 gnu_decl | 403 gnu_decl |
391 = gnat_to_gnu_entity (Full_View (gnat_entity), NULL_TREE, false); | 404 = gnat_to_gnu_entity (Full_View (gnat_entity), NULL_TREE, |
405 false); | |
406 save_gnu_tree (gnat_entity, NULL_TREE, false); | |
407 save_gnu_tree (gnat_entity, gnu_decl, false); | |
408 } | |
409 | |
410 if (TREE_CODE (gnu_decl) == TYPE_DECL | |
411 && TYPE_IS_DUMMY_P (TREE_TYPE (gnu_decl)) | |
412 && Ekind (gnat_entity) == E_Record_Subtype | |
413 && No (Freeze_Node (gnat_entity)) | |
414 && Present (Cloned_Subtype (gnat_entity)) | |
415 && (present_gnu_tree (Cloned_Subtype (gnat_entity)) | |
416 || No (Freeze_Node (Cloned_Subtype (gnat_entity))))) | |
417 { | |
418 gnu_decl | |
419 = gnat_to_gnu_entity (Cloned_Subtype (gnat_entity), NULL_TREE, | |
420 false); | |
392 save_gnu_tree (gnat_entity, NULL_TREE, false); | 421 save_gnu_tree (gnat_entity, NULL_TREE, false); |
393 save_gnu_tree (gnat_entity, gnu_decl, false); | 422 save_gnu_tree (gnat_entity, gnu_decl, false); |
394 } | 423 } |
395 | 424 |
396 return gnu_decl; | 425 return gnu_decl; |
417 | 446 |
418 /* If we get here, it means we have not yet done anything with this entity. | 447 /* If we get here, it means we have not yet done anything with this entity. |
419 If we are not defining it, it must be a type or an entity that is defined | 448 If we are not defining it, it must be a type or an entity that is defined |
420 elsewhere or externally, otherwise we should have defined it already. */ | 449 elsewhere or externally, otherwise we should have defined it already. */ |
421 gcc_assert (definition | 450 gcc_assert (definition |
422 || type_annotate_only | |
423 || is_type | 451 || is_type |
424 || kind == E_Discriminant | 452 || kind == E_Discriminant |
425 || kind == E_Component | 453 || kind == E_Component |
426 || kind == E_Label | 454 || kind == E_Label |
427 || (kind == E_Constant && Present (Full_View (gnat_entity))) | 455 || (kind == E_Constant && Present (Full_View (gnat_entity))) |
428 || Is_Public (gnat_entity)); | 456 || Is_Public (gnat_entity) |
457 || type_annotate_only); | |
429 | 458 |
430 /* Get the name of the entity and set up the line number and filename of | 459 /* Get the name of the entity and set up the line number and filename of |
431 the original definition for use in any decl we make. Make sure we do | 460 the original definition for use in any decl we make. Make sure we do |
432 not inherit another source location. */ | 461 not inherit another source location. */ |
433 gnu_entity_name = get_entity_name (gnat_entity); | 462 gnu_entity_name = get_entity_name (gnat_entity); |
554 /* Here we have no GCC type and this is a reference rather than a | 583 /* Here we have no GCC type and this is a reference rather than a |
555 definition. This should never happen. Most likely the cause is | 584 definition. This should never happen. Most likely the cause is |
556 reference before declaration in the GNAT tree for gnat_entity. */ | 585 reference before declaration in the GNAT tree for gnat_entity. */ |
557 gcc_unreachable (); | 586 gcc_unreachable (); |
558 } | 587 } |
588 | |
589 case E_Named_Integer: | |
590 case E_Named_Real: | |
591 { | |
592 tree gnu_ext_name = NULL_TREE; | |
593 | |
594 if (Is_Public (gnat_entity)) | |
595 gnu_ext_name = create_concat_name (gnat_entity, NULL); | |
596 | |
597 /* All references are supposed to be folded in the front-end. */ | |
598 gcc_assert (definition && gnu_expr); | |
599 | |
600 gnu_type = gnat_to_gnu_type (Etype (gnat_entity)); | |
601 gnu_expr = convert (gnu_type, gnu_expr); | |
602 | |
603 /* Build a CONST_DECL for debugging purposes exclusively. */ | |
604 gnu_decl | |
605 = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, | |
606 gnu_expr, true, Is_Public (gnat_entity), | |
607 false, false, false, artificial_p, | |
608 debug_info_p, NULL, gnat_entity, true); | |
609 } | |
610 break; | |
559 | 611 |
560 case E_Constant: | 612 case E_Constant: |
561 /* Ignore constant definitions already marked with the error node. See | 613 /* Ignore constant definitions already marked with the error node. See |
562 the N_Object_Declaration case of gnat_to_gnu for the rationale. */ | 614 the N_Object_Declaration case of gnat_to_gnu for the rationale. */ |
563 if (definition | 615 if (definition |
727 | 779 |
728 /* Likewise, if a size is specified, use it if valid. */ | 780 /* Likewise, if a size is specified, use it if valid. */ |
729 if (Known_Esize (gnat_entity)) | 781 if (Known_Esize (gnat_entity)) |
730 gnu_size | 782 gnu_size |
731 = validate_size (Esize (gnat_entity), gnu_type, gnat_entity, | 783 = validate_size (Esize (gnat_entity), gnu_type, gnat_entity, |
732 VAR_DECL, false, Has_Size_Clause (gnat_entity)); | 784 VAR_DECL, false, Has_Size_Clause (gnat_entity), |
785 NULL, NULL); | |
733 if (gnu_size) | 786 if (gnu_size) |
734 { | 787 { |
735 gnu_type | 788 gnu_type |
736 = make_type_from_size (gnu_type, gnu_size, | 789 = make_type_from_size (gnu_type, gnu_size, |
737 Has_Biased_Representation (gnat_entity)); | 790 Has_Biased_Representation (gnat_entity)); |
1489 SET_DECL_RENAMED_OBJECT (gnu_decl, renamed_obj); | 1542 SET_DECL_RENAMED_OBJECT (gnu_decl, renamed_obj); |
1490 | 1543 |
1491 /* If this is a constant and we are defining it or it generates a real | 1544 /* If this is a constant and we are defining it or it generates a real |
1492 symbol at the object level and we are referencing it, we may want | 1545 symbol at the object level and we are referencing it, we may want |
1493 or need to have a true variable to represent it: | 1546 or need to have a true variable to represent it: |
1494 - if optimization isn't enabled, for debugging purposes, | |
1495 - if the constant is public and not overlaid on something else, | 1547 - if the constant is public and not overlaid on something else, |
1496 - if its address is taken, | 1548 - if its address is taken, |
1497 - if either itself or its type is aliased. */ | 1549 - if it is aliased, |
1550 - if optimization isn't enabled, for debugging purposes. */ | |
1498 if (TREE_CODE (gnu_decl) == CONST_DECL | 1551 if (TREE_CODE (gnu_decl) == CONST_DECL |
1499 && (definition || Sloc (gnat_entity) > Standard_Location) | 1552 && (definition || Sloc (gnat_entity) > Standard_Location) |
1500 && ((!optimize && debug_info_p) | 1553 && ((Is_Public (gnat_entity) && No (Address_Clause (gnat_entity))) |
1501 || (Is_Public (gnat_entity) | |
1502 && No (Address_Clause (gnat_entity))) | |
1503 || Address_Taken (gnat_entity) | 1554 || Address_Taken (gnat_entity) |
1504 || Is_Aliased (gnat_entity) | 1555 || Is_Aliased (gnat_entity) |
1505 || Is_Aliased (gnat_type))) | 1556 || (!optimize && debug_info_p))) |
1506 { | 1557 { |
1507 tree gnu_corr_var | 1558 tree gnu_corr_var |
1508 = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, | 1559 = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, |
1509 gnu_expr, true, Is_Public (gnat_entity), | 1560 gnu_expr, true, Is_Public (gnat_entity), |
1510 !definition, static_flag, volatile_flag, | 1561 !definition, static_flag, volatile_flag, |
1511 artificial_p, debug_info_p && definition, | 1562 artificial_p, debug_info_p && definition, |
1512 attr_list, gnat_entity, false); | 1563 attr_list, gnat_entity, false); |
1513 | 1564 |
1514 SET_DECL_CONST_CORRESPONDING_VAR (gnu_decl, gnu_corr_var); | 1565 SET_DECL_CONST_CORRESPONDING_VAR (gnu_decl, gnu_corr_var); |
1566 DECL_IGNORED_P (gnu_decl) = 1; | |
1515 } | 1567 } |
1516 | 1568 |
1517 /* If this is a constant, even if we don't need a true variable, we | 1569 /* If this is a constant, even if we don't need a true variable, we |
1518 may need to avoid returning the initializer in every case. That | 1570 may need to avoid returning the initializer in every case. That |
1519 can happen for the address of a (constant) constructor because, | 1571 can happen for the address of a (constant) constructor because, |
1728 } | 1780 } |
1729 goto discrete_type; | 1781 goto discrete_type; |
1730 | 1782 |
1731 case E_Modular_Integer_Type: | 1783 case E_Modular_Integer_Type: |
1732 { | 1784 { |
1785 /* Packed Array Impl. Types are supposed to be subtypes only. */ | |
1786 gcc_assert (!Is_Packed_Array_Impl_Type (gnat_entity)); | |
1787 | |
1733 /* For modular types, make the unsigned type of the proper number | 1788 /* For modular types, make the unsigned type of the proper number |
1734 of bits and then set up the modulus, if required. */ | 1789 of bits and then set up the modulus, if required. */ |
1735 tree gnu_modulus, gnu_high = NULL_TREE; | |
1736 | |
1737 /* Packed Array Impl. Types are supposed to be subtypes only. */ | |
1738 gcc_assert (!Is_Packed_Array_Impl_Type (gnat_entity)); | |
1739 | |
1740 gnu_type = make_unsigned_type (esize); | 1790 gnu_type = make_unsigned_type (esize); |
1741 | 1791 |
1742 /* Get the modulus in this type. If it overflows, assume it is because | 1792 /* Get the modulus in this type. If the modulus overflows, assume |
1743 it is equal to 2**Esize. Note that there is no overflow checking | 1793 that this is because it was equal to 2**Esize. Note that there |
1744 done on unsigned type, so we detect the overflow by looking for | 1794 is no overflow checking done on unsigned types, so we detect the |
1745 a modulus of zero, which is otherwise invalid. */ | 1795 overflow by looking for a modulus of zero, which is invalid. */ |
1746 gnu_modulus = UI_To_gnu (Modulus (gnat_entity), gnu_type); | 1796 tree gnu_modulus = UI_To_gnu (Modulus (gnat_entity), gnu_type); |
1747 | 1797 |
1798 /* If the modulus is not 2**Esize, then this also means that the upper | |
1799 bound of the type, i.e. modulus - 1, is not maximal, so we create an | |
1800 extra subtype to carry it and set the modulus on the base type. */ | |
1748 if (!integer_zerop (gnu_modulus)) | 1801 if (!integer_zerop (gnu_modulus)) |
1749 { | 1802 { |
1803 TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "UMT"); | |
1750 TYPE_MODULAR_P (gnu_type) = 1; | 1804 TYPE_MODULAR_P (gnu_type) = 1; |
1751 SET_TYPE_MODULUS (gnu_type, gnu_modulus); | 1805 SET_TYPE_MODULUS (gnu_type, gnu_modulus); |
1752 gnu_high = fold_build2 (MINUS_EXPR, gnu_type, gnu_modulus, | 1806 tree gnu_high = fold_build2 (MINUS_EXPR, gnu_type, gnu_modulus, |
1753 build_int_cst (gnu_type, 1)); | 1807 build_int_cst (gnu_type, 1)); |
1754 } | 1808 gnu_type |
1755 | 1809 = create_extra_subtype (gnu_type, TYPE_MIN_VALUE (gnu_type), |
1756 /* If the upper bound is not maximal, make an extra subtype. */ | 1810 gnu_high); |
1757 if (gnu_high | |
1758 && !tree_int_cst_equal (gnu_high, TYPE_MAX_VALUE (gnu_type))) | |
1759 { | |
1760 tree gnu_subtype = make_unsigned_type (esize); | |
1761 SET_TYPE_RM_MAX_VALUE (gnu_subtype, gnu_high); | |
1762 TREE_TYPE (gnu_subtype) = gnu_type; | |
1763 TYPE_EXTRA_SUBTYPE_P (gnu_subtype) = 1; | |
1764 TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "UMT"); | |
1765 gnu_type = gnu_subtype; | |
1766 } | 1811 } |
1767 } | 1812 } |
1768 goto discrete_type; | 1813 goto discrete_type; |
1769 | 1814 |
1770 case E_Signed_Integer_Subtype: | 1815 case E_Signed_Integer_Subtype: |
1845 if (TREE_CODE (gnu_type) == INTEGER_TYPE) | 1890 if (TREE_CODE (gnu_type) == INTEGER_TYPE) |
1846 TYPE_BIASED_REPRESENTATION_P (gnu_type) | 1891 TYPE_BIASED_REPRESENTATION_P (gnu_type) |
1847 = Has_Biased_Representation (gnat_entity); | 1892 = Has_Biased_Representation (gnat_entity); |
1848 | 1893 |
1849 /* Do the same processing for Character subtypes as for types. */ | 1894 /* Do the same processing for Character subtypes as for types. */ |
1850 if (TYPE_STRING_FLAG (TREE_TYPE (gnu_type))) | 1895 if (TREE_CODE (TREE_TYPE (gnu_type)) == INTEGER_TYPE |
1896 && TYPE_STRING_FLAG (TREE_TYPE (gnu_type))) | |
1851 { | 1897 { |
1852 TYPE_NAME (gnu_type) = gnu_entity_name; | 1898 TYPE_NAME (gnu_type) = gnu_entity_name; |
1853 TYPE_STRING_FLAG (gnu_type) = 1; | 1899 TYPE_STRING_FLAG (gnu_type) = 1; |
1854 TYPE_ARTIFICIAL (gnu_type) = artificial_p; | 1900 TYPE_ARTIFICIAL (gnu_type) = artificial_p; |
1855 finish_character_type (gnu_type); | 1901 finish_character_type (gnu_type); |
2047 tree gnu_template_type; | 2093 tree gnu_template_type; |
2048 tree gnu_ptr_template; | 2094 tree gnu_ptr_template; |
2049 tree gnu_template_reference, gnu_template_fields, gnu_fat_type; | 2095 tree gnu_template_reference, gnu_template_fields, gnu_fat_type; |
2050 tree *gnu_index_types = XALLOCAVEC (tree, ndim); | 2096 tree *gnu_index_types = XALLOCAVEC (tree, ndim); |
2051 tree *gnu_temp_fields = XALLOCAVEC (tree, ndim); | 2097 tree *gnu_temp_fields = XALLOCAVEC (tree, ndim); |
2052 tree gnu_max_size = size_one_node, gnu_max_size_unit, tem, t; | 2098 tree gnu_max_size = size_one_node, tem, t; |
2053 Entity_Id gnat_index, gnat_name; | 2099 Entity_Id gnat_index, gnat_name; |
2054 int index; | 2100 int index; |
2055 tree comp_type; | 2101 tree comp_type; |
2056 | 2102 |
2057 /* Create the type for the component now, as it simplifies breaking | 2103 /* Create the type for the component now, as it simplifies breaking |
2160 index += (convention_fortran_p ? - 1 : 1), | 2206 index += (convention_fortran_p ? - 1 : 1), |
2161 gnat_index = Next_Index (gnat_index)) | 2207 gnat_index = Next_Index (gnat_index)) |
2162 { | 2208 { |
2163 char field_name[16]; | 2209 char field_name[16]; |
2164 tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); | 2210 tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); |
2165 tree gnu_index_base_type | 2211 tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type); |
2166 = maybe_character_type (get_base_type (gnu_index_type)); | 2212 tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type); |
2167 tree gnu_lb_field, gnu_hb_field, gnu_orig_min, gnu_orig_max; | 2213 tree gnu_index_base_type = get_base_type (gnu_index_type); |
2214 tree gnu_lb_field, gnu_hb_field; | |
2168 tree gnu_min, gnu_max, gnu_high; | 2215 tree gnu_min, gnu_max, gnu_high; |
2216 | |
2217 /* Update the maximum size of the array in elements. */ | |
2218 if (gnu_max_size) | |
2219 gnu_max_size | |
2220 = update_n_elem (gnu_max_size, gnu_orig_min, gnu_orig_max); | |
2221 | |
2222 /* Now build the self-referential bounds of the index type. */ | |
2223 gnu_index_type = maybe_character_type (gnu_index_type); | |
2224 gnu_index_base_type = maybe_character_type (gnu_index_base_type); | |
2169 | 2225 |
2170 /* Make the FIELD_DECLs for the low and high bounds of this | 2226 /* Make the FIELD_DECLs for the low and high bounds of this |
2171 type and then make extractions of these fields from the | 2227 type and then make extractions of these fields from the |
2172 template. */ | 2228 template. */ |
2173 sprintf (field_name, "LB%d", index); | 2229 sprintf (field_name, "LB%d", index); |
2174 gnu_lb_field = create_field_decl (get_identifier (field_name), | 2230 gnu_lb_field = create_field_decl (get_identifier (field_name), |
2175 gnu_index_base_type, | 2231 gnu_index_type, |
2176 gnu_template_type, NULL_TREE, | 2232 gnu_template_type, NULL_TREE, |
2177 NULL_TREE, 0, 0); | 2233 NULL_TREE, 0, 0); |
2178 Sloc_to_locus (Sloc (gnat_entity), | 2234 Sloc_to_locus (Sloc (gnat_entity), |
2179 &DECL_SOURCE_LOCATION (gnu_lb_field)); | 2235 &DECL_SOURCE_LOCATION (gnu_lb_field)); |
2180 | 2236 |
2181 field_name[0] = 'U'; | 2237 field_name[0] = 'U'; |
2182 gnu_hb_field = create_field_decl (get_identifier (field_name), | 2238 gnu_hb_field = create_field_decl (get_identifier (field_name), |
2183 gnu_index_base_type, | 2239 gnu_index_type, |
2184 gnu_template_type, NULL_TREE, | 2240 gnu_template_type, NULL_TREE, |
2185 NULL_TREE, 0, 0); | 2241 NULL_TREE, 0, 0); |
2186 Sloc_to_locus (Sloc (gnat_entity), | 2242 Sloc_to_locus (Sloc (gnat_entity), |
2187 &DECL_SOURCE_LOCATION (gnu_hb_field)); | 2243 &DECL_SOURCE_LOCATION (gnu_hb_field)); |
2188 | 2244 |
2189 gnu_temp_fields[index] = chainon (gnu_lb_field, gnu_hb_field); | 2245 gnu_temp_fields[index] = chainon (gnu_lb_field, gnu_hb_field); |
2190 | 2246 |
2191 /* We can't use build_component_ref here since the template type | 2247 /* We can't use build_component_ref here since the template type |
2192 isn't complete yet. */ | 2248 isn't complete yet. */ |
2193 gnu_orig_min = build3 (COMPONENT_REF, gnu_index_base_type, | 2249 gnu_orig_min = build3 (COMPONENT_REF, TREE_TYPE (gnu_lb_field), |
2194 gnu_template_reference, gnu_lb_field, | 2250 gnu_template_reference, gnu_lb_field, |
2195 NULL_TREE); | 2251 NULL_TREE); |
2196 gnu_orig_max = build3 (COMPONENT_REF, gnu_index_base_type, | 2252 gnu_orig_max = build3 (COMPONENT_REF, TREE_TYPE (gnu_hb_field), |
2197 gnu_template_reference, gnu_hb_field, | 2253 gnu_template_reference, gnu_hb_field, |
2198 NULL_TREE); | 2254 NULL_TREE); |
2199 TREE_READONLY (gnu_orig_min) = TREE_READONLY (gnu_orig_max) = 1; | 2255 TREE_READONLY (gnu_orig_min) = TREE_READONLY (gnu_orig_max) = 1; |
2200 | 2256 |
2201 gnu_min = convert (sizetype, gnu_orig_min); | 2257 gnu_min = convert (sizetype, gnu_orig_min); |
2216 = create_index_type (gnu_min, gnu_high, | 2272 = create_index_type (gnu_min, gnu_high, |
2217 create_range_type (gnu_index_base_type, | 2273 create_range_type (gnu_index_base_type, |
2218 gnu_orig_min, | 2274 gnu_orig_min, |
2219 gnu_orig_max), | 2275 gnu_orig_max), |
2220 gnat_entity); | 2276 gnat_entity); |
2221 | |
2222 /* Update the maximum size of the array in elements. */ | |
2223 if (gnu_max_size) | |
2224 { | |
2225 tree gnu_min | |
2226 = convert (sizetype, TYPE_MIN_VALUE (gnu_index_type)); | |
2227 tree gnu_max | |
2228 = convert (sizetype, TYPE_MAX_VALUE (gnu_index_type)); | |
2229 tree gnu_this_max | |
2230 = size_binop (PLUS_EXPR, size_one_node, | |
2231 size_binop (MINUS_EXPR, gnu_max, gnu_min)); | |
2232 | |
2233 if (TREE_CODE (gnu_this_max) == INTEGER_CST | |
2234 && TREE_OVERFLOW (gnu_this_max)) | |
2235 gnu_max_size = NULL_TREE; | |
2236 else | |
2237 gnu_max_size | |
2238 = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max); | |
2239 } | |
2240 | 2277 |
2241 TYPE_NAME (gnu_index_types[index]) | 2278 TYPE_NAME (gnu_index_types[index]) |
2242 = create_concat_name (gnat_entity, field_name); | 2279 = create_concat_name (gnat_entity, field_name); |
2243 } | 2280 } |
2244 | 2281 |
2257 size of the component. */ | 2294 size of the component. */ |
2258 if (Unknown_Component_Size (gnat_entity)) | 2295 if (Unknown_Component_Size (gnat_entity)) |
2259 Set_Component_Size (gnat_entity, | 2296 Set_Component_Size (gnat_entity, |
2260 annotate_value (TYPE_SIZE (comp_type))); | 2297 annotate_value (TYPE_SIZE (comp_type))); |
2261 | 2298 |
2262 /* Compute the maximum size of the array in units and bits. */ | 2299 /* Compute the maximum size of the array in units. */ |
2263 if (gnu_max_size) | 2300 if (gnu_max_size) |
2264 { | 2301 gnu_max_size |
2265 gnu_max_size_unit = size_binop (MULT_EXPR, gnu_max_size, | 2302 = size_binop (MULT_EXPR, gnu_max_size, TYPE_SIZE_UNIT (comp_type)); |
2266 TYPE_SIZE_UNIT (comp_type)); | |
2267 gnu_max_size = size_binop (MULT_EXPR, | |
2268 convert (bitsizetype, gnu_max_size), | |
2269 TYPE_SIZE (comp_type)); | |
2270 } | |
2271 else | |
2272 gnu_max_size_unit = NULL_TREE; | |
2273 | 2303 |
2274 /* Now build the array type. */ | 2304 /* Now build the array type. */ |
2275 tem = comp_type; | 2305 tem = comp_type; |
2276 for (index = ndim - 1; index >= 0; index--) | 2306 for (index = ndim - 1; index >= 0; index--) |
2277 { | 2307 { |
2324 | 2354 |
2325 /* If the maximum size doesn't overflow, use it. */ | 2355 /* If the maximum size doesn't overflow, use it. */ |
2326 if (gnu_max_size | 2356 if (gnu_max_size |
2327 && TREE_CODE (gnu_max_size) == INTEGER_CST | 2357 && TREE_CODE (gnu_max_size) == INTEGER_CST |
2328 && !TREE_OVERFLOW (gnu_max_size) | 2358 && !TREE_OVERFLOW (gnu_max_size) |
2329 && TREE_CODE (gnu_max_size_unit) == INTEGER_CST | 2359 && compare_tree_int (gnu_max_size, TYPE_ARRAY_SIZE_LIMIT) <= 0) |
2330 && !TREE_OVERFLOW (gnu_max_size_unit)) | 2360 TYPE_ARRAY_MAX_SIZE (tem) = gnu_max_size; |
2331 { | |
2332 TYPE_SIZE (tem) = size_binop (MIN_EXPR, gnu_max_size, | |
2333 TYPE_SIZE (tem)); | |
2334 TYPE_SIZE_UNIT (tem) = size_binop (MIN_EXPR, gnu_max_size_unit, | |
2335 TYPE_SIZE_UNIT (tem)); | |
2336 } | |
2337 | 2361 |
2338 create_type_decl (create_concat_name (gnat_entity, "XUA"), tem, | 2362 create_type_decl (create_concat_name (gnat_entity, "XUA"), tem, |
2339 artificial_p, debug_info_p, gnat_entity); | 2363 artificial_p, debug_info_p, gnat_entity); |
2340 | 2364 |
2341 /* If told to generate GNAT encodings for them (GDB rely on them at the | 2365 /* If told to generate GNAT encodings for them (GDB rely on them at the |
2395 const bool convention_fortran_p | 2419 const bool convention_fortran_p |
2396 = (Convention (gnat_entity) == Convention_Fortran); | 2420 = (Convention (gnat_entity) == Convention_Fortran); |
2397 const int ndim = Number_Dimensions (gnat_entity); | 2421 const int ndim = Number_Dimensions (gnat_entity); |
2398 tree gnu_base_type = gnu_type; | 2422 tree gnu_base_type = gnu_type; |
2399 tree *gnu_index_types = XALLOCAVEC (tree, ndim); | 2423 tree *gnu_index_types = XALLOCAVEC (tree, ndim); |
2400 tree gnu_max_size = size_one_node, gnu_max_size_unit; | 2424 tree gnu_max_size = size_one_node; |
2401 bool need_index_type_struct = false; | 2425 bool need_index_type_struct = false; |
2402 int index; | 2426 int index; |
2403 | 2427 |
2404 /* First create the GCC type for each index and find out whether | 2428 /* First create the GCC type for each index and find out whether |
2405 special types are needed for debugging information. */ | 2429 special types are needed for debugging information. */ |
2411 index += (convention_fortran_p ? - 1 : 1), | 2435 index += (convention_fortran_p ? - 1 : 1), |
2412 gnat_index = Next_Index (gnat_index), | 2436 gnat_index = Next_Index (gnat_index), |
2413 gnat_base_index = Next_Index (gnat_base_index)) | 2437 gnat_base_index = Next_Index (gnat_base_index)) |
2414 { | 2438 { |
2415 tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); | 2439 tree gnu_index_type = get_unpadded_type (Etype (gnat_index)); |
2416 tree gnu_index_base_type | 2440 tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type); |
2417 = maybe_character_type (get_base_type (gnu_index_type)); | 2441 tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type); |
2418 tree gnu_orig_min | 2442 tree gnu_index_base_type = get_base_type (gnu_index_type); |
2419 = convert (gnu_index_base_type, | |
2420 TYPE_MIN_VALUE (gnu_index_type)); | |
2421 tree gnu_orig_max | |
2422 = convert (gnu_index_base_type, | |
2423 TYPE_MAX_VALUE (gnu_index_type)); | |
2424 tree gnu_min = convert (sizetype, gnu_orig_min); | |
2425 tree gnu_max = convert (sizetype, gnu_orig_max); | |
2426 tree gnu_base_index_type | 2443 tree gnu_base_index_type |
2427 = get_unpadded_type (Etype (gnat_base_index)); | 2444 = get_unpadded_type (Etype (gnat_base_index)); |
2428 tree gnu_base_index_base_type | 2445 tree gnu_base_orig_min = TYPE_MIN_VALUE (gnu_base_index_type); |
2429 = maybe_character_type (get_base_type (gnu_base_index_type)); | 2446 tree gnu_base_orig_max = TYPE_MAX_VALUE (gnu_base_index_type); |
2430 tree gnu_base_orig_min | 2447 tree gnu_min, gnu_max, gnu_high; |
2431 = convert (gnu_base_index_base_type, | 2448 |
2432 TYPE_MIN_VALUE (gnu_base_index_type)); | 2449 /* We try to define subtypes for discriminants used as bounds |
2433 tree gnu_base_orig_max | 2450 that are more restrictive than those declared by using the |
2434 = convert (gnu_base_index_base_type, | 2451 bounds of the index type of the base array type. This will |
2435 TYPE_MAX_VALUE (gnu_base_index_type)); | 2452 make it possible to calculate the maximum size of the record |
2436 tree gnu_high; | 2453 type more conservatively. This may have already been done by |
2454 the front-end (Exp_Ch3.Adjust_Discriminants), in which case | |
2455 there will be a conversion that needs to be removed first. */ | |
2456 if (CONTAINS_PLACEHOLDER_P (gnu_orig_min) | |
2457 && TYPE_RM_SIZE (gnu_base_index_type) | |
2458 && !tree_int_cst_lt (TYPE_RM_SIZE (gnu_index_type), | |
2459 TYPE_RM_SIZE (gnu_base_index_type))) | |
2460 { | |
2461 gnu_orig_min = remove_conversions (gnu_orig_min, false); | |
2462 TREE_TYPE (gnu_orig_min) | |
2463 = create_extra_subtype (TREE_TYPE (gnu_orig_min), | |
2464 gnu_base_orig_min, | |
2465 gnu_base_orig_max); | |
2466 } | |
2467 | |
2468 if (CONTAINS_PLACEHOLDER_P (gnu_orig_max) | |
2469 && TYPE_RM_SIZE (gnu_base_index_type) | |
2470 && !tree_int_cst_lt (TYPE_RM_SIZE (gnu_index_type), | |
2471 TYPE_RM_SIZE (gnu_base_index_type))) | |
2472 { | |
2473 gnu_orig_max = remove_conversions (gnu_orig_max, false); | |
2474 TREE_TYPE (gnu_orig_max) | |
2475 = create_extra_subtype (TREE_TYPE (gnu_orig_max), | |
2476 gnu_base_orig_min, | |
2477 gnu_base_orig_max); | |
2478 } | |
2479 | |
2480 /* Update the maximum size of the array in elements. Here we | |
2481 see if any constraint on the index type of the base type | |
2482 can be used in the case of self-referential bounds on the | |
2483 index type of the array type. We look for a non-"infinite" | |
2484 and non-self-referential bound from any type involved and | |
2485 handle each bound separately. */ | |
2486 if (gnu_max_size) | |
2487 { | |
2488 if (CONTAINS_PLACEHOLDER_P (gnu_orig_min)) | |
2489 gnu_min = gnu_base_orig_min; | |
2490 else | |
2491 gnu_min = gnu_orig_min; | |
2492 | |
2493 if (TREE_CODE (gnu_min) != INTEGER_CST | |
2494 || TREE_OVERFLOW (gnu_min)) | |
2495 gnu_min = TYPE_MIN_VALUE (TREE_TYPE (gnu_min)); | |
2496 | |
2497 if (CONTAINS_PLACEHOLDER_P (gnu_orig_max)) | |
2498 gnu_max = gnu_base_orig_max; | |
2499 else | |
2500 gnu_max = gnu_orig_max; | |
2501 | |
2502 if (TREE_CODE (gnu_max) != INTEGER_CST | |
2503 || TREE_OVERFLOW (gnu_max)) | |
2504 gnu_max = TYPE_MAX_VALUE (TREE_TYPE (gnu_max)); | |
2505 | |
2506 gnu_max_size | |
2507 = update_n_elem (gnu_max_size, gnu_min, gnu_max); | |
2508 } | |
2509 | |
2510 /* Convert the bounds to the base type for consistency below. */ | |
2511 gnu_index_base_type = maybe_character_type (gnu_index_base_type); | |
2512 gnu_orig_min = convert (gnu_index_base_type, gnu_orig_min); | |
2513 gnu_orig_max = convert (gnu_index_base_type, gnu_orig_max); | |
2514 | |
2515 gnu_min = convert (sizetype, gnu_orig_min); | |
2516 gnu_max = convert (sizetype, gnu_orig_max); | |
2437 | 2517 |
2438 /* See if the base array type is already flat. If it is, we | 2518 /* See if the base array type is already flat. If it is, we |
2439 are probably compiling an ACATS test but it will cause the | 2519 are probably compiling an ACATS test but it will cause the |
2440 code below to malfunction if we don't handle it specially. */ | 2520 code below to malfunction if we don't handle it specially. */ |
2441 if (TREE_CODE (gnu_base_orig_min) == INTEGER_CST | 2521 if (TREE_CODE (gnu_base_orig_min) == INTEGER_CST |
2465 else if (TREE_CODE (gnu_min) == INTEGER_CST | 2545 else if (TREE_CODE (gnu_min) == INTEGER_CST |
2466 && TREE_CODE (gnu_max) == INTEGER_CST | 2546 && TREE_CODE (gnu_max) == INTEGER_CST |
2467 && TREE_OVERFLOW (gnu_min) && TREE_OVERFLOW (gnu_max) | 2547 && TREE_OVERFLOW (gnu_min) && TREE_OVERFLOW (gnu_max) |
2468 && !TREE_OVERFLOW | 2548 && !TREE_OVERFLOW |
2469 (convert (sizetype, | 2549 (convert (sizetype, |
2470 fold_build2 (MINUS_EXPR, gnu_index_type, | 2550 fold_build2 (MINUS_EXPR, |
2551 gnu_index_base_type, | |
2471 gnu_orig_max, | 2552 gnu_orig_max, |
2472 gnu_orig_min)))) | 2553 gnu_orig_min)))) |
2473 { | 2554 { |
2474 TREE_OVERFLOW (gnu_min) = 0; | 2555 TREE_OVERFLOW (gnu_min) = 0; |
2475 TREE_OVERFLOW (gnu_max) = 0; | 2556 TREE_OVERFLOW (gnu_max) = 0; |
2507 int_const_binop (PLUS_EXPR, gnu_max, | 2588 int_const_binop (PLUS_EXPR, gnu_max, |
2508 size_one_node)); | 2589 size_one_node)); |
2509 } | 2590 } |
2510 | 2591 |
2511 /* Finally we use (hb >= lb) ? hb : lb - 1 for the upper bound | 2592 /* Finally we use (hb >= lb) ? hb : lb - 1 for the upper bound |
2512 in all the other cases. Note that, here as well as above, | 2593 in all the other cases. Note that we use int_const_binop for |
2513 the condition used in the comparison must be equivalent to | 2594 the shift by 1 if the bound is constant to avoid any unwanted |
2514 the condition (length != 0). This is relied upon in order | 2595 overflow. */ |
2515 to optimize array comparisons in compare_arrays. Moreover | |
2516 we use int_const_binop for the shift by 1 if the bound is | |
2517 constant to avoid any unwanted overflow. */ | |
2518 else | 2596 else |
2519 gnu_high | 2597 gnu_high |
2520 = build_cond_expr (sizetype, | 2598 = build_cond_expr (sizetype, |
2521 build_binary_op (GE_EXPR, | 2599 build_binary_op (GE_EXPR, |
2522 boolean_type_node, | 2600 boolean_type_node, |
2532 /* Reuse the index type for the range type. Then make an index | 2610 /* Reuse the index type for the range type. Then make an index |
2533 type with the size range in sizetype. */ | 2611 type with the size range in sizetype. */ |
2534 gnu_index_types[index] | 2612 gnu_index_types[index] |
2535 = create_index_type (gnu_min, gnu_high, gnu_index_type, | 2613 = create_index_type (gnu_min, gnu_high, gnu_index_type, |
2536 gnat_entity); | 2614 gnat_entity); |
2537 | |
2538 /* Update the maximum size of the array in elements. Here we | |
2539 see if any constraint on the index type of the base type | |
2540 can be used in the case of self-referential bound on the | |
2541 index type of the subtype. We look for a non-"infinite" | |
2542 and non-self-referential bound from any type involved and | |
2543 handle each bound separately. */ | |
2544 if (gnu_max_size) | |
2545 { | |
2546 tree gnu_base_min = convert (sizetype, gnu_base_orig_min); | |
2547 tree gnu_base_max = convert (sizetype, gnu_base_orig_max); | |
2548 tree gnu_base_base_min | |
2549 = convert (sizetype, | |
2550 TYPE_MIN_VALUE (gnu_base_index_base_type)); | |
2551 tree gnu_base_base_max | |
2552 = convert (sizetype, | |
2553 TYPE_MAX_VALUE (gnu_base_index_base_type)); | |
2554 | |
2555 if (!CONTAINS_PLACEHOLDER_P (gnu_min) | |
2556 || !(TREE_CODE (gnu_base_min) == INTEGER_CST | |
2557 && !TREE_OVERFLOW (gnu_base_min))) | |
2558 gnu_base_min = gnu_min; | |
2559 | |
2560 if (!CONTAINS_PLACEHOLDER_P (gnu_max) | |
2561 || !(TREE_CODE (gnu_base_max) == INTEGER_CST | |
2562 && !TREE_OVERFLOW (gnu_base_max))) | |
2563 gnu_base_max = gnu_max; | |
2564 | |
2565 if ((TREE_CODE (gnu_base_min) == INTEGER_CST | |
2566 && TREE_OVERFLOW (gnu_base_min)) | |
2567 || operand_equal_p (gnu_base_min, gnu_base_base_min, 0) | |
2568 || (TREE_CODE (gnu_base_max) == INTEGER_CST | |
2569 && TREE_OVERFLOW (gnu_base_max)) | |
2570 || operand_equal_p (gnu_base_max, gnu_base_base_max, 0)) | |
2571 gnu_max_size = NULL_TREE; | |
2572 else | |
2573 { | |
2574 tree gnu_this_max; | |
2575 | |
2576 /* Use int_const_binop if the bounds are constant to | |
2577 avoid any unwanted overflow. */ | |
2578 if (TREE_CODE (gnu_base_min) == INTEGER_CST | |
2579 && TREE_CODE (gnu_base_max) == INTEGER_CST) | |
2580 gnu_this_max | |
2581 = int_const_binop (PLUS_EXPR, size_one_node, | |
2582 int_const_binop (MINUS_EXPR, | |
2583 gnu_base_max, | |
2584 gnu_base_min)); | |
2585 else | |
2586 gnu_this_max | |
2587 = size_binop (PLUS_EXPR, size_one_node, | |
2588 size_binop (MINUS_EXPR, | |
2589 gnu_base_max, | |
2590 gnu_base_min)); | |
2591 | |
2592 gnu_max_size | |
2593 = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max); | |
2594 } | |
2595 } | |
2596 | 2615 |
2597 /* We need special types for debugging information to point to | 2616 /* We need special types for debugging information to point to |
2598 the index types if they have variable bounds, are not integer | 2617 the index types if they have variable bounds, are not integer |
2599 types, are biased or are wider than sizetype. These are GNAT | 2618 types, are biased or are wider than sizetype. These are GNAT |
2600 encodings, so we have to include them only when all encodings | 2619 encodings, so we have to include them only when all encodings |
2641 maybe_present = true; | 2660 maybe_present = true; |
2642 break; | 2661 break; |
2643 } | 2662 } |
2644 } | 2663 } |
2645 | 2664 |
2646 /* Compute the maximum size of the array in units and bits. */ | 2665 /* Compute the maximum size of the array in units. */ |
2647 if (gnu_max_size) | 2666 if (gnu_max_size) |
2648 { | 2667 gnu_max_size |
2649 gnu_max_size_unit = size_binop (MULT_EXPR, gnu_max_size, | 2668 = size_binop (MULT_EXPR, gnu_max_size, TYPE_SIZE_UNIT (gnu_type)); |
2650 TYPE_SIZE_UNIT (gnu_type)); | |
2651 gnu_max_size = size_binop (MULT_EXPR, | |
2652 convert (bitsizetype, gnu_max_size), | |
2653 TYPE_SIZE (gnu_type)); | |
2654 } | |
2655 else | |
2656 gnu_max_size_unit = NULL_TREE; | |
2657 | 2669 |
2658 /* Now build the array type. */ | 2670 /* Now build the array type. */ |
2659 for (index = ndim - 1; index >= 0; index --) | 2671 for (index = ndim - 1; index >= 0; index --) |
2660 { | 2672 { |
2661 gnu_type = build_nonshared_array_type (gnu_type, | 2673 gnu_type = build_nonshared_array_type (gnu_type, |
2771 can output the appropriate description for them. */ | 2783 can output the appropriate description for them. */ |
2772 TYPE_PACKED (gnu_type) | 2784 TYPE_PACKED (gnu_type) |
2773 = (Is_Packed (gnat_entity) | 2785 = (Is_Packed (gnat_entity) |
2774 || Is_Packed_Array_Impl_Type (gnat_entity)); | 2786 || Is_Packed_Array_Impl_Type (gnat_entity)); |
2775 | 2787 |
2776 /* If the size is self-referential and the maximum size doesn't | 2788 /* If the maximum size doesn't overflow, use it. */ |
2777 overflow, use it. */ | 2789 if (gnu_max_size |
2778 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_type)) | 2790 && TREE_CODE (gnu_max_size) == INTEGER_CST |
2779 && gnu_max_size | 2791 && !TREE_OVERFLOW (gnu_max_size) |
2780 && !(TREE_CODE (gnu_max_size) == INTEGER_CST | 2792 && compare_tree_int (gnu_max_size, TYPE_ARRAY_SIZE_LIMIT) <= 0) |
2781 && TREE_OVERFLOW (gnu_max_size)) | 2793 TYPE_ARRAY_MAX_SIZE (gnu_type) = gnu_max_size; |
2782 && !(TREE_CODE (gnu_max_size_unit) == INTEGER_CST | |
2783 && TREE_OVERFLOW (gnu_max_size_unit))) | |
2784 { | |
2785 TYPE_SIZE (gnu_type) = size_binop (MIN_EXPR, gnu_max_size, | |
2786 TYPE_SIZE (gnu_type)); | |
2787 TYPE_SIZE_UNIT (gnu_type) | |
2788 = size_binop (MIN_EXPR, gnu_max_size_unit, | |
2789 TYPE_SIZE_UNIT (gnu_type)); | |
2790 } | |
2791 | 2794 |
2792 /* Set our alias set to that of our base type. This gives all | 2795 /* Set our alias set to that of our base type. This gives all |
2793 array subtypes the same alias set. */ | 2796 array subtypes the same alias set. */ |
2794 relate_alias_sets (gnu_type, gnu_base_type, ALIAS_SET_COPY); | 2797 relate_alias_sets (gnu_type, gnu_base_type, ALIAS_SET_COPY); |
2795 | 2798 |
2845 { | 2848 { |
2846 /* The TYPE_ACTUAL_BOUNDS field is overloaded with the | 2849 /* The TYPE_ACTUAL_BOUNDS field is overloaded with the |
2847 TYPE_MODULUS for modular types so we make an extra | 2850 TYPE_MODULUS for modular types so we make an extra |
2848 subtype if necessary. */ | 2851 subtype if necessary. */ |
2849 if (TYPE_MODULAR_P (gnu_inner)) | 2852 if (TYPE_MODULAR_P (gnu_inner)) |
2850 { | 2853 gnu_inner |
2851 tree gnu_subtype | 2854 = create_extra_subtype (gnu_inner, |
2852 = make_unsigned_type (TYPE_PRECISION (gnu_inner)); | 2855 TYPE_MIN_VALUE (gnu_inner), |
2853 TREE_TYPE (gnu_subtype) = gnu_inner; | 2856 TYPE_MAX_VALUE (gnu_inner)); |
2854 TYPE_EXTRA_SUBTYPE_P (gnu_subtype) = 1; | |
2855 SET_TYPE_RM_MIN_VALUE (gnu_subtype, | |
2856 TYPE_MIN_VALUE (gnu_inner)); | |
2857 SET_TYPE_RM_MAX_VALUE (gnu_subtype, | |
2858 TYPE_MAX_VALUE (gnu_inner)); | |
2859 gnu_inner = gnu_subtype; | |
2860 } | |
2861 | 2857 |
2862 TYPE_HAS_ACTUAL_BOUNDS_P (gnu_inner) = 1; | 2858 TYPE_HAS_ACTUAL_BOUNDS_P (gnu_inner) = 1; |
2863 | 2859 |
2864 /* Check for other cases of overloading. */ | 2860 /* Check for other cases of overloading. */ |
2865 gcc_checking_assert (!TYPE_ACTUAL_BOUNDS (gnu_inner)); | 2861 gcc_checking_assert (!TYPE_ACTUAL_BOUNDS (gnu_inner)); |
2979 : Component_Alignment (gnat_entity) == Calign_Storage_Unit | 2975 : Component_Alignment (gnat_entity) == Calign_Storage_Unit |
2980 ? -1 | 2976 ? -1 |
2981 : 0; | 2977 : 0; |
2982 const bool has_align = Known_Alignment (gnat_entity); | 2978 const bool has_align = Known_Alignment (gnat_entity); |
2983 const bool has_discr = Has_Discriminants (gnat_entity); | 2979 const bool has_discr = Has_Discriminants (gnat_entity); |
2984 const bool has_rep = Has_Specified_Layout (gnat_entity); | |
2985 const bool is_extension | 2980 const bool is_extension |
2986 = (Is_Tagged_Type (gnat_entity) | 2981 = (Is_Tagged_Type (gnat_entity) |
2987 && Nkind (record_definition) == N_Derived_Type_Definition); | 2982 && Nkind (record_definition) == N_Derived_Type_Definition); |
2983 const bool has_rep | |
2984 = is_extension | |
2985 ? Has_Record_Rep_Clause (gnat_entity) | |
2986 : Has_Specified_Layout (gnat_entity); | |
2988 const bool is_unchecked_union = Is_Unchecked_Union (gnat_entity); | 2987 const bool is_unchecked_union = Is_Unchecked_Union (gnat_entity); |
2989 bool all_rep = has_rep; | 2988 bool all_rep = has_rep; |
2990 | 2989 |
2991 /* See if all fields have a rep clause. Stop when we find one | 2990 /* See if all fields have a rep clause. Stop when we find one |
2992 that doesn't. */ | 2991 that doesn't. */ |
3008 { | 3007 { |
3009 if (!type_annotate_only | 3008 if (!type_annotate_only |
3010 || Present (Record_Extension_Part (record_definition))) | 3009 || Present (Record_Extension_Part (record_definition))) |
3011 record_definition = Record_Extension_Part (record_definition); | 3010 record_definition = Record_Extension_Part (record_definition); |
3012 | 3011 |
3013 gcc_assert (type_annotate_only | 3012 gcc_assert (Present (Parent_Subtype (gnat_entity)) |
3014 || Present (Parent_Subtype (gnat_entity))); | 3013 || type_annotate_only); |
3015 } | 3014 } |
3016 | 3015 |
3017 /* Make a node for the record. If we are not defining the record, | 3016 /* Make a node for the record. If we are not defining the record, |
3018 suppress expanding incomplete types. */ | 3017 suppress expanding incomplete types. */ |
3019 gnu_type = make_node (tree_code_for_record_type (gnat_entity)); | 3018 gnu_type = make_node (tree_code_for_record_type (gnat_entity)); |
3043 gnat_entity, 0)); | 3042 gnat_entity, 0)); |
3044 else | 3043 else |
3045 { | 3044 { |
3046 SET_TYPE_ALIGN (gnu_type, 0); | 3045 SET_TYPE_ALIGN (gnu_type, 0); |
3047 | 3046 |
3048 /* If a type needs strict alignment, the minimum size will be the | 3047 /* If a type needs strict alignment, then its type size will also |
3049 type size instead of the RM size (see validate_size). Cap the | 3048 be the RM size (see below). Cap the alignment if needed, lest |
3050 alignment lest it causes this type size to become too large. */ | 3049 it may cause this type size to become too large. */ |
3051 if (Strict_Alignment (gnat_entity) && Known_RM_Size (gnat_entity)) | 3050 if (Strict_Alignment (gnat_entity) && Known_RM_Size (gnat_entity)) |
3052 { | 3051 { |
3053 unsigned int max_size = UI_To_Int (RM_Size (gnat_entity)); | 3052 unsigned int max_size = UI_To_Int (RM_Size (gnat_entity)); |
3053 unsigned int max_align = max_size & -max_size; | |
3054 if (max_align < BIGGEST_ALIGNMENT) | |
3055 TYPE_MAX_ALIGN (gnu_type) = max_align; | |
3056 } | |
3057 | |
3058 /* Similarly if an Object_Size clause has been specified. */ | |
3059 else if (Known_Esize (gnat_entity)) | |
3060 { | |
3061 unsigned int max_size = UI_To_Int (Esize (gnat_entity)); | |
3054 unsigned int max_align = max_size & -max_size; | 3062 unsigned int max_align = max_size & -max_size; |
3055 if (max_align < BIGGEST_ALIGNMENT) | 3063 if (max_align < BIGGEST_ALIGNMENT) |
3056 TYPE_MAX_ALIGN (gnu_type) = max_align; | 3064 TYPE_MAX_ALIGN (gnu_type) = max_align; |
3057 } | 3065 } |
3058 } | 3066 } |
3254 if (Nkind (Node (gnat_constr)) == N_Identifier | 3262 if (Nkind (Node (gnat_constr)) == N_Identifier |
3255 /* Ignore access discriminants. */ | 3263 /* Ignore access discriminants. */ |
3256 && !Is_Access_Type (Etype (Node (gnat_constr))) | 3264 && !Is_Access_Type (Etype (Node (gnat_constr))) |
3257 && Ekind (Entity (Node (gnat_constr))) == E_Discriminant) | 3265 && Ekind (Entity (Node (gnat_constr))) == E_Discriminant) |
3258 { | 3266 { |
3259 Entity_Id gnat_discr = Entity (Node (gnat_constr)); | 3267 const Entity_Id gnat_discr = Entity (Node (gnat_constr)); |
3260 tree gnu_discr_type = gnat_to_gnu_type (Etype (gnat_discr)); | 3268 tree gnu_discr_type = gnat_to_gnu_type (Etype (gnat_discr)); |
3261 tree gnu_ref | 3269 tree gnu_ref |
3262 = gnat_to_gnu_entity (Original_Record_Component (gnat_discr), | 3270 = gnat_to_gnu_entity (Original_Record_Component (gnat_discr), |
3263 NULL_TREE, false); | 3271 NULL_TREE, false); |
3264 | 3272 |
3265 /* GNU_REF must be an expression using a PLACEHOLDER_EXPR built | 3273 /* GNU_REF must be an expression using a PLACEHOLDER_EXPR built |
3266 just above for one of the stored discriminants. */ | 3274 just above for one of the stored discriminants. */ |
3267 gcc_assert (TREE_TYPE (TREE_OPERAND (gnu_ref, 0)) == gnu_type); | 3275 gcc_assert (TREE_TYPE (TREE_OPERAND (gnu_ref, 0)) == gnu_type); |
3268 | 3276 |
3269 if (gnu_discr_type != TREE_TYPE (gnu_ref)) | 3277 if (gnu_discr_type != TREE_TYPE (gnu_ref)) |
3270 { | 3278 TREE_TYPE (gnu_ref) |
3271 const unsigned prec = TYPE_PRECISION (TREE_TYPE (gnu_ref)); | 3279 = create_extra_subtype (TREE_TYPE (gnu_ref), |
3272 tree gnu_subtype | 3280 TYPE_MIN_VALUE (gnu_discr_type), |
3273 = TYPE_UNSIGNED (TREE_TYPE (gnu_ref)) | 3281 TYPE_MAX_VALUE (gnu_discr_type)); |
3274 ? make_unsigned_type (prec) : make_signed_type (prec); | |
3275 TREE_TYPE (gnu_subtype) = TREE_TYPE (gnu_ref); | |
3276 TYPE_EXTRA_SUBTYPE_P (gnu_subtype) = 1; | |
3277 SET_TYPE_RM_MIN_VALUE (gnu_subtype, | |
3278 TYPE_MIN_VALUE (gnu_discr_type)); | |
3279 SET_TYPE_RM_MAX_VALUE (gnu_subtype, | |
3280 TYPE_MAX_VALUE (gnu_discr_type)); | |
3281 TREE_TYPE (gnu_ref) | |
3282 = TREE_TYPE (TREE_OPERAND (gnu_ref, 1)) = gnu_subtype; | |
3283 } | |
3284 } | 3282 } |
3285 | 3283 |
3286 /* If this is a derived type with discriminants and these discriminants | 3284 /* If this is a derived type with discriminants and these discriminants |
3287 affect the initial shape it has inherited, factor them in. */ | 3285 affect the initial shape it has inherited, factor them in. */ |
3288 if (has_discr | 3286 if (has_discr |
3332 TYPE_SIZE (gnu_type) = bitsize_unit_node; | 3330 TYPE_SIZE (gnu_type) = bitsize_unit_node; |
3333 TYPE_SIZE_UNIT (gnu_type) = size_one_node; | 3331 TYPE_SIZE_UNIT (gnu_type) = size_one_node; |
3334 compute_record_mode (gnu_type); | 3332 compute_record_mode (gnu_type); |
3335 } | 3333 } |
3336 | 3334 |
3335 /* If the type needs strict alignment, then no object of the type | |
3336 may have a size smaller than the natural size, which means that | |
3337 the RM size of the type is equal to the type size. */ | |
3338 if (Strict_Alignment (gnat_entity)) | |
3339 SET_TYPE_ADA_SIZE (gnu_type, TYPE_SIZE (gnu_type)); | |
3340 | |
3337 /* If there are entities in the chain corresponding to components | 3341 /* If there are entities in the chain corresponding to components |
3338 that we did not elaborate, ensure we elaborate their types if | 3342 that we did not elaborate, ensure we elaborate their types if |
3339 they are Itypes. */ | 3343 they are Itypes. */ |
3340 for (gnat_temp = First_Entity (gnat_entity); | 3344 for (gnat_temp = First_Entity (gnat_entity); |
3341 Present (gnat_temp); | 3345 Present (gnat_temp); |
3381 /* ... fall through ... */ | 3385 /* ... fall through ... */ |
3382 | 3386 |
3383 case E_Record_Subtype: | 3387 case E_Record_Subtype: |
3384 /* If Cloned_Subtype is Present it means this record subtype has | 3388 /* If Cloned_Subtype is Present it means this record subtype has |
3385 identical layout to that type or subtype and we should use | 3389 identical layout to that type or subtype and we should use |
3386 that GCC type for this one. The front end guarantees that | 3390 that GCC type for this one. The front-end guarantees that |
3387 the component list is shared. */ | 3391 the component list is shared. */ |
3388 if (Present (Cloned_Subtype (gnat_entity))) | 3392 if (Present (Cloned_Subtype (gnat_entity))) |
3389 { | 3393 { |
3390 gnu_decl = gnat_to_gnu_entity (Cloned_Subtype (gnat_entity), | 3394 gnu_decl = gnat_to_gnu_entity (Cloned_Subtype (gnat_entity), |
3391 NULL_TREE, false); | 3395 NULL_TREE, false); |
3392 saved = true; | 3396 gnat_annotate_type = Cloned_Subtype (gnat_entity); |
3397 maybe_present = true; | |
3393 break; | 3398 break; |
3394 } | 3399 } |
3395 | 3400 |
3396 /* Otherwise, first ensure the base type is elaborated. Then, if we are | 3401 /* Otherwise, first ensure the base type is elaborated. Then, if we are |
3397 changing the type, make a new type with each field having the type of | 3402 changing the type, make a new type with each field having the type of |
3422 /* When the subtype has discriminants and these discriminants affect | 3427 /* When the subtype has discriminants and these discriminants affect |
3423 the initial shape it has inherited, factor them in. But for an | 3428 the initial shape it has inherited, factor them in. But for an |
3424 Unchecked_Union (it must be an Itype), just return the type. */ | 3429 Unchecked_Union (it must be an Itype), just return the type. */ |
3425 if (Has_Discriminants (gnat_entity) | 3430 if (Has_Discriminants (gnat_entity) |
3426 && Stored_Constraint (gnat_entity) != No_Elist | 3431 && Stored_Constraint (gnat_entity) != No_Elist |
3427 && !Is_For_Access_Subtype (gnat_entity) | |
3428 && Is_Record_Type (gnat_base_type) | 3432 && Is_Record_Type (gnat_base_type) |
3429 && !Is_Unchecked_Union (gnat_base_type)) | 3433 && !Is_Unchecked_Union (gnat_base_type)) |
3430 { | 3434 { |
3431 vec<subst_pair> gnu_subst_list | 3435 vec<subst_pair> gnu_subst_list |
3432 = build_subst_list (gnat_entity, gnat_base_type, definition); | 3436 = build_subst_list (gnat_entity, gnat_base_type, definition); |
3801 break; | 3805 break; |
3802 | 3806 |
3803 case E_Access_Subtype: | 3807 case E_Access_Subtype: |
3804 /* We treat this as identical to its base type; any constraint is | 3808 /* We treat this as identical to its base type; any constraint is |
3805 meaningful only to the front-end. */ | 3809 meaningful only to the front-end. */ |
3806 gnu_decl = gnat_to_gnu_entity (Etype (gnat_entity), NULL_TREE, false); | 3810 gnu_decl = gnat_to_gnu_entity (gnat_equiv_type, NULL_TREE, false); |
3807 saved = true; | 3811 maybe_present = true; |
3808 | 3812 |
3809 /* The designated subtype must be elaborated as well, if it does | 3813 /* The designated subtype must be elaborated as well, if it does |
3810 not have its own freeze node. But designated subtypes created | 3814 not have its own freeze node. But designated subtypes created |
3811 for constrained components of records with discriminants are | 3815 for constrained components of records with discriminants are |
3812 not frozen by the front-end and not elaborated here, because | 3816 not frozen by the front-end and not elaborated here, because |
3881 case E_Function: | 3885 case E_Function: |
3882 case E_Procedure: | 3886 case E_Procedure: |
3883 { | 3887 { |
3884 tree gnu_ext_name | 3888 tree gnu_ext_name |
3885 = gnu_ext_name_for_subprog (gnat_entity, gnu_entity_name); | 3889 = gnu_ext_name_for_subprog (gnat_entity, gnu_entity_name); |
3886 enum inline_status_t inline_status | 3890 const enum inline_status_t inline_status |
3887 = Has_Pragma_No_Inline (gnat_entity) | 3891 = inline_status_for_subprog (gnat_entity); |
3888 ? is_suppressed | |
3889 : Has_Pragma_Inline_Always (gnat_entity) | |
3890 ? is_required | |
3891 : (Is_Inlined (gnat_entity) ? is_enabled : is_disabled); | |
3892 bool public_flag = Is_Public (gnat_entity) || imported_p; | 3892 bool public_flag = Is_Public (gnat_entity) || imported_p; |
3893 /* Subprograms marked both Intrinsic and Always_Inline need not | 3893 /* Subprograms marked both Intrinsic and Always_Inline need not |
3894 have a body of their own. */ | 3894 have a body of their own. */ |
3895 bool extern_flag | 3895 bool extern_flag |
3896 = ((Is_Public (gnat_entity) && !definition) | 3896 = ((Is_Public (gnat_entity) && !definition) |
4229 { | 4229 { |
4230 gnu_decl = get_gnu_tree (gnat_entity); | 4230 gnu_decl = get_gnu_tree (gnat_entity); |
4231 saved = true; | 4231 saved = true; |
4232 } | 4232 } |
4233 | 4233 |
4234 /* If we are processing a type and there is either no decl for it or | 4234 /* If we are processing a type and there is either no DECL for it or |
4235 we just made one, do some common processing for the type, such as | 4235 we just made one, do some common processing for the type, such as |
4236 handling alignment and possible padding. */ | 4236 handling alignment and possible padding. */ |
4237 if (is_type && (!gnu_decl || this_made_decl)) | 4237 if (is_type && (!gnu_decl || this_made_decl)) |
4238 { | 4238 { |
4239 gcc_assert (!TYPE_IS_DUMMY_P (gnu_type)); | 4239 gcc_assert (!TYPE_IS_DUMMY_P (gnu_type)); |
4240 | 4240 |
4241 /* Process the attributes, if not already done. Note that the type is | 4241 /* Process the attributes, if not already done. Note that the type is |
4242 already defined so we cannot pass true for IN_PLACE here. */ | 4242 already defined so we cannot pass true for IN_PLACE here. */ |
4243 process_attributes (&gnu_type, &attr_list, false, gnat_entity); | 4243 process_attributes (&gnu_type, &attr_list, false, gnat_entity); |
4244 | 4244 |
4245 /* ??? Don't set the size for a String_Literal since it is either | 4245 /* See if a size was specified, by means of either an Object_Size or |
4246 a regular Size clause, and validate it if so. | |
4247 | |
4248 ??? Don't set the size for a String_Literal since it is either | |
4246 confirming or we don't handle it properly (if the low bound is | 4249 confirming or we don't handle it properly (if the low bound is |
4247 non-constant). */ | 4250 non-constant). */ |
4248 if (!gnu_size && kind != E_String_Literal_Subtype) | 4251 if (!gnu_size && kind != E_String_Literal_Subtype) |
4249 { | 4252 { |
4250 Uint gnat_size = Known_Esize (gnat_entity) | 4253 if (Known_Esize (gnat_entity)) |
4251 ? Esize (gnat_entity) : RM_Size (gnat_entity); | 4254 gnu_size |
4252 gnu_size | 4255 = validate_size (Esize (gnat_entity), gnu_type, gnat_entity, |
4253 = validate_size (gnat_size, gnu_type, gnat_entity, TYPE_DECL, | 4256 VAR_DECL, false, false, NULL, NULL); |
4254 false, Has_Size_Clause (gnat_entity)); | 4257 else |
4258 gnu_size | |
4259 = validate_size (RM_Size (gnat_entity), gnu_type, gnat_entity, | |
4260 TYPE_DECL, false, Has_Size_Clause (gnat_entity), | |
4261 NULL, NULL); | |
4255 } | 4262 } |
4256 | 4263 |
4257 /* If a size was specified, see if we can make a new type of that size | 4264 /* If a size was specified, see if we can make a new type of that size |
4258 by rearranging the type, for example from a fat to a thin pointer. */ | 4265 by rearranging the type, for example from a fat to a thin pointer. */ |
4259 if (gnu_size) | 4266 if (gnu_size) |
4324 gnu_entity_name = TYPE_IDENTIFIER (gnu_type); | 4331 gnu_entity_name = TYPE_IDENTIFIER (gnu_type); |
4325 | 4332 |
4326 /* Now set the RM size of the type. We cannot do it before padding | 4333 /* Now set the RM size of the type. We cannot do it before padding |
4327 because we need to accept arbitrary RM sizes on integral types. */ | 4334 because we need to accept arbitrary RM sizes on integral types. */ |
4328 set_rm_size (RM_Size (gnat_entity), gnu_type, gnat_entity); | 4335 set_rm_size (RM_Size (gnat_entity), gnu_type, gnat_entity); |
4336 | |
4337 /* Back-annotate the alignment of the type if not already set. */ | |
4338 if (Unknown_Alignment (gnat_entity)) | |
4339 { | |
4340 unsigned int double_align, align; | |
4341 bool is_capped_double, align_clause; | |
4342 | |
4343 /* If the default alignment of "double" or larger scalar types is | |
4344 specifically capped and this is not an array with an alignment | |
4345 clause on the component type, return the cap. */ | |
4346 if ((double_align = double_float_alignment) > 0) | |
4347 is_capped_double | |
4348 = is_double_float_or_array (gnat_entity, &align_clause); | |
4349 else if ((double_align = double_scalar_alignment) > 0) | |
4350 is_capped_double | |
4351 = is_double_scalar_or_array (gnat_entity, &align_clause); | |
4352 else | |
4353 is_capped_double = align_clause = false; | |
4354 | |
4355 if (is_capped_double && !align_clause) | |
4356 align = double_align; | |
4357 else | |
4358 align = TYPE_ALIGN (gnu_type) / BITS_PER_UNIT; | |
4359 | |
4360 Set_Alignment (gnat_entity, UI_From_Int (align)); | |
4361 } | |
4362 | |
4363 /* Likewise for the size, if any. */ | |
4364 if (Unknown_Esize (gnat_entity) && TYPE_SIZE (gnu_type)) | |
4365 { | |
4366 tree gnu_size = TYPE_SIZE (gnu_type); | |
4367 | |
4368 /* If the size is self-referential, annotate the maximum value | |
4369 after saturating it, if need be, to avoid a No_Uint value. */ | |
4370 if (CONTAINS_PLACEHOLDER_P (gnu_size)) | |
4371 gnu_size = maybe_saturate_size (max_size (gnu_size, true)); | |
4372 | |
4373 /* If we are just annotating types and the type is tagged, the tag | |
4374 and the parent components are not generated by the front-end so | |
4375 alignment and sizes must be adjusted. */ | |
4376 if (type_annotate_only && Is_Tagged_Type (gnat_entity)) | |
4377 { | |
4378 const bool derived_p = Is_Derived_Type (gnat_entity); | |
4379 const Entity_Id gnat_parent | |
4380 = derived_p ? Etype (Base_Type (gnat_entity)) : Empty; | |
4381 const unsigned int inherited_align | |
4382 = derived_p | |
4383 ? UI_To_Int (Alignment (gnat_parent)) * BITS_PER_UNIT | |
4384 : POINTER_SIZE; | |
4385 const unsigned int align | |
4386 = MAX (TYPE_ALIGN (gnu_type), inherited_align); | |
4387 | |
4388 Set_Alignment (gnat_entity, UI_From_Int (align / BITS_PER_UNIT)); | |
4389 | |
4390 /* If there is neither size clause nor representation clause, the | |
4391 sizes need to be adjusted. */ | |
4392 if (Unknown_RM_Size (gnat_entity) | |
4393 && !VOID_TYPE_P (gnu_type) | |
4394 && (!TYPE_FIELDS (gnu_type) | |
4395 || integer_zerop (bit_position (TYPE_FIELDS (gnu_type))))) | |
4396 { | |
4397 tree offset | |
4398 = derived_p | |
4399 ? UI_To_gnu (Esize (gnat_parent), bitsizetype) | |
4400 : bitsize_int (POINTER_SIZE); | |
4401 if (TYPE_FIELDS (gnu_type)) | |
4402 offset | |
4403 = round_up (offset, DECL_ALIGN (TYPE_FIELDS (gnu_type))); | |
4404 gnu_size = size_binop (PLUS_EXPR, gnu_size, offset); | |
4405 } | |
4406 | |
4407 gnu_size = maybe_saturate_size (round_up (gnu_size, align)); | |
4408 Set_Esize (gnat_entity, annotate_value (gnu_size)); | |
4409 | |
4410 /* Tagged types are Strict_Alignment so RM_Size = Esize. */ | |
4411 if (Unknown_RM_Size (gnat_entity)) | |
4412 Set_RM_Size (gnat_entity, Esize (gnat_entity)); | |
4413 } | |
4414 | |
4415 /* Otherwise no adjustment is needed. */ | |
4416 else | |
4417 Set_Esize (gnat_entity, annotate_value (gnu_size)); | |
4418 } | |
4419 | |
4420 /* Likewise for the RM size, if any. */ | |
4421 if (Unknown_RM_Size (gnat_entity) && TYPE_SIZE (gnu_type)) | |
4422 Set_RM_Size (gnat_entity, annotate_value (rm_size (gnu_type))); | |
4329 | 4423 |
4330 /* If we are at global level, GCC will have applied variable_size to | 4424 /* If we are at global level, GCC will have applied variable_size to |
4331 the type, but that won't have done anything. So, if it's not | 4425 the type, but that won't have done anything. So, if it's not |
4332 a constant or self-referential, call elaborate_expression_1 to | 4426 a constant or self-referential, call elaborate_expression_1 to |
4333 make a variable for the size rather than calculating it each time. | 4427 make a variable for the size rather than calculating it each time. |
4443 the call to create_type_decl below. */ | 4537 the call to create_type_decl below. */ |
4444 MARK_VISITED (DECL_FIELD_OFFSET (gnu_field)); | 4538 MARK_VISITED (DECL_FIELD_OFFSET (gnu_field)); |
4445 } | 4539 } |
4446 } | 4540 } |
4447 | 4541 |
4542 /* Now check if the type allows atomic access. */ | |
4448 if (Is_Atomic_Or_VFA (gnat_entity)) | 4543 if (Is_Atomic_Or_VFA (gnat_entity)) |
4449 check_ok_for_atomic_type (gnu_type, gnat_entity, false); | 4544 check_ok_for_atomic_type (gnu_type, gnat_entity, false); |
4450 | 4545 |
4451 /* If this is not an unconstrained array type, set some flags. */ | 4546 /* If this is not an unconstrained array type, set some flags. */ |
4452 if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE) | 4547 if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE) |
4576 else | 4671 else |
4577 gnu_decl = create_type_decl (gnu_entity_name, gnu_type, artificial_p, | 4672 gnu_decl = create_type_decl (gnu_entity_name, gnu_type, artificial_p, |
4578 debug_info_p, gnat_entity); | 4673 debug_info_p, gnat_entity); |
4579 } | 4674 } |
4580 | 4675 |
4581 /* If we got a type that is not dummy, back-annotate the alignment of the | 4676 /* Otherwise, for a type reusing an existing DECL, back-annotate values. */ |
4582 type if not already in the tree. Likewise for the size, if any. */ | 4677 else if (is_type |
4583 if (is_type && !TYPE_IS_DUMMY_P (TREE_TYPE (gnu_decl))) | 4678 && !TYPE_IS_DUMMY_P (TREE_TYPE (gnu_decl)) |
4679 && Present (gnat_annotate_type)) | |
4584 { | 4680 { |
4585 gnu_type = TREE_TYPE (gnu_decl); | |
4586 | |
4587 if (Unknown_Alignment (gnat_entity)) | 4681 if (Unknown_Alignment (gnat_entity)) |
4588 { | 4682 Set_Alignment (gnat_entity, Alignment (gnat_annotate_type)); |
4589 unsigned int double_align, align; | 4683 if (Unknown_Esize (gnat_entity)) |
4590 bool is_capped_double, align_clause; | 4684 Set_Esize (gnat_entity, Esize (gnat_annotate_type)); |
4591 | 4685 if (Unknown_RM_Size (gnat_entity)) |
4592 /* If the default alignment of "double" or larger scalar types is | 4686 Set_RM_Size (gnat_entity, RM_Size (gnat_annotate_type)); |
4593 specifically capped and this is not an array with an alignment | |
4594 clause on the component type, return the cap. */ | |
4595 if ((double_align = double_float_alignment) > 0) | |
4596 is_capped_double | |
4597 = is_double_float_or_array (gnat_entity, &align_clause); | |
4598 else if ((double_align = double_scalar_alignment) > 0) | |
4599 is_capped_double | |
4600 = is_double_scalar_or_array (gnat_entity, &align_clause); | |
4601 else | |
4602 is_capped_double = align_clause = false; | |
4603 | |
4604 if (is_capped_double && !align_clause) | |
4605 align = double_align; | |
4606 else | |
4607 align = TYPE_ALIGN (gnu_type) / BITS_PER_UNIT; | |
4608 | |
4609 Set_Alignment (gnat_entity, UI_From_Int (align)); | |
4610 } | |
4611 | |
4612 if (Unknown_Esize (gnat_entity) && TYPE_SIZE (gnu_type)) | |
4613 { | |
4614 tree gnu_size = TYPE_SIZE (gnu_type); | |
4615 | |
4616 /* If the size is self-referential, annotate the maximum value. */ | |
4617 if (CONTAINS_PLACEHOLDER_P (gnu_size)) | |
4618 gnu_size = max_size (gnu_size, true); | |
4619 | |
4620 /* If we are just annotating types and the type is tagged, the tag | |
4621 and the parent components are not generated by the front-end so | |
4622 alignment and sizes must be adjusted if there is no rep clause. */ | |
4623 if (type_annotate_only | |
4624 && Is_Tagged_Type (gnat_entity) | |
4625 && Unknown_RM_Size (gnat_entity) | |
4626 && !VOID_TYPE_P (gnu_type) | |
4627 && (!TYPE_FIELDS (gnu_type) | |
4628 || integer_zerop (bit_position (TYPE_FIELDS (gnu_type))))) | |
4629 { | |
4630 tree offset; | |
4631 | |
4632 if (Is_Derived_Type (gnat_entity)) | |
4633 { | |
4634 Entity_Id gnat_parent = Etype (Base_Type (gnat_entity)); | |
4635 offset = UI_To_gnu (Esize (gnat_parent), bitsizetype); | |
4636 Set_Alignment (gnat_entity, Alignment (gnat_parent)); | |
4637 } | |
4638 else | |
4639 { | |
4640 unsigned int align | |
4641 = MAX (TYPE_ALIGN (gnu_type), POINTER_SIZE) / BITS_PER_UNIT; | |
4642 offset = bitsize_int (POINTER_SIZE); | |
4643 Set_Alignment (gnat_entity, UI_From_Int (align)); | |
4644 } | |
4645 | |
4646 if (TYPE_FIELDS (gnu_type)) | |
4647 offset | |
4648 = round_up (offset, DECL_ALIGN (TYPE_FIELDS (gnu_type))); | |
4649 | |
4650 gnu_size = size_binop (PLUS_EXPR, gnu_size, offset); | |
4651 gnu_size = round_up (gnu_size, POINTER_SIZE); | |
4652 Uint uint_size = annotate_value (gnu_size); | |
4653 Set_RM_Size (gnat_entity, uint_size); | |
4654 Set_Esize (gnat_entity, uint_size); | |
4655 } | |
4656 | |
4657 /* If there is a rep clause, only adjust alignment and Esize. */ | |
4658 else if (type_annotate_only && Is_Tagged_Type (gnat_entity)) | |
4659 { | |
4660 unsigned int align | |
4661 = MAX (TYPE_ALIGN (gnu_type), POINTER_SIZE) / BITS_PER_UNIT; | |
4662 Set_Alignment (gnat_entity, UI_From_Int (align)); | |
4663 gnu_size = round_up (gnu_size, POINTER_SIZE); | |
4664 Set_Esize (gnat_entity, annotate_value (gnu_size)); | |
4665 } | |
4666 | |
4667 /* Otherwise no adjustment is needed. */ | |
4668 else | |
4669 Set_Esize (gnat_entity, annotate_value (gnu_size)); | |
4670 } | |
4671 | |
4672 if (Unknown_RM_Size (gnat_entity) && TYPE_SIZE (gnu_type)) | |
4673 Set_RM_Size (gnat_entity, annotate_value (rm_size (gnu_type))); | |
4674 } | 4687 } |
4675 | 4688 |
4676 /* If we haven't already, associate the ..._DECL node that we just made with | 4689 /* If we haven't already, associate the ..._DECL node that we just made with |
4677 the input GNAT entity node. */ | 4690 the input GNAT entity node. */ |
4678 if (!saved) | 4691 if (!saved) |
4932 } | 4945 } |
4933 | 4946 |
4934 return false; | 4947 return false; |
4935 } | 4948 } |
4936 | 4949 |
4950 /* Return the inlining status of the GNAT subprogram SUBPROG. */ | |
4951 | |
4952 static enum inline_status_t | |
4953 inline_status_for_subprog (Entity_Id subprog) | |
4954 { | |
4955 if (Has_Pragma_No_Inline (subprog)) | |
4956 return is_suppressed; | |
4957 | |
4958 if (Has_Pragma_Inline_Always (subprog)) | |
4959 return is_required; | |
4960 | |
4961 if (Is_Inlined (subprog)) | |
4962 { | |
4963 tree gnu_type; | |
4964 | |
4965 /* This is a kludge to work around a pass ordering issue: for small | |
4966 record types with many components, i.e. typically bit-fields, the | |
4967 initialization routine can contain many assignments that will be | |
4968 merged by the GIMPLE store merging pass. But this pass runs very | |
4969 late in the pipeline, in particular after the inlining decisions | |
4970 are made, so the inlining heuristics cannot take its outcome into | |
4971 account. Therefore, we optimistically override the heuristics for | |
4972 the initialization routine in this case. */ | |
4973 if (Is_Init_Proc (subprog) | |
4974 && flag_store_merging | |
4975 && Is_Record_Type (Etype (First_Formal (subprog))) | |
4976 && (gnu_type = gnat_to_gnu_type (Etype (First_Formal (subprog)))) | |
4977 && !TYPE_IS_BY_REFERENCE_P (gnu_type) | |
4978 && tree_fits_uhwi_p (TYPE_SIZE (gnu_type)) | |
4979 && compare_tree_int (TYPE_SIZE (gnu_type), MAX_FIXED_MODE_SIZE) <= 0) | |
4980 return is_prescribed; | |
4981 | |
4982 return is_requested; | |
4983 } | |
4984 | |
4985 return is_default; | |
4986 } | |
4987 | |
4937 /* Finalize the processing of From_Limited_With incomplete types. */ | 4988 /* Finalize the processing of From_Limited_With incomplete types. */ |
4938 | 4989 |
4939 void | 4990 void |
4940 finalize_from_limited_with (void) | 4991 finalize_from_limited_with (void) |
4941 { | 4992 { |
4984 case E_Anonymous_Access_Protected_Subprogram_Type: | 5035 case E_Anonymous_Access_Protected_Subprogram_Type: |
4985 if (Present (Equivalent_Type (gnat_entity))) | 5036 if (Present (Equivalent_Type (gnat_entity))) |
4986 gnat_equiv = Equivalent_Type (gnat_entity); | 5037 gnat_equiv = Equivalent_Type (gnat_entity); |
4987 break; | 5038 break; |
4988 | 5039 |
5040 case E_Access_Subtype: | |
5041 gnat_equiv = Etype (gnat_entity); | |
5042 break; | |
5043 | |
5044 case E_Array_Subtype: | |
5045 if (!Is_Constrained (gnat_entity)) | |
5046 gnat_equiv = Etype (gnat_entity); | |
5047 break; | |
5048 | |
4989 case E_Class_Wide_Type: | 5049 case E_Class_Wide_Type: |
4990 gnat_equiv = Root_Type (gnat_entity); | 5050 gnat_equiv = Root_Type (gnat_entity); |
4991 break; | 5051 break; |
4992 | 5052 |
4993 case E_Protected_Type: | 5053 case E_Protected_Type: |
5014 gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition, | 5074 gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition, |
5015 bool debug_info_p) | 5075 bool debug_info_p) |
5016 { | 5076 { |
5017 const Entity_Id gnat_type = Component_Type (gnat_array); | 5077 const Entity_Id gnat_type = Component_Type (gnat_array); |
5018 tree gnu_type = gnat_to_gnu_type (gnat_type); | 5078 tree gnu_type = gnat_to_gnu_type (gnat_type); |
5079 bool has_packed_components = Is_Bit_Packed_Array (gnat_array); | |
5019 tree gnu_comp_size; | 5080 tree gnu_comp_size; |
5020 unsigned int max_align; | 5081 unsigned int max_align; |
5021 | 5082 |
5022 /* If an alignment is specified, use it as a cap on the component type | 5083 /* If an alignment is specified, use it as a cap on the component type |
5023 so that it can be honored for the whole type. But ignore it for the | 5084 so that it can be honored for the whole type. But ignore it for the |
5026 && Known_Alignment (gnat_array)) | 5087 && Known_Alignment (gnat_array)) |
5027 max_align = validate_alignment (Alignment (gnat_array), gnat_array, 0); | 5088 max_align = validate_alignment (Alignment (gnat_array), gnat_array, 0); |
5028 else | 5089 else |
5029 max_align = 0; | 5090 max_align = 0; |
5030 | 5091 |
5031 /* Try to get a smaller form of the component if needed. */ | 5092 /* Try to get a packable form of the component if needed. */ |
5032 if ((Is_Packed (gnat_array) || Has_Component_Size_Clause (gnat_array)) | 5093 if ((Is_Packed (gnat_array) || Has_Component_Size_Clause (gnat_array)) |
5033 && !Is_Bit_Packed_Array (gnat_array) | |
5034 && !Has_Aliased_Components (gnat_array) | 5094 && !Has_Aliased_Components (gnat_array) |
5035 && !Strict_Alignment (gnat_type) | 5095 && !Strict_Alignment (gnat_type) |
5096 && !has_packed_components | |
5036 && RECORD_OR_UNION_TYPE_P (gnu_type) | 5097 && RECORD_OR_UNION_TYPE_P (gnu_type) |
5037 && !TYPE_FAT_POINTER_P (gnu_type) | 5098 && !TYPE_FAT_POINTER_P (gnu_type) |
5038 && tree_fits_uhwi_p (TYPE_SIZE (gnu_type))) | 5099 && tree_fits_uhwi_p (TYPE_SIZE (gnu_type))) |
5039 gnu_type = make_packable_type (gnu_type, false, max_align); | 5100 { |
5101 gnu_type = make_packable_type (gnu_type, false, max_align); | |
5102 has_packed_components = true; | |
5103 } | |
5040 | 5104 |
5041 /* Get and validate any specified Component_Size. */ | 5105 /* Get and validate any specified Component_Size. */ |
5042 gnu_comp_size | 5106 gnu_comp_size |
5043 = validate_size (Component_Size (gnat_array), gnu_type, gnat_array, | 5107 = validate_size (Component_Size (gnat_array), gnu_type, gnat_array, |
5044 Is_Bit_Packed_Array (gnat_array) ? TYPE_DECL : VAR_DECL, | 5108 has_packed_components ? TYPE_DECL : VAR_DECL, true, |
5045 true, Has_Component_Size_Clause (gnat_array)); | 5109 Has_Component_Size_Clause (gnat_array), NULL, NULL); |
5046 | 5110 |
5047 /* If the component type is a RECORD_TYPE that has a self-referential size, | 5111 /* If the component type is a RECORD_TYPE that has a self-referential size, |
5048 then use the maximum size for the component size. */ | 5112 then use the maximum size for the component size. */ |
5049 if (!gnu_comp_size | 5113 if (!gnu_comp_size |
5050 && TREE_CODE (gnu_type) == RECORD_TYPE | 5114 && TREE_CODE (gnu_type) == RECORD_TYPE |
5102 create_type_decl (TYPE_NAME (gnu_type), gnu_type, true, debug_info_p, | 5166 create_type_decl (TYPE_NAME (gnu_type), gnu_type, true, debug_info_p, |
5103 gnat_array); | 5167 gnat_array); |
5104 } | 5168 } |
5105 } | 5169 } |
5106 | 5170 |
5171 /* Now check if the type of the component allows atomic access. */ | |
5107 if (Has_Atomic_Components (gnat_array) || Is_Atomic_Or_VFA (gnat_type)) | 5172 if (Has_Atomic_Components (gnat_array) || Is_Atomic_Or_VFA (gnat_type)) |
5108 check_ok_for_atomic_type (gnu_type, gnat_array, true); | 5173 check_ok_for_atomic_type (gnu_type, gnat_array, true); |
5109 | 5174 |
5110 /* If the component type is a padded type made for a non-bit-packed array | 5175 /* If the component type is a padded type made for a non-bit-packed array |
5111 of scalars with reverse storage order, we need to propagate the reverse | 5176 of scalars with reverse storage order, we need to propagate the reverse |
5185 bool in_param = (Ekind (gnat_param) == E_In_Parameter); | 5250 bool in_param = (Ekind (gnat_param) == E_In_Parameter); |
5186 /* The parameter can be indirectly modified if its address is taken. */ | 5251 /* The parameter can be indirectly modified if its address is taken. */ |
5187 bool ro_param = in_param && !Address_Taken (gnat_param); | 5252 bool ro_param = in_param && !Address_Taken (gnat_param); |
5188 bool by_return = false, by_component_ptr = false; | 5253 bool by_return = false, by_component_ptr = false; |
5189 bool by_ref = false; | 5254 bool by_ref = false; |
5255 bool forced_by_ref = false; | |
5190 bool restricted_aliasing_p = false; | 5256 bool restricted_aliasing_p = false; |
5191 location_t saved_location = input_location; | 5257 location_t saved_location = input_location; |
5192 tree gnu_param; | 5258 tree gnu_param; |
5193 | 5259 |
5194 /* Make sure to use the proper SLOC for vector ABI warnings. */ | 5260 /* Make sure to use the proper SLOC for vector ABI warnings. */ |
5212 } | 5278 } |
5213 | 5279 |
5214 /* Or else, see if a Mechanism was supplied that forced this parameter | 5280 /* Or else, see if a Mechanism was supplied that forced this parameter |
5215 to be passed one way or another. */ | 5281 to be passed one way or another. */ |
5216 else if (mech == Default || mech == By_Copy || mech == By_Reference) | 5282 else if (mech == Default || mech == By_Copy || mech == By_Reference) |
5217 ; | 5283 forced_by_ref |
5284 = (mech == By_Reference | |
5285 && !foreign | |
5286 && !TYPE_IS_BY_REFERENCE_P (gnu_param_type) | |
5287 && !Is_Aliased (gnat_param)); | |
5218 | 5288 |
5219 /* Positive mechanism means by copy for sufficiently small parameters. */ | 5289 /* Positive mechanism means by copy for sufficiently small parameters. */ |
5220 else if (mech > 0) | 5290 else if (mech > 0) |
5221 { | 5291 { |
5222 if (TREE_CODE (gnu_param_type) == UNCONSTRAINED_ARRAY_TYPE | 5292 if (TREE_CODE (gnu_param_type) == UNCONSTRAINED_ARRAY_TYPE |
5345 return gnu_param_type; | 5415 return gnu_param_type; |
5346 | 5416 |
5347 gnu_param = create_param_decl (gnu_param_name, gnu_param_type); | 5417 gnu_param = create_param_decl (gnu_param_name, gnu_param_type); |
5348 TREE_READONLY (gnu_param) = ro_param || by_ref || by_component_ptr; | 5418 TREE_READONLY (gnu_param) = ro_param || by_ref || by_component_ptr; |
5349 DECL_BY_REF_P (gnu_param) = by_ref; | 5419 DECL_BY_REF_P (gnu_param) = by_ref; |
5420 DECL_FORCED_BY_REF_P (gnu_param) = forced_by_ref; | |
5350 DECL_BY_COMPONENT_PTR_P (gnu_param) = by_component_ptr; | 5421 DECL_BY_COMPONENT_PTR_P (gnu_param) = by_component_ptr; |
5351 DECL_POINTS_TO_READONLY_P (gnu_param) | 5422 DECL_POINTS_TO_READONLY_P (gnu_param) |
5352 = (ro_param && (by_ref || by_component_ptr)); | 5423 = (ro_param && (by_ref || by_component_ptr)); |
5353 DECL_CAN_NEVER_BE_NULL_P (gnu_param) = Can_Never_Be_Null (gnat_param); | 5424 DECL_CAN_NEVER_BE_NULL_P (gnu_param) = Can_Never_Be_Null (gnat_param); |
5354 DECL_RESTRICTED_ALIASING_P (gnu_param) = restricted_aliasing_p; | 5425 DECL_RESTRICTED_ALIASING_P (gnu_param) = restricted_aliasing_p; |
5562 } | 5633 } |
5563 | 5634 |
5564 return gnu_type; | 5635 return gnu_type; |
5565 } | 5636 } |
5566 | 5637 |
5638 /* Return true if TYPE contains only integral data, recursively if need be. */ | |
5639 | |
5640 static bool | |
5641 type_contains_only_integral_data (tree type) | |
5642 { | |
5643 switch (TREE_CODE (type)) | |
5644 { | |
5645 case RECORD_TYPE: | |
5646 case UNION_TYPE: | |
5647 case QUAL_UNION_TYPE: | |
5648 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) | |
5649 if (!type_contains_only_integral_data (TREE_TYPE (field))) | |
5650 return false; | |
5651 return true; | |
5652 | |
5653 case ARRAY_TYPE: | |
5654 case COMPLEX_TYPE: | |
5655 return type_contains_only_integral_data (TREE_TYPE (type)); | |
5656 | |
5657 default: | |
5658 return INTEGRAL_TYPE_P (type); | |
5659 } | |
5660 | |
5661 gcc_unreachable (); | |
5662 } | |
5663 | |
5567 /* Return a GCC tree for a subprogram type corresponding to GNAT_SUBPROG. | 5664 /* Return a GCC tree for a subprogram type corresponding to GNAT_SUBPROG. |
5568 DEFINITION is true if this is for a subprogram being defined. DEBUG_INFO_P | 5665 DEFINITION is true if this is for a subprogram being defined. DEBUG_INFO_P |
5569 is true if we need to write debug information for other types that we may | 5666 is true if we need to write debug information for other types that we may |
5570 create in the process. Also set PARAM_LIST to the list of parameters. | 5667 create in the process. Also set PARAM_LIST to the list of parameters. |
5571 If GNAT_SUBPROG is bound to a GCC builtin, return the DECL for the builtin | 5668 If GNAT_SUBPROG is bound to a GCC builtin, return the DECL for the builtin |
5591 an element of this list is a FIELD_DECL of the record and the TREE_VALUE | 5688 an element of this list is a FIELD_DECL of the record and the TREE_VALUE |
5592 is the PARM_DECL corresponding to that field. This list will be saved in | 5689 is the PARM_DECL corresponding to that field. This list will be saved in |
5593 the TYPE_CI_CO_LIST field of the FUNCTION_TYPE node we create. */ | 5690 the TYPE_CI_CO_LIST field of the FUNCTION_TYPE node we create. */ |
5594 tree gnu_cico_list = NULL_TREE; | 5691 tree gnu_cico_list = NULL_TREE; |
5595 tree gnu_cico_return_type = NULL_TREE; | 5692 tree gnu_cico_return_type = NULL_TREE; |
5596 /* Fields in return type of procedure with copy-in copy-out parameters. */ | 5693 tree gnu_cico_field_list = NULL_TREE; |
5597 tree gnu_field_list = NULL_TREE; | 5694 bool gnu_cico_only_integral_type = true; |
5598 /* The semantics of "pure" in Ada essentially matches that of "const" | 5695 /* The semantics of "pure" in Ada essentially matches that of "const" |
5599 or "pure" in GCC. In particular, both properties are orthogonal | 5696 or "pure" in GCC. In particular, both properties are orthogonal |
5600 to the "nothrow" property if the EH circuitry is explicit in the | 5697 to the "nothrow" property if the EH circuitry is explicit in the |
5601 internal representation of the middle-end. If we are to completely | 5698 internal representation of the middle-end. If we are to completely |
5602 hide the EH circuitry from it, we need to declare that calls to pure | 5699 hide the EH circuitry from it, we need to declare that calls to pure |
5918 gnu_return_type, | 6015 gnu_return_type, |
5919 gnu_cico_return_type, NULL_TREE, | 6016 gnu_cico_return_type, NULL_TREE, |
5920 NULL_TREE, 0, 0); | 6017 NULL_TREE, 0, 0); |
5921 Sloc_to_locus (Sloc (gnat_subprog), | 6018 Sloc_to_locus (Sloc (gnat_subprog), |
5922 &DECL_SOURCE_LOCATION (gnu_field)); | 6019 &DECL_SOURCE_LOCATION (gnu_field)); |
5923 gnu_field_list = gnu_field; | 6020 gnu_cico_field_list = gnu_field; |
5924 gnu_cico_list | 6021 gnu_cico_list |
5925 = tree_cons (gnu_field, void_type_node, NULL_TREE); | 6022 = tree_cons (gnu_field, void_type_node, NULL_TREE); |
6023 if (!type_contains_only_integral_data (gnu_return_type)) | |
6024 gnu_cico_only_integral_type = false; | |
5926 } | 6025 } |
5927 | 6026 |
5928 TYPE_NAME (gnu_cico_return_type) = get_identifier ("RETURN"); | 6027 TYPE_NAME (gnu_cico_return_type) = get_identifier ("RETURN"); |
5929 /* Set a default alignment to speed up accesses. But we should | 6028 /* Set a default alignment to speed up accesses. But we should |
5930 not increase the size of the structure too much, lest it does | 6029 not increase the size of the structure too much, lest it does |
5937 = create_field_decl (gnu_param_name, gnu_param_type, | 6036 = create_field_decl (gnu_param_name, gnu_param_type, |
5938 gnu_cico_return_type, NULL_TREE, NULL_TREE, | 6037 gnu_cico_return_type, NULL_TREE, NULL_TREE, |
5939 0, 0); | 6038 0, 0); |
5940 Sloc_to_locus (Sloc (gnat_param), | 6039 Sloc_to_locus (Sloc (gnat_param), |
5941 &DECL_SOURCE_LOCATION (gnu_field)); | 6040 &DECL_SOURCE_LOCATION (gnu_field)); |
5942 DECL_CHAIN (gnu_field) = gnu_field_list; | 6041 DECL_CHAIN (gnu_field) = gnu_cico_field_list; |
5943 gnu_field_list = gnu_field; | 6042 gnu_cico_field_list = gnu_field; |
5944 gnu_cico_list = tree_cons (gnu_field, gnu_param, gnu_cico_list); | 6043 gnu_cico_list = tree_cons (gnu_field, gnu_param, gnu_cico_list); |
6044 if (!type_contains_only_integral_data (gnu_param_type)) | |
6045 gnu_cico_only_integral_type = false; | |
5945 } | 6046 } |
5946 } | 6047 } |
5947 | 6048 |
5948 /* If the subprogram uses the copy-in copy-out mechanism, possibly adjust | 6049 /* If the subprogram uses the copy-in copy-out mechanism, possibly adjust |
5949 and finish up the return type. */ | 6050 and finish up the return type. */ |
5956 | 6057 |
5957 /* Do not finalize the return type if the subprogram is stubbed | 6058 /* Do not finalize the return type if the subprogram is stubbed |
5958 since structures are incomplete for the back-end. */ | 6059 since structures are incomplete for the back-end. */ |
5959 else if (Convention (gnat_subprog) != Convention_Stubbed) | 6060 else if (Convention (gnat_subprog) != Convention_Stubbed) |
5960 { | 6061 { |
5961 finish_record_type (gnu_cico_return_type, nreverse (gnu_field_list), | 6062 finish_record_type (gnu_cico_return_type, |
6063 nreverse (gnu_cico_field_list), | |
5962 0, false); | 6064 0, false); |
5963 | 6065 |
5964 /* Try to promote the mode of the return type if it is passed | 6066 /* Try to promote the mode if the return type is fully returned |
5965 in registers, again to speed up accesses. */ | 6067 in integer registers, again to speed up accesses. */ |
5966 if (TYPE_MODE (gnu_cico_return_type) == BLKmode | 6068 if (TYPE_MODE (gnu_cico_return_type) == BLKmode |
6069 && gnu_cico_only_integral_type | |
5967 && !targetm.calls.return_in_memory (gnu_cico_return_type, | 6070 && !targetm.calls.return_in_memory (gnu_cico_return_type, |
5968 NULL_TREE)) | 6071 NULL_TREE)) |
5969 { | 6072 { |
5970 unsigned int size | 6073 unsigned int size |
5971 = TREE_INT_CST_LOW (TYPE_SIZE (gnu_cico_return_type)); | 6074 = TREE_INT_CST_LOW (TYPE_SIZE (gnu_cico_return_type)); |
5983 = bitsize_int (GET_MODE_BITSIZE (mode)); | 6086 = bitsize_int (GET_MODE_BITSIZE (mode)); |
5984 TYPE_SIZE_UNIT (gnu_cico_return_type) | 6087 TYPE_SIZE_UNIT (gnu_cico_return_type) |
5985 = size_int (GET_MODE_SIZE (mode)); | 6088 = size_int (GET_MODE_SIZE (mode)); |
5986 } | 6089 } |
5987 } | 6090 } |
6091 | |
6092 /* But demote the mode if the return type is partly returned in FP | |
6093 registers to avoid creating problematic paradoxical subregs. | |
6094 Note that we need to cater to historical 32-bit architectures | |
6095 that incorrectly use the mode to select the return mechanism. */ | |
6096 else if (INTEGRAL_MODE_P (TYPE_MODE (gnu_cico_return_type)) | |
6097 && !gnu_cico_only_integral_type | |
6098 && BITS_PER_WORD >= 64 | |
6099 && !targetm.calls.return_in_memory (gnu_cico_return_type, | |
6100 NULL_TREE)) | |
6101 SET_TYPE_MODE (gnu_cico_return_type, BLKmode); | |
5988 | 6102 |
5989 if (debug_info_p) | 6103 if (debug_info_p) |
5990 rest_of_record_type_compilation (gnu_cico_return_type); | 6104 rest_of_record_type_compilation (gnu_cico_return_type); |
5991 } | 6105 } |
5992 | 6106 |
6150 | 6264 |
6151 static void | 6265 static void |
6152 set_nonaliased_component_on_array_type (tree type) | 6266 set_nonaliased_component_on_array_type (tree type) |
6153 { | 6267 { |
6154 TYPE_NONALIASED_COMPONENT (type) = 1; | 6268 TYPE_NONALIASED_COMPONENT (type) = 1; |
6155 TYPE_NONALIASED_COMPONENT (TYPE_CANONICAL (type)) = 1; | 6269 if (TYPE_CANONICAL (type)) |
6270 TYPE_NONALIASED_COMPONENT (TYPE_CANONICAL (type)) = 1; | |
6156 } | 6271 } |
6157 | 6272 |
6158 /* Set TYPE_REVERSE_STORAGE_ORDER on an array type built by means of | 6273 /* Set TYPE_REVERSE_STORAGE_ORDER on an array type built by means of |
6159 build_nonshared_array_type. */ | 6274 build_nonshared_array_type. */ |
6160 | 6275 |
6161 static void | 6276 static void |
6162 set_reverse_storage_order_on_array_type (tree type) | 6277 set_reverse_storage_order_on_array_type (tree type) |
6163 { | 6278 { |
6164 TYPE_REVERSE_STORAGE_ORDER (type) = 1; | 6279 TYPE_REVERSE_STORAGE_ORDER (type) = 1; |
6165 TYPE_REVERSE_STORAGE_ORDER (TYPE_CANONICAL (type)) = 1; | 6280 if (TYPE_CANONICAL (type)) |
6281 TYPE_REVERSE_STORAGE_ORDER (TYPE_CANONICAL (type)) = 1; | |
6166 } | 6282 } |
6167 | 6283 |
6168 /* Return true if DISCR1 and DISCR2 represent the same discriminant. */ | 6284 /* Return true if DISCR1 and DISCR2 represent the same discriminant. */ |
6169 | 6285 |
6170 static bool | 6286 static bool |
6184 GNAT_TYPE, has a non-aliased component in the back-end sense. */ | 6300 GNAT_TYPE, has a non-aliased component in the back-end sense. */ |
6185 | 6301 |
6186 static bool | 6302 static bool |
6187 array_type_has_nonaliased_component (tree gnu_type, Entity_Id gnat_type) | 6303 array_type_has_nonaliased_component (tree gnu_type, Entity_Id gnat_type) |
6188 { | 6304 { |
6189 /* If the array type is not the innermost dimension of the GNAT type, | |
6190 then it has a non-aliased component. */ | |
6191 if (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE | |
6192 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type))) | |
6193 return true; | |
6194 | |
6195 /* If the array type has an aliased component in the front-end sense, | 6305 /* If the array type has an aliased component in the front-end sense, |
6196 then it also has an aliased component in the back-end sense. */ | 6306 then it also has an aliased component in the back-end sense. */ |
6197 if (Has_Aliased_Components (gnat_type)) | 6307 if (Has_Aliased_Components (gnat_type)) |
6198 return false; | 6308 return false; |
6199 | 6309 |
6200 /* If this is a derived type, then it has a non-aliased component if | 6310 /* If this is a derived type, then it has a non-aliased component if |
6201 and only if its parent type also has one. */ | 6311 and only if its parent type also has one. */ |
6202 if (Is_Derived_Type (gnat_type)) | 6312 if (Is_Derived_Type (gnat_type)) |
6203 { | 6313 { |
6204 tree gnu_parent_type = gnat_to_gnu_type (Etype (gnat_type)); | 6314 tree gnu_parent_type = gnat_to_gnu_type (Etype (gnat_type)); |
6205 int index; | |
6206 if (TREE_CODE (gnu_parent_type) == UNCONSTRAINED_ARRAY_TYPE) | 6315 if (TREE_CODE (gnu_parent_type) == UNCONSTRAINED_ARRAY_TYPE) |
6207 gnu_parent_type | 6316 gnu_parent_type |
6208 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_parent_type)))); | 6317 = TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (gnu_parent_type)))); |
6209 for (index = Number_Dimensions (gnat_type) - 1; index > 0; index--) | |
6210 gnu_parent_type = TREE_TYPE (gnu_parent_type); | |
6211 return TYPE_NONALIASED_COMPONENT (gnu_parent_type); | 6318 return TYPE_NONALIASED_COMPONENT (gnu_parent_type); |
6212 } | 6319 } |
6320 | |
6321 /* For a multi-dimensional array type, find the component type. */ | |
6322 while (TREE_CODE (TREE_TYPE (gnu_type)) == ARRAY_TYPE | |
6323 && TYPE_MULTI_ARRAY_P (TREE_TYPE (gnu_type))) | |
6324 gnu_type = TREE_TYPE (gnu_type); | |
6213 | 6325 |
6214 /* Consider that an array of pointers has an aliased component, which is | 6326 /* Consider that an array of pointers has an aliased component, which is |
6215 sort of logical and helps with Taft Amendment types in LTO mode. */ | 6327 sort of logical and helps with Taft Amendment types in LTO mode. */ |
6216 if (POINTER_TYPE_P (TREE_TYPE (gnu_type))) | 6328 if (POINTER_TYPE_P (TREE_TYPE (gnu_type))) |
6217 return false; | 6329 return false; |
6349 && !get_variant_part (TREE_TYPE (gnu_expr))) | 6461 && !get_variant_part (TREE_TYPE (gnu_expr))) |
6350 return false; | 6462 return false; |
6351 | 6463 |
6352 /* In all the other cases, convert the expression to the object's type. */ | 6464 /* In all the other cases, convert the expression to the object's type. */ |
6353 return true; | 6465 return true; |
6466 } | |
6467 | |
6468 /* Add the contribution of [MIN, MAX] to the current number of elements N_ELEM | |
6469 of an array type and return the result, or NULL_TREE if it overflowed. */ | |
6470 | |
6471 static tree | |
6472 update_n_elem (tree n_elem, tree min, tree max) | |
6473 { | |
6474 /* First deal with the empty case. */ | |
6475 if (TREE_CODE (min) == INTEGER_CST | |
6476 && TREE_CODE (max) == INTEGER_CST | |
6477 && tree_int_cst_lt (max, min)) | |
6478 return size_zero_node; | |
6479 | |
6480 min = convert (sizetype, min); | |
6481 max = convert (sizetype, max); | |
6482 | |
6483 /* Compute the number of elements in this dimension. */ | |
6484 tree this_n_elem | |
6485 = size_binop (PLUS_EXPR, size_one_node, size_binop (MINUS_EXPR, max, min)); | |
6486 | |
6487 if (TREE_CODE (this_n_elem) == INTEGER_CST && TREE_OVERFLOW (this_n_elem)) | |
6488 return NULL_TREE; | |
6489 | |
6490 /* Multiply the current number of elements by the result. */ | |
6491 n_elem = size_binop (MULT_EXPR, n_elem, this_n_elem); | |
6492 | |
6493 if (TREE_CODE (n_elem) == INTEGER_CST && TREE_OVERFLOW (n_elem)) | |
6494 return NULL_TREE; | |
6495 | |
6496 return n_elem; | |
6354 } | 6497 } |
6355 | 6498 |
6356 /* Given GNAT_ENTITY, elaborate all expressions that are required to | 6499 /* Given GNAT_ENTITY, elaborate all expressions that are required to |
6357 be elaborated at the point of its definition, but do nothing else. */ | 6500 be elaborated at the point of its definition, but do nothing else. */ |
6358 | 6501 |
6434 /* Prepend to ATTR_LIST an entry for an attribute provided by GNAT_PRAGMA. */ | 6577 /* Prepend to ATTR_LIST an entry for an attribute provided by GNAT_PRAGMA. */ |
6435 | 6578 |
6436 static void | 6579 static void |
6437 prepend_one_attribute_pragma (struct attrib **attr_list, Node_Id gnat_pragma) | 6580 prepend_one_attribute_pragma (struct attrib **attr_list, Node_Id gnat_pragma) |
6438 { | 6581 { |
6439 const Node_Id gnat_arg = Pragma_Argument_Associations (gnat_pragma); | 6582 const Node_Id gnat_arg = First (Pragma_Argument_Associations (gnat_pragma)); |
6440 tree gnu_arg0 = NULL_TREE, gnu_arg1 = NULL_TREE; | 6583 Node_Id gnat_next_arg = Next (gnat_arg); |
6584 tree gnu_arg1 = NULL_TREE, gnu_arg_list = NULL_TREE; | |
6441 enum attrib_type etype; | 6585 enum attrib_type etype; |
6442 | 6586 |
6443 /* Map the pragma at hand. Skip if this isn't one we know how to handle. */ | 6587 /* Map the pragma at hand. Skip if this isn't one we know how to handle. */ |
6444 switch (Get_Pragma_Id (Chars (Pragma_Identifier (gnat_pragma)))) | 6588 switch (Get_Pragma_Id (Chars (Pragma_Identifier (gnat_pragma)))) |
6445 { | 6589 { |
6590 case Pragma_Linker_Alias: | |
6591 etype = ATTR_LINK_ALIAS; | |
6592 break; | |
6593 | |
6594 case Pragma_Linker_Constructor: | |
6595 etype = ATTR_LINK_CONSTRUCTOR; | |
6596 break; | |
6597 | |
6598 case Pragma_Linker_Destructor: | |
6599 etype = ATTR_LINK_DESTRUCTOR; | |
6600 break; | |
6601 | |
6602 case Pragma_Linker_Section: | |
6603 etype = ATTR_LINK_SECTION; | |
6604 break; | |
6605 | |
6446 case Pragma_Machine_Attribute: | 6606 case Pragma_Machine_Attribute: |
6447 etype = ATTR_MACHINE_ATTRIBUTE; | 6607 etype = ATTR_MACHINE_ATTRIBUTE; |
6448 break; | 6608 break; |
6449 | 6609 |
6450 case Pragma_Linker_Alias: | 6610 case Pragma_Thread_Local_Storage: |
6451 etype = ATTR_LINK_ALIAS; | 6611 etype = ATTR_THREAD_LOCAL_STORAGE; |
6452 break; | |
6453 | |
6454 case Pragma_Linker_Section: | |
6455 etype = ATTR_LINK_SECTION; | |
6456 break; | |
6457 | |
6458 case Pragma_Linker_Constructor: | |
6459 etype = ATTR_LINK_CONSTRUCTOR; | |
6460 break; | |
6461 | |
6462 case Pragma_Linker_Destructor: | |
6463 etype = ATTR_LINK_DESTRUCTOR; | |
6464 break; | 6612 break; |
6465 | 6613 |
6466 case Pragma_Weak_External: | 6614 case Pragma_Weak_External: |
6467 etype = ATTR_WEAK_EXTERNAL; | 6615 etype = ATTR_WEAK_EXTERNAL; |
6468 break; | 6616 break; |
6469 | 6617 |
6470 case Pragma_Thread_Local_Storage: | |
6471 etype = ATTR_THREAD_LOCAL_STORAGE; | |
6472 break; | |
6473 | |
6474 default: | 6618 default: |
6475 return; | 6619 return; |
6476 } | 6620 } |
6477 | 6621 |
6478 /* See what arguments we have and turn them into GCC trees for attribute | 6622 /* See what arguments we have and turn them into GCC trees for attribute |
6479 handlers. These expect identifier for strings. We handle at most two | 6623 handlers. The first one is always expected to be a string meant to be |
6480 arguments and static expressions only. */ | 6624 turned into an identifier. The next ones are all static expressions, |
6481 if (Present (gnat_arg) && Present (First (gnat_arg))) | 6625 among which strings meant to be turned into an identifier, except for |
6626 a couple of specific attributes that require raw strings. */ | |
6627 if (Present (gnat_next_arg)) | |
6482 { | 6628 { |
6483 Node_Id gnat_arg0 = Next (First (gnat_arg)); | 6629 gnu_arg1 = gnat_to_gnu (Expression (gnat_next_arg)); |
6484 Node_Id gnat_arg1 = Empty; | 6630 gcc_assert (TREE_CODE (gnu_arg1) == STRING_CST); |
6485 | 6631 |
6486 if (Present (gnat_arg0) | 6632 const char *const p = TREE_STRING_POINTER (gnu_arg1); |
6487 && Is_OK_Static_Expression (Expression (gnat_arg0))) | 6633 const bool string_args |
6634 = strcmp (p, "target") == 0 || strcmp (p, "target_clones") == 0; | |
6635 gnu_arg1 = get_identifier (p); | |
6636 if (IDENTIFIER_LENGTH (gnu_arg1) == 0) | |
6637 return; | |
6638 gnat_next_arg = Next (gnat_next_arg); | |
6639 | |
6640 while (Present (gnat_next_arg)) | |
6488 { | 6641 { |
6489 gnu_arg0 = gnat_to_gnu (Expression (gnat_arg0)); | 6642 tree gnu_arg = gnat_to_gnu (Expression (gnat_next_arg)); |
6490 | 6643 if (TREE_CODE (gnu_arg) == STRING_CST && !string_args) |
6491 if (TREE_CODE (gnu_arg0) == STRING_CST) | 6644 gnu_arg = get_identifier (TREE_STRING_POINTER (gnu_arg)); |
6492 { | 6645 gnu_arg_list |
6493 gnu_arg0 = get_identifier (TREE_STRING_POINTER (gnu_arg0)); | 6646 = chainon (gnu_arg_list, build_tree_list (NULL_TREE, gnu_arg)); |
6494 if (IDENTIFIER_LENGTH (gnu_arg0) == 0) | 6647 gnat_next_arg = Next (gnat_next_arg); |
6495 return; | |
6496 } | |
6497 | |
6498 gnat_arg1 = Next (gnat_arg0); | |
6499 } | |
6500 | |
6501 if (Present (gnat_arg1) | |
6502 && Is_OK_Static_Expression (Expression (gnat_arg1))) | |
6503 { | |
6504 gnu_arg1 = gnat_to_gnu (Expression (gnat_arg1)); | |
6505 | |
6506 if (TREE_CODE (gnu_arg1) == STRING_CST) | |
6507 gnu_arg1 = get_identifier (TREE_STRING_POINTER (gnu_arg1)); | |
6508 } | 6648 } |
6509 } | 6649 } |
6510 | 6650 |
6511 /* Prepend to the list. Make a list of the argument we might have, as GCC | 6651 prepend_one_attribute (attr_list, etype, gnu_arg1, gnu_arg_list, |
6512 expects it. */ | 6652 Present (Next (gnat_arg)) |
6513 prepend_one_attribute (attr_list, etype, gnu_arg0, | 6653 ? Expression (Next (gnat_arg)) : gnat_pragma); |
6514 gnu_arg1 | |
6515 ? build_tree_list (NULL_TREE, gnu_arg1) : NULL_TREE, | |
6516 Present (Next (First (gnat_arg))) | |
6517 ? Expression (Next (First (gnat_arg))) : gnat_pragma); | |
6518 } | 6654 } |
6519 | 6655 |
6520 /* Prepend to ATTR_LIST the list of attributes for GNAT_ENTITY, if any. */ | 6656 /* Prepend to ATTR_LIST the list of attributes for GNAT_ENTITY, if any. */ |
6521 | 6657 |
6522 static void | 6658 static void |
6702 && TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (ref, 0)))) | 6838 && TYPE_IS_FAT_POINTER_P (TREE_TYPE (TREE_OPERAND (ref, 0)))) |
6703 return build3 (COMPONENT_REF, TREE_TYPE (ref), | 6839 return build3 (COMPONENT_REF, TREE_TYPE (ref), |
6704 elaborate_reference_1 (TREE_OPERAND (ref, 0), data), | 6840 elaborate_reference_1 (TREE_OPERAND (ref, 0), data), |
6705 TREE_OPERAND (ref, 1), NULL_TREE); | 6841 TREE_OPERAND (ref, 1), NULL_TREE); |
6706 | 6842 |
6843 /* If this is the displacement of a pointer, elaborate the pointer and then | |
6844 displace the result. The actual purpose here is to drop the location on | |
6845 the expression, which may be problematic if replicated on references. */ | |
6846 if (TREE_CODE (ref) == POINTER_PLUS_EXPR | |
6847 && TREE_CODE (TREE_OPERAND (ref, 1)) == INTEGER_CST) | |
6848 return build2 (POINTER_PLUS_EXPR, TREE_TYPE (ref), | |
6849 elaborate_reference_1 (TREE_OPERAND (ref, 0), data), | |
6850 TREE_OPERAND (ref, 1)); | |
6851 | |
6707 sprintf (suffix, "EXP%d", ++er->n); | 6852 sprintf (suffix, "EXP%d", ++er->n); |
6708 return | 6853 return |
6709 elaborate_expression_1 (ref, er->entity, suffix, er->definition, false); | 6854 elaborate_expression_1 (ref, er->entity, suffix, er->definition, false); |
6710 } | 6855 } |
6711 | 6856 |
6795 build_binary_op (GE_EXPR, boolean_type_node, | 6940 build_binary_op (GE_EXPR, boolean_type_node, |
6796 gnu_operand, gnu_low, true), | 6941 gnu_operand, gnu_low, true), |
6797 build_binary_op (LE_EXPR, boolean_type_node, | 6942 build_binary_op (LE_EXPR, boolean_type_node, |
6798 gnu_operand, gnu_high, true), | 6943 gnu_operand, gnu_high, true), |
6799 true); | 6944 true); |
6945 else if (gnu_low == boolean_true_node | |
6946 && TREE_TYPE (gnu_operand) == boolean_type_node) | |
6947 gnu_test = gnu_operand; | |
6800 else if (gnu_low) | 6948 else if (gnu_low) |
6801 gnu_test | 6949 gnu_test |
6802 = build_binary_op (EQ_EXPR, boolean_type_node, gnu_operand, gnu_low, | 6950 = build_binary_op (EQ_EXPR, boolean_type_node, gnu_operand, gnu_low, |
6803 true); | 6951 true); |
6804 else | 6952 else |
6819 type FIELD_TYPE to be placed in RECORD_TYPE. Return the result. */ | 6967 type FIELD_TYPE to be placed in RECORD_TYPE. Return the result. */ |
6820 | 6968 |
6821 static int | 6969 static int |
6822 adjust_packed (tree field_type, tree record_type, int packed) | 6970 adjust_packed (tree field_type, tree record_type, int packed) |
6823 { | 6971 { |
6824 /* If the field contains an item of variable size, we cannot pack it | 6972 /* If the field contains an array with self-referential size, we'd better |
6825 because we cannot create temporaries of non-fixed size in case | 6973 not pack it because this would misalign it and, therefore, cause large |
6826 we need to take the address of the field. See addressable_p and | 6974 temporaries to be created in case we need to take the address of the |
6827 the notes on the addressability issues for further details. */ | 6975 field. See addressable_p and the notes on the addressability issues |
6828 if (type_has_variable_size (field_type)) | 6976 for further details. */ |
6977 if (AGGREGATE_TYPE_P (field_type) | |
6978 && aggregate_type_contains_array_p (field_type, true)) | |
6829 return 0; | 6979 return 0; |
6830 | 6980 |
6831 /* In the other cases, we can honor the packing. */ | 6981 /* In the other cases, we can honor the packing. */ |
6832 if (packed) | 6982 if (packed) |
6833 return packed; | 6983 return packed; |
6859 | 7009 |
6860 static tree | 7010 static tree |
6861 gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, | 7011 gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, |
6862 bool definition, bool debug_info_p) | 7012 bool definition, bool debug_info_p) |
6863 { | 7013 { |
7014 const Node_Id gnat_clause = Component_Clause (gnat_field); | |
6864 const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field)); | 7015 const Entity_Id gnat_record_type = Underlying_Type (Scope (gnat_field)); |
6865 const Entity_Id gnat_field_type = Etype (gnat_field); | 7016 const Entity_Id gnat_field_type = Etype (gnat_field); |
7017 tree gnu_field_type = gnat_to_gnu_type (gnat_field_type); | |
7018 tree gnu_field_id = get_entity_name (gnat_field); | |
6866 const bool is_atomic | 7019 const bool is_atomic |
6867 = (Is_Atomic_Or_VFA (gnat_field) || Is_Atomic_Or_VFA (gnat_field_type)); | 7020 = (Is_Atomic_Or_VFA (gnat_field) || Is_Atomic_Or_VFA (gnat_field_type)); |
6868 const bool is_aliased = Is_Aliased (gnat_field); | 7021 const bool is_aliased = Is_Aliased (gnat_field); |
6869 const bool is_independent | 7022 const bool is_independent |
6870 = (Is_Independent (gnat_field) || Is_Independent (gnat_field_type)); | 7023 = (Is_Independent (gnat_field) || Is_Independent (gnat_field_type)); |
6871 const bool is_volatile | 7024 const bool is_volatile |
6872 = (Treat_As_Volatile (gnat_field) || Treat_As_Volatile (gnat_field_type)); | 7025 = (Treat_As_Volatile (gnat_field) || Treat_As_Volatile (gnat_field_type)); |
7026 const bool is_by_ref = TYPE_IS_BY_REFERENCE_P (gnu_field_type); | |
6873 const bool is_strict_alignment = Strict_Alignment (gnat_field_type); | 7027 const bool is_strict_alignment = Strict_Alignment (gnat_field_type); |
6874 /* We used to consider that volatile fields also require strict alignment, | 7028 /* We used to consider that volatile fields also require strict alignment, |
6875 but that was an interpolation and would cause us to reject a pragma | 7029 but that was an interpolation and would cause us to reject a pragma |
6876 volatile on a packed record type containing boolean components, while | 7030 volatile on a packed record type containing boolean components, while |
6877 there is no basis to do so in the RM. In such cases, the writes will | 7031 there is no basis to do so in the RM. In such cases, the writes will |
6878 involve load-modify-store sequences, but that's OK for volatile. The | 7032 involve load-modify-store sequences, but that's OK for volatile. The |
6879 only constraint is the implementation advice whereby only the bits of | 7033 only constraint is the implementation advice whereby only the bits of |
6880 the components should be accessed if they both start and end on byte | 7034 the components should be accessed if they both start and end on byte |
6881 boundaries, but that should be guaranteed by the GCC memory model. */ | 7035 boundaries, but that should be guaranteed by the GCC memory model. |
6882 const bool needs_strict_alignment | 7036 Note that we have some redundancies (is_atomic => is_independent, |
6883 = (is_atomic || is_aliased || is_independent || is_strict_alignment); | 7037 is_aliased => is_independent and is_by_ref => is_strict_alignment) |
6884 tree gnu_field_type = gnat_to_gnu_type (gnat_field_type); | 7038 so the following formula is sufficient. */ |
6885 tree gnu_field_id = get_entity_name (gnat_field); | 7039 const bool needs_strict_alignment = (is_independent || is_strict_alignment); |
7040 const char *field_s, *size_s; | |
6886 tree gnu_field, gnu_size, gnu_pos; | 7041 tree gnu_field, gnu_size, gnu_pos; |
6887 | 7042 bool is_bitfield; |
6888 /* If this field requires strict alignment, we cannot pack it because | 7043 |
6889 it would very likely be under-aligned in the record. */ | 7044 /* The qualifier to be used in messages. */ |
7045 if (is_atomic) | |
7046 field_s = "atomic&"; | |
7047 else if (is_aliased) | |
7048 field_s = "aliased&"; | |
7049 else if (is_independent) | |
7050 field_s = "independent&"; | |
7051 else if (is_by_ref) | |
7052 field_s = "& with by-reference type"; | |
7053 else if (is_strict_alignment) | |
7054 field_s = "& with aliased part"; | |
7055 else | |
7056 field_s = "&"; | |
7057 | |
7058 /* The message to be used for incompatible size. */ | |
7059 if (is_atomic || is_aliased) | |
7060 size_s = "size for %s must be ^"; | |
7061 else if (field_s) | |
7062 size_s = "size for %s too small{, minimum allowed is ^}"; | |
7063 | |
7064 /* If a field requires strict alignment, we cannot pack it (RM 13.2(7)). */ | |
6890 if (needs_strict_alignment) | 7065 if (needs_strict_alignment) |
6891 packed = 0; | 7066 packed = 0; |
6892 else | 7067 else |
6893 packed = adjust_packed (gnu_field_type, gnu_record_type, packed); | 7068 packed = adjust_packed (gnu_field_type, gnu_record_type, packed); |
6894 | 7069 |
6895 /* If a size is specified, use it. Otherwise, if the record type is packed, | 7070 /* If a size is specified, use it. Otherwise, if the record type is packed, |
6896 use the official RM size. See "Handling of Type'Size Values" in Einfo | 7071 use the official RM size. See "Handling of Type'Size Values" in Einfo |
6897 for further details. */ | 7072 for further details. */ |
6898 if (Known_Esize (gnat_field)) | 7073 if (Present (gnat_clause) || Known_Esize (gnat_field)) |
6899 gnu_size = validate_size (Esize (gnat_field), gnu_field_type, | 7074 gnu_size = validate_size (Esize (gnat_field), gnu_field_type, gnat_field, |
6900 gnat_field, FIELD_DECL, false, true); | 7075 FIELD_DECL, false, true, size_s, field_s); |
6901 else if (packed == 1) | 7076 else if (packed == 1) |
6902 gnu_size = validate_size (RM_Size (gnat_field_type), gnu_field_type, | 7077 { |
6903 gnat_field, FIELD_DECL, false, true); | 7078 gnu_size = rm_size (gnu_field_type); |
7079 if (TREE_CODE (gnu_size) != INTEGER_CST) | |
7080 gnu_size = NULL_TREE; | |
7081 } | |
6904 else | 7082 else |
6905 gnu_size = NULL_TREE; | 7083 gnu_size = NULL_TREE; |
6906 | 7084 |
6907 /* If we have a specified size that is smaller than that of the field's type, | 7085 /* Likewise for the position. */ |
6908 or a position is specified, and the field's type is a record that doesn't | 7086 if (Present (gnat_clause)) |
6909 require strict alignment, see if we can get either an integral mode form | 7087 { |
6910 of the type or a smaller form. If we can, show a size was specified for | 7088 gnu_pos = UI_To_gnu (Component_Bit_Offset (gnat_field), bitsizetype); |
6911 the field if there wasn't one already, so we know to make this a bitfield | 7089 is_bitfield = !value_factor_p (gnu_pos, BITS_PER_UNIT); |
6912 and avoid making things wider. | 7090 } |
7091 | |
7092 /* If the record has rep clauses and this is the tag field, make a rep | |
7093 clause for it as well. */ | |
7094 else if (Has_Specified_Layout (gnat_record_type) | |
7095 && Chars (gnat_field) == Name_uTag) | |
7096 { | |
7097 gnu_pos = bitsize_zero_node; | |
7098 gnu_size = TYPE_SIZE (gnu_field_type); | |
7099 is_bitfield = false; | |
7100 } | |
7101 | |
7102 else | |
7103 { | |
7104 gnu_pos = NULL_TREE; | |
7105 is_bitfield = false; | |
7106 } | |
7107 | |
7108 /* If the field's type is a fixed-size record that does not require strict | |
7109 alignment, and the record is packed or we have a position specified for | |
7110 the field that makes it a bitfield or we have a specified size that is | |
7111 smaller than that of the field's type, then see if we can get either an | |
7112 integral mode form of the field's type or a smaller form. If we can, | |
7113 consider that a size was specified for the field if there wasn't one | |
7114 already, so we know to make it a bitfield and avoid making things wider. | |
6913 | 7115 |
6914 Changing to an integral mode form is useful when the record is packed as | 7116 Changing to an integral mode form is useful when the record is packed as |
6915 we can then place the field at a non-byte-aligned position and so achieve | 7117 we can then place the field at a non-byte-aligned position and so achieve |
6916 tighter packing. This is in addition required if the field shares a byte | 7118 tighter packing. This is in addition required if the field shares a byte |
6917 with another field and the front-end lets the back-end handle the access | 7119 with another field and the front-end lets the back-end handle the access |
6929 if (!needs_strict_alignment | 7131 if (!needs_strict_alignment |
6930 && RECORD_OR_UNION_TYPE_P (gnu_field_type) | 7132 && RECORD_OR_UNION_TYPE_P (gnu_field_type) |
6931 && !TYPE_FAT_POINTER_P (gnu_field_type) | 7133 && !TYPE_FAT_POINTER_P (gnu_field_type) |
6932 && tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type)) | 7134 && tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type)) |
6933 && (packed == 1 | 7135 && (packed == 1 |
7136 || is_bitfield | |
6934 || (gnu_size | 7137 || (gnu_size |
6935 && (tree_int_cst_lt (gnu_size, TYPE_SIZE (gnu_field_type)) | 7138 && tree_int_cst_lt (gnu_size, TYPE_SIZE (gnu_field_type))))) |
6936 || (Present (Component_Clause (gnat_field)) | |
6937 && !(UI_To_Int (Component_Bit_Offset (gnat_field)) | |
6938 % BITS_PER_UNIT == 0 | |
6939 && value_factor_p (gnu_size, BITS_PER_UNIT))))))) | |
6940 { | 7139 { |
6941 tree gnu_packable_type = make_packable_type (gnu_field_type, true); | 7140 tree gnu_packable_type |
7141 = make_packable_type (gnu_field_type, true, is_bitfield ? 1 : 0); | |
6942 if (gnu_packable_type != gnu_field_type) | 7142 if (gnu_packable_type != gnu_field_type) |
6943 { | 7143 { |
6944 gnu_field_type = gnu_packable_type; | 7144 gnu_field_type = gnu_packable_type; |
6945 if (!gnu_size) | 7145 if (!gnu_size) |
6946 gnu_size = rm_size (gnu_field_type); | 7146 gnu_size = rm_size (gnu_field_type); |
6947 } | 7147 } |
6948 } | 7148 } |
6949 | 7149 |
7150 /* Now check if the type of the field allows atomic access. */ | |
6950 if (Is_Atomic_Or_VFA (gnat_field)) | 7151 if (Is_Atomic_Or_VFA (gnat_field)) |
6951 { | 7152 { |
6952 const unsigned int align | 7153 const unsigned int align |
6953 = promote_object_alignment (gnu_field_type, gnat_field); | 7154 = promote_object_alignment (gnu_field_type, gnat_field); |
6954 if (align > 0) | 7155 if (align > 0) |
6956 = maybe_pad_type (gnu_field_type, NULL_TREE, align, gnat_field, | 7157 = maybe_pad_type (gnu_field_type, NULL_TREE, align, gnat_field, |
6957 false, false, definition, true); | 7158 false, false, definition, true); |
6958 check_ok_for_atomic_type (gnu_field_type, gnat_field, false); | 7159 check_ok_for_atomic_type (gnu_field_type, gnat_field, false); |
6959 } | 7160 } |
6960 | 7161 |
6961 if (Present (Component_Clause (gnat_field))) | 7162 /* If a position is specified, check that it is valid. */ |
7163 if (gnu_pos) | |
6962 { | 7164 { |
6963 Node_Id gnat_clause = Component_Clause (gnat_field); | |
6964 Entity_Id gnat_parent = Parent_Subtype (gnat_record_type); | 7165 Entity_Id gnat_parent = Parent_Subtype (gnat_record_type); |
6965 | |
6966 gnu_pos = UI_To_gnu (Component_Bit_Offset (gnat_field), bitsizetype); | |
6967 gnu_size = validate_size (Esize (gnat_field), gnu_field_type, | |
6968 gnat_field, FIELD_DECL, false, true); | |
6969 | 7166 |
6970 /* Ensure the position does not overlap with the parent subtype, if there | 7167 /* Ensure the position does not overlap with the parent subtype, if there |
6971 is one. This test is omitted if the parent of the tagged type has a | 7168 is one. This test is omitted if the parent of the tagged type has a |
6972 full rep clause since, in this case, component clauses are allowed to | 7169 full rep clause since, in this case, component clauses are allowed to |
6973 overlay the space allocated for the parent type and the front-end has | 7170 overlay the space allocated for the parent type and the front-end has |
6977 tree gnu_parent = gnat_to_gnu_type (gnat_parent); | 7174 tree gnu_parent = gnat_to_gnu_type (gnat_parent); |
6978 | 7175 |
6979 if (TREE_CODE (TYPE_SIZE (gnu_parent)) == INTEGER_CST | 7176 if (TREE_CODE (TYPE_SIZE (gnu_parent)) == INTEGER_CST |
6980 && tree_int_cst_lt (gnu_pos, TYPE_SIZE (gnu_parent))) | 7177 && tree_int_cst_lt (gnu_pos, TYPE_SIZE (gnu_parent))) |
6981 post_error_ne_tree | 7178 post_error_ne_tree |
6982 ("offset of& must be beyond parent{, minimum allowed is ^}", | 7179 ("position for& must be beyond parent{, minimum allowed is ^}", |
6983 Position (gnat_clause), gnat_field, TYPE_SIZE_UNIT (gnu_parent)); | 7180 Position (gnat_clause), gnat_field, TYPE_SIZE_UNIT (gnu_parent)); |
6984 } | 7181 } |
6985 | 7182 |
6986 /* If this field needs strict alignment, make sure that the record is | 7183 /* If this field needs strict alignment, make sure that the record is |
6987 sufficiently aligned and that the position and size are consistent | 7184 sufficiently aligned and that the position and size are consistent |
6996 | 7193 |
6997 if (TYPE_ALIGN (gnu_record_type) | 7194 if (TYPE_ALIGN (gnu_record_type) |
6998 && TYPE_ALIGN (gnu_record_type) < type_align) | 7195 && TYPE_ALIGN (gnu_record_type) < type_align) |
6999 SET_TYPE_ALIGN (gnu_record_type, type_align); | 7196 SET_TYPE_ALIGN (gnu_record_type, type_align); |
7000 | 7197 |
7198 /* If the position is not a multiple of the storage unit, then error | |
7199 out and reset the position. */ | |
7200 if (!integer_zerop (size_binop (TRUNC_MOD_EXPR, gnu_pos, | |
7201 bitsize_unit_node))) | |
7202 { | |
7203 char s[128]; | |
7204 snprintf (s, sizeof (s), "position for %s must be " | |
7205 "multiple of Storage_Unit", field_s); | |
7206 post_error_ne (s, First_Bit (gnat_clause), gnat_field); | |
7207 gnu_pos = NULL_TREE; | |
7208 } | |
7209 | |
7001 /* If the position is not a multiple of the alignment of the type, | 7210 /* If the position is not a multiple of the alignment of the type, |
7002 then error out and reset the position. */ | 7211 then error out and reset the position. */ |
7003 if (!integer_zerop (size_binop (TRUNC_MOD_EXPR, gnu_pos, | 7212 else if (type_align > BITS_PER_UNIT |
7004 bitsize_int (type_align)))) | 7213 && !integer_zerop (size_binop (TRUNC_MOD_EXPR, gnu_pos, |
7214 bitsize_int (type_align)))) | |
7005 { | 7215 { |
7006 const char *s; | 7216 char s[128]; |
7007 | 7217 snprintf (s, sizeof (s), "position for %s must be multiple of ^", |
7008 if (is_atomic) | 7218 field_s); |
7009 s = "position of atomic field& must be multiple of ^ bits"; | |
7010 else if (is_aliased) | |
7011 s = "position of aliased field& must be multiple of ^ bits"; | |
7012 else if (is_independent) | |
7013 s = "position of independent field& must be multiple of ^ bits"; | |
7014 else if (is_strict_alignment) | |
7015 s = "position of & with aliased or tagged part must be" | |
7016 " multiple of ^ bits"; | |
7017 else | |
7018 gcc_unreachable (); | |
7019 | |
7020 post_error_ne_num (s, First_Bit (gnat_clause), gnat_field, | 7219 post_error_ne_num (s, First_Bit (gnat_clause), gnat_field, |
7021 type_align); | 7220 type_align / BITS_PER_UNIT); |
7221 post_error_ne_num ("\\because alignment of its type& is ^", | |
7222 First_Bit (gnat_clause), Etype (gnat_field), | |
7223 type_align / BITS_PER_UNIT); | |
7022 gnu_pos = NULL_TREE; | 7224 gnu_pos = NULL_TREE; |
7023 } | 7225 } |
7024 | 7226 |
7025 if (gnu_size) | 7227 if (gnu_size) |
7026 { | 7228 { |
7027 tree gnu_type_size = TYPE_SIZE (gnu_field_type); | 7229 tree type_size = TYPE_SIZE (gnu_field_type); |
7028 const int cmp = tree_int_cst_compare (gnu_size, gnu_type_size); | 7230 int cmp; |
7231 | |
7232 /* If the size is not a multiple of the storage unit, then error | |
7233 out and reset the size. */ | |
7234 if (!integer_zerop (size_binop (TRUNC_MOD_EXPR, gnu_size, | |
7235 bitsize_unit_node))) | |
7236 { | |
7237 char s[128]; | |
7238 snprintf (s, sizeof (s), "size for %s must be " | |
7239 "multiple of Storage_Unit", field_s); | |
7240 post_error_ne (s, Last_Bit (gnat_clause), gnat_field); | |
7241 gnu_size = NULL_TREE; | |
7242 } | |
7029 | 7243 |
7030 /* If the size is lower than that of the type, or greater for | 7244 /* If the size is lower than that of the type, or greater for |
7031 atomic and aliased, then error out and reset the size. */ | 7245 atomic and aliased, then error out and reset the size. */ |
7032 if (cmp < 0 || (cmp > 0 && (is_atomic || is_aliased))) | 7246 else if ((cmp = tree_int_cst_compare (gnu_size, type_size)) < 0 |
7247 || (cmp > 0 && (is_atomic || is_aliased))) | |
7033 { | 7248 { |
7034 const char *s; | 7249 char s[128]; |
7035 | 7250 snprintf (s, sizeof (s), size_s, field_s); |
7036 if (is_atomic) | |
7037 s = "size of atomic field& must be ^ bits"; | |
7038 else if (is_aliased) | |
7039 s = "size of aliased field& must be ^ bits"; | |
7040 else if (is_independent) | |
7041 s = "size of independent field& must be at least ^ bits"; | |
7042 else if (is_strict_alignment) | |
7043 s = "size of & with aliased or tagged part must be" | |
7044 " at least ^ bits"; | |
7045 else | |
7046 gcc_unreachable (); | |
7047 | |
7048 post_error_ne_tree (s, Last_Bit (gnat_clause), gnat_field, | 7251 post_error_ne_tree (s, Last_Bit (gnat_clause), gnat_field, |
7049 gnu_type_size); | 7252 type_size); |
7050 gnu_size = NULL_TREE; | |
7051 } | |
7052 | |
7053 /* Likewise if the size is not a multiple of a byte, */ | |
7054 else if (!integer_zerop (size_binop (TRUNC_MOD_EXPR, gnu_size, | |
7055 bitsize_unit_node))) | |
7056 { | |
7057 const char *s; | |
7058 | |
7059 if (is_independent) | |
7060 s = "size of independent field& must be multiple of" | |
7061 " Storage_Unit"; | |
7062 else if (is_strict_alignment) | |
7063 s = "size of & with aliased or tagged part must be" | |
7064 " multiple of Storage_Unit"; | |
7065 else | |
7066 gcc_unreachable (); | |
7067 | |
7068 post_error_ne (s, Last_Bit (gnat_clause), gnat_field); | |
7069 gnu_size = NULL_TREE; | 7253 gnu_size = NULL_TREE; |
7070 } | 7254 } |
7071 } | 7255 } |
7072 } | 7256 } |
7073 } | 7257 } |
7074 | 7258 |
7075 /* If the record has rep clauses and this is the tag field, make a rep | |
7076 clause for it as well. */ | |
7077 else if (Has_Specified_Layout (gnat_record_type) | |
7078 && Chars (gnat_field) == Name_uTag) | |
7079 { | |
7080 gnu_pos = bitsize_zero_node; | |
7081 gnu_size = TYPE_SIZE (gnu_field_type); | |
7082 } | |
7083 | |
7084 else | 7259 else |
7085 { | 7260 { |
7086 gnu_pos = NULL_TREE; | |
7087 | |
7088 /* If we are packing the record and the field is BLKmode, round the | 7261 /* If we are packing the record and the field is BLKmode, round the |
7089 size up to a byte boundary. */ | 7262 size up to a byte boundary. */ |
7090 if (packed && TYPE_MODE (gnu_field_type) == BLKmode && gnu_size) | 7263 if (packed && TYPE_MODE (gnu_field_type) == BLKmode && gnu_size) |
7091 gnu_size = round_up (gnu_size, BITS_PER_UNIT); | 7264 gnu_size = round_up (gnu_size, BITS_PER_UNIT); |
7092 } | 7265 } |
7128 if (!needs_strict_alignment | 7301 if (!needs_strict_alignment |
7129 && TYPE_IS_PADDING_P (gnu_field_type) | 7302 && TYPE_IS_PADDING_P (gnu_field_type) |
7130 && INTEGRAL_TYPE_P (TREE_TYPE (TYPE_FIELDS (gnu_field_type)))) | 7303 && INTEGRAL_TYPE_P (TREE_TYPE (TYPE_FIELDS (gnu_field_type)))) |
7131 gnu_field_type = TREE_TYPE (TYPE_FIELDS (gnu_field_type)); | 7304 gnu_field_type = TREE_TYPE (TYPE_FIELDS (gnu_field_type)); |
7132 | 7305 |
7306 orig_field_type = gnu_field_type; | |
7133 gnu_field_type | 7307 gnu_field_type |
7134 = make_type_from_size (gnu_field_type, gnu_size, | 7308 = make_type_from_size (gnu_field_type, gnu_size, |
7135 Has_Biased_Representation (gnat_field)); | 7309 Has_Biased_Representation (gnat_field)); |
7310 | |
7311 /* If the type has been extended, we may need to cap the alignment. */ | |
7312 if (!needs_strict_alignment | |
7313 && gnu_field_type != orig_field_type | |
7314 && tree_int_cst_lt (TYPE_SIZE (orig_field_type), gnu_size)) | |
7315 packed = adjust_packed (gnu_field_type, gnu_record_type, packed); | |
7136 | 7316 |
7137 orig_field_type = gnu_field_type; | 7317 orig_field_type = gnu_field_type; |
7138 gnu_field_type = maybe_pad_type (gnu_field_type, gnu_size, 0, gnat_field, | 7318 gnu_field_type = maybe_pad_type (gnu_field_type, gnu_size, 0, gnat_field, |
7139 false, false, definition, true); | 7319 false, false, definition, true); |
7140 | 7320 |
7169 gnu_size, gnu_pos, packed, is_aliased); | 7349 gnu_size, gnu_pos, packed, is_aliased); |
7170 Sloc_to_locus (Sloc (gnat_field), &DECL_SOURCE_LOCATION (gnu_field)); | 7350 Sloc_to_locus (Sloc (gnat_field), &DECL_SOURCE_LOCATION (gnu_field)); |
7171 DECL_ALIASED_P (gnu_field) = is_aliased; | 7351 DECL_ALIASED_P (gnu_field) = is_aliased; |
7172 TREE_SIDE_EFFECTS (gnu_field) = TREE_THIS_VOLATILE (gnu_field) = is_volatile; | 7352 TREE_SIDE_EFFECTS (gnu_field) = TREE_THIS_VOLATILE (gnu_field) = is_volatile; |
7173 | 7353 |
7354 /* If this is a discriminant, then we treat it specially: first, we set its | |
7355 index number for the back-annotation; second, we record whether it cannot | |
7356 be changed once it has been set for the computation of loop invariants; | |
7357 third, we make it addressable in order for the optimizer to more easily | |
7358 see that it cannot be modified by assignments to the other fields of the | |
7359 record (see create_field_decl for a more detailed explanation), which is | |
7360 crucial to hoist the offset and size computations of dynamic fields. */ | |
7174 if (Ekind (gnat_field) == E_Discriminant) | 7361 if (Ekind (gnat_field) == E_Discriminant) |
7175 { | 7362 { |
7363 DECL_DISCRIMINANT_NUMBER (gnu_field) | |
7364 = UI_To_gnu (Discriminant_Number (gnat_field), sizetype); | |
7176 DECL_INVARIANT_P (gnu_field) | 7365 DECL_INVARIANT_P (gnu_field) |
7177 = No (Discriminant_Default_Value (gnat_field)); | 7366 = No (Discriminant_Default_Value (gnat_field)); |
7178 DECL_DISCRIMINANT_NUMBER (gnu_field) | 7367 DECL_NONADDRESSABLE_P (gnu_field) = 0; |
7179 = UI_To_gnu (Discriminant_Number (gnat_field), sizetype); | |
7180 } | 7368 } |
7181 | 7369 |
7182 return gnu_field; | 7370 return gnu_field; |
7183 } | 7371 } |
7184 | 7372 |
7194 Present (component_decl); | 7382 Present (component_decl); |
7195 component_decl = Next_Non_Pragma (component_decl)) | 7383 component_decl = Next_Non_Pragma (component_decl)) |
7196 { | 7384 { |
7197 Entity_Id gnat_field = Defining_Entity (component_decl); | 7385 Entity_Id gnat_field = Defining_Entity (component_decl); |
7198 | 7386 |
7199 if (Is_Aliased (gnat_field)) | 7387 if (Is_Independent (gnat_field) || Is_Independent (Etype (gnat_field))) |
7200 return true; | 7388 return true; |
7201 | 7389 |
7202 if (Strict_Alignment (Etype (gnat_field))) | 7390 if (Strict_Alignment (Etype (gnat_field))) |
7203 return true; | 7391 return true; |
7204 } | 7392 } |
7205 | 7393 |
7206 return false; | 7394 return false; |
7207 } | 7395 } |
7208 | 7396 |
7209 /* Return true if TYPE is a type with variable size or a padding type with a | |
7210 field of variable size or a record that has a field with such a type. */ | |
7211 | |
7212 static bool | |
7213 type_has_variable_size (tree type) | |
7214 { | |
7215 tree field; | |
7216 | |
7217 if (!TREE_CONSTANT (TYPE_SIZE (type))) | |
7218 return true; | |
7219 | |
7220 if (TYPE_IS_PADDING_P (type) | |
7221 && !TREE_CONSTANT (DECL_SIZE (TYPE_FIELDS (type)))) | |
7222 return true; | |
7223 | |
7224 if (!RECORD_OR_UNION_TYPE_P (type)) | |
7225 return false; | |
7226 | |
7227 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) | |
7228 if (type_has_variable_size (TREE_TYPE (field))) | |
7229 return true; | |
7230 | |
7231 return false; | |
7232 } | |
7233 | |
7234 /* Return true if FIELD is an artificial field. */ | 7397 /* Return true if FIELD is an artificial field. */ |
7235 | 7398 |
7236 static bool | 7399 static bool |
7237 field_is_artificial (tree field) | 7400 field_is_artificial (tree field) |
7238 { | 7401 { |
7464 const bool needs_xv_encodings | 7627 const bool needs_xv_encodings |
7465 = debug_info && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL; | 7628 = debug_info && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL; |
7466 bool all_rep_and_size = all_rep && TYPE_SIZE (gnu_record_type); | 7629 bool all_rep_and_size = all_rep && TYPE_SIZE (gnu_record_type); |
7467 bool variants_have_rep = all_rep; | 7630 bool variants_have_rep = all_rep; |
7468 bool layout_with_rep = false; | 7631 bool layout_with_rep = false; |
7632 bool has_non_packed_fixed_size_field = false; | |
7469 bool has_self_field = false; | 7633 bool has_self_field = false; |
7470 bool has_aliased_after_self_field = false; | 7634 bool has_aliased_after_self_field = false; |
7471 Entity_Id gnat_component_decl, gnat_variant_part; | 7635 Entity_Id gnat_component_decl, gnat_variant_part; |
7472 tree gnu_field, gnu_next, gnu_last; | 7636 tree gnu_field, gnu_next, gnu_last; |
7473 tree gnu_variant_part = NULL_TREE; | 7637 tree gnu_variant_part = NULL_TREE; |
7520 /* And record information for the final layout. */ | 7684 /* And record information for the final layout. */ |
7521 if (field_has_self_size (gnu_field)) | 7685 if (field_has_self_size (gnu_field)) |
7522 has_self_field = true; | 7686 has_self_field = true; |
7523 else if (has_self_field && DECL_ALIASED_P (gnu_field)) | 7687 else if (has_self_field && DECL_ALIASED_P (gnu_field)) |
7524 has_aliased_after_self_field = true; | 7688 has_aliased_after_self_field = true; |
7689 else if (!DECL_FIELD_OFFSET (gnu_field) | |
7690 && !DECL_PACKED (gnu_field) | |
7691 && !field_has_variable_size (gnu_field)) | |
7692 has_non_packed_fixed_size_field = true; | |
7525 } | 7693 } |
7526 } | 7694 } |
7527 | 7695 |
7528 save_gnu_tree (gnat_field, gnu_field, false); | 7696 save_gnu_tree (gnat_field, gnu_field, false); |
7529 } | 7697 } |
7544 tree gnu_discr = gnat_to_gnu (gnat_discr); | 7712 tree gnu_discr = gnat_to_gnu (gnat_discr); |
7545 tree gnu_name = TYPE_IDENTIFIER (gnu_record_type); | 7713 tree gnu_name = TYPE_IDENTIFIER (gnu_record_type); |
7546 tree gnu_var_name | 7714 tree gnu_var_name |
7547 = concat_name (get_identifier (Get_Name_String (Chars (gnat_discr))), | 7715 = concat_name (get_identifier (Get_Name_String (Chars (gnat_discr))), |
7548 "XVN"); | 7716 "XVN"); |
7549 tree gnu_union_type, gnu_union_name; | 7717 tree gnu_union_name |
7718 = concat_name (gnu_name, IDENTIFIER_POINTER (gnu_var_name)); | |
7719 tree gnu_union_type; | |
7550 tree this_first_free_pos, gnu_variant_list = NULL_TREE; | 7720 tree this_first_free_pos, gnu_variant_list = NULL_TREE; |
7551 bool union_field_needs_strict_alignment = false; | 7721 bool union_field_needs_strict_alignment = false; |
7552 auto_vec <vinfo_t, 16> variant_types; | 7722 auto_vec <vinfo_t, 16> variant_types; |
7553 vinfo_t *gnu_variant; | 7723 vinfo_t *gnu_variant; |
7554 unsigned int variants_align = 0; | 7724 unsigned int variants_align = 0; |
7555 unsigned int i; | 7725 unsigned int i; |
7556 | |
7557 gnu_union_name | |
7558 = concat_name (gnu_name, IDENTIFIER_POINTER (gnu_var_name)); | |
7559 | 7726 |
7560 /* Reuse the enclosing union if this is an Unchecked_Union whose fields | 7727 /* Reuse the enclosing union if this is an Unchecked_Union whose fields |
7561 are all in the variant part, to match the layout of C unions. There | 7728 are all in the variant part, to match the layout of C unions. There |
7562 is an associated check below. */ | 7729 is an associated check below. */ |
7563 if (TREE_CODE (gnu_record_type) == UNION_TYPE) | 7730 if (TREE_CODE (gnu_record_type) == UNION_TYPE) |
7812 with self-referential size, variable size and fixed size not a multiple | 7979 with self-referential size, variable size and fixed size not a multiple |
7813 of a byte, so that they don't cause the regular fields to be either at | 7980 of a byte, so that they don't cause the regular fields to be either at |
7814 self-referential/variable offset or misaligned. Note, in the latter | 7981 self-referential/variable offset or misaligned. Note, in the latter |
7815 case, that this can only happen in packed record types so the alignment | 7982 case, that this can only happen in packed record types so the alignment |
7816 is effectively capped to the byte for the whole record. But we don't | 7983 is effectively capped to the byte for the whole record. But we don't |
7817 do it for non-packed record types if pragma Optimize_Alignment (Space) | 7984 do it for packed record types if not all fixed-size fiels can be packed |
7818 is specified because this can prevent alignment gaps from being filled. | 7985 and for non-packed record types if pragma Optimize_Alignment (Space) is |
7986 specified, because this can prevent alignment gaps from being filled. | |
7819 | 7987 |
7820 Optionally, if the layout warning is enabled, keep track of the above 4 | 7988 Optionally, if the layout warning is enabled, keep track of the above 4 |
7821 different kinds of fields and issue a warning if some of them would be | 7989 different kinds of fields and issue a warning if some of them would be |
7822 (or are being) reordered by the reordering mechanism. | 7990 (or are being) reordered by the reordering mechanism. |
7823 | 7991 |
7824 ??? If we reorder fields, the debugging information will be affected and | 7992 ??? If we reorder fields, the debugging information will be affected and |
7825 the debugger print fields in a different order from the source code. */ | 7993 the debugger print fields in a different order from the source code. */ |
7826 const bool do_reorder | 7994 const bool do_reorder |
7827 = (Convention (gnat_record_type) == Convention_Ada | 7995 = (Convention (gnat_record_type) == Convention_Ada |
7828 && !No_Reordering (gnat_record_type) | 7996 && !No_Reordering (gnat_record_type) |
7829 && (!Optimize_Alignment_Space (gnat_record_type) | 7997 && !(Is_Packed (gnat_record_type) |
7830 || Is_Packed (gnat_record_type)) | 7998 ? has_non_packed_fixed_size_field |
7831 && !debug__debug_flag_dot_r); | 7999 : Optimize_Alignment_Space (gnat_record_type)) |
8000 && !Debug_Flag_Dot_R); | |
7832 const bool w_reorder | 8001 const bool w_reorder |
7833 = (Convention (gnat_record_type) == Convention_Ada | 8002 = (Convention (gnat_record_type) == Convention_Ada |
7834 && Warn_On_Questionable_Layout | 8003 && Warn_On_Questionable_Layout |
7835 && !(No_Reordering (gnat_record_type) && GNAT_Mode)); | 8004 && !(No_Reordering (gnat_record_type) && GNAT_Mode)); |
7836 const bool in_variant = (p_gnu_rep_list != NULL); | 8005 const bool in_variant = (p_gnu_rep_list != NULL); |
7865 continue; | 8034 continue; |
7866 } | 8035 } |
7867 | 8036 |
7868 if (DECL_SIZE (gnu_field) && integer_zerop (DECL_SIZE (gnu_field))) | 8037 if (DECL_SIZE (gnu_field) && integer_zerop (DECL_SIZE (gnu_field))) |
7869 { | 8038 { |
8039 DECL_SIZE_UNIT (gnu_field) = size_zero_node; | |
7870 DECL_FIELD_OFFSET (gnu_field) = size_zero_node; | 8040 DECL_FIELD_OFFSET (gnu_field) = size_zero_node; |
7871 SET_DECL_OFFSET_ALIGN (gnu_field, BIGGEST_ALIGNMENT); | 8041 SET_DECL_OFFSET_ALIGN (gnu_field, BIGGEST_ALIGNMENT); |
7872 DECL_FIELD_BIT_OFFSET (gnu_field) = bitsize_zero_node; | 8042 DECL_FIELD_BIT_OFFSET (gnu_field) = bitsize_zero_node; |
7873 if (DECL_ALIASED_P (gnu_field)) | 8043 if (DECL_ALIASED_P (gnu_field)) |
7874 SET_TYPE_ALIGN (gnu_record_type, | 8044 SET_TYPE_ALIGN (gnu_record_type, |
8126 | 8296 |
8127 if (layout_with_rep) | 8297 if (layout_with_rep) |
8128 gnu_field_list = gnu_rep_list; | 8298 gnu_field_list = gnu_rep_list; |
8129 else | 8299 else |
8130 { | 8300 { |
8301 TYPE_NAME (gnu_rep_type) | |
8302 = create_concat_name (gnat_record_type, "REP"); | |
8131 TYPE_REVERSE_STORAGE_ORDER (gnu_rep_type) | 8303 TYPE_REVERSE_STORAGE_ORDER (gnu_rep_type) |
8132 = TYPE_REVERSE_STORAGE_ORDER (gnu_record_type); | 8304 = TYPE_REVERSE_STORAGE_ORDER (gnu_record_type); |
8133 finish_record_type (gnu_rep_type, gnu_rep_list, 1, debug_info); | 8305 finish_record_type (gnu_rep_type, gnu_rep_list, 1, debug_info); |
8134 | 8306 |
8135 /* If FIRST_FREE_POS is nonzero, we need to ensure that the fields | 8307 /* If FIRST_FREE_POS is nonzero, we need to ensure that the fields |
8144 } | 8316 } |
8145 } | 8317 } |
8146 | 8318 |
8147 /* Chain the variant part at the end of the field list. */ | 8319 /* Chain the variant part at the end of the field list. */ |
8148 if (gnu_variant_part) | 8320 if (gnu_variant_part) |
8149 { | 8321 gnu_field_list = chainon (gnu_field_list, gnu_variant_part); |
8150 /* We make an exception if the variant part is at offset 0, has a fixed | |
8151 size, and there is a single rep'ed field placed after it because, in | |
8152 this case, there is an obvious order of increasing position. */ | |
8153 if (variants_have_rep | |
8154 && TREE_CODE (DECL_SIZE_UNIT (gnu_variant_part)) == INTEGER_CST | |
8155 && gnu_rep_list | |
8156 && gnu_field_list == gnu_rep_list | |
8157 && !tree_int_cst_lt (DECL_FIELD_OFFSET (gnu_rep_list), | |
8158 DECL_SIZE_UNIT (gnu_variant_part))) | |
8159 { | |
8160 DECL_CHAIN (gnu_variant_part) = gnu_field_list; | |
8161 gnu_field_list = gnu_variant_part; | |
8162 } | |
8163 else | |
8164 gnu_field_list = chainon (gnu_field_list, gnu_variant_part); | |
8165 } | |
8166 | 8322 |
8167 if (cancel_alignment) | 8323 if (cancel_alignment) |
8168 SET_TYPE_ALIGN (gnu_record_type, 0); | 8324 SET_TYPE_ALIGN (gnu_record_type, 0); |
8169 | 8325 |
8170 TYPE_ARTIFICIAL (gnu_record_type) = artificial; | 8326 TYPE_ARTIFICIAL (gnu_record_type) = artificial; |
8283 case GT_EXPR: tcode = Gt_Expr; break; | 8439 case GT_EXPR: tcode = Gt_Expr; break; |
8284 case GE_EXPR: tcode = Ge_Expr; break; | 8440 case GE_EXPR: tcode = Ge_Expr; break; |
8285 case EQ_EXPR: tcode = Eq_Expr; break; | 8441 case EQ_EXPR: tcode = Eq_Expr; break; |
8286 case NE_EXPR: tcode = Ne_Expr; break; | 8442 case NE_EXPR: tcode = Ne_Expr; break; |
8287 | 8443 |
8444 case PLUS_EXPR: | |
8445 /* Turn addition of negative constant into subtraction. */ | |
8446 if (TREE_CODE (TREE_OPERAND (gnu_size, 1)) == INTEGER_CST | |
8447 && tree_int_cst_sign_bit (TREE_OPERAND (gnu_size, 1))) | |
8448 { | |
8449 tcode = Minus_Expr; | |
8450 wide_int wop1 = -wi::to_wide (TREE_OPERAND (gnu_size, 1)); | |
8451 ops[1] = annotate_value (wide_int_to_tree (sizetype, wop1)); | |
8452 break; | |
8453 } | |
8454 | |
8455 /* ... fall through ... */ | |
8456 | |
8288 case MULT_EXPR: | 8457 case MULT_EXPR: |
8289 case PLUS_EXPR: | |
8290 tcode = (TREE_CODE (gnu_size) == MULT_EXPR ? Mult_Expr : Plus_Expr); | 8458 tcode = (TREE_CODE (gnu_size) == MULT_EXPR ? Mult_Expr : Plus_Expr); |
8291 /* Fold conversions from bytes to bits into inner operations. */ | 8459 /* Fold conversions from bytes to bits into inner operations. */ |
8292 if (TREE_CODE (TREE_OPERAND (gnu_size, 1)) == INTEGER_CST | 8460 if (TREE_CODE (TREE_OPERAND (gnu_size, 1)) == INTEGER_CST |
8293 && CONVERT_EXPR_P (TREE_OPERAND (gnu_size, 0))) | 8461 && CONVERT_EXPR_P (TREE_OPERAND (gnu_size, 0))) |
8294 { | 8462 { |
8295 tree inner_op = TREE_OPERAND (TREE_OPERAND (gnu_size, 0), 0); | 8463 tree inner_op = TREE_OPERAND (TREE_OPERAND (gnu_size, 0), 0); |
8296 if (TREE_CODE (inner_op) == TREE_CODE (gnu_size) | 8464 if (TREE_CODE (inner_op) == TREE_CODE (gnu_size) |
8297 && TREE_CODE (TREE_OPERAND (inner_op, 1)) == INTEGER_CST) | 8465 && TREE_CODE (TREE_OPERAND (inner_op, 1)) == INTEGER_CST) |
8298 { | 8466 { |
8467 ops[0] = annotate_value (TREE_OPERAND (inner_op, 0)); | |
8299 tree inner_op_op1 = TREE_OPERAND (inner_op, 1); | 8468 tree inner_op_op1 = TREE_OPERAND (inner_op, 1); |
8300 tree gnu_size_op1 = TREE_OPERAND (gnu_size, 1); | 8469 tree gnu_size_op1 = TREE_OPERAND (gnu_size, 1); |
8301 widest_int op1; | 8470 widest_int op1; |
8302 if (TREE_CODE (gnu_size) == MULT_EXPR) | 8471 if (TREE_CODE (gnu_size) == MULT_EXPR) |
8303 op1 = (wi::to_widest (inner_op_op1) | 8472 op1 = (wi::to_widest (inner_op_op1) |
8304 * wi::to_widest (gnu_size_op1)); | 8473 * wi::to_widest (gnu_size_op1)); |
8305 else | 8474 else |
8306 op1 = (wi::to_widest (inner_op_op1) | 8475 { |
8307 + wi::to_widest (gnu_size_op1)); | 8476 op1 = (wi::to_widest (inner_op_op1) |
8308 ops[1] = UI_From_gnu (wide_int_to_tree (sizetype, op1)); | 8477 + wi::to_widest (gnu_size_op1)); |
8309 ops[0] = annotate_value (TREE_OPERAND (inner_op, 0)); | 8478 if (wi::zext (op1, TYPE_PRECISION (sizetype)) == 0) |
8479 return ops[0]; | |
8480 } | |
8481 ops[1] = annotate_value (wide_int_to_tree (sizetype, op1)); | |
8310 } | 8482 } |
8311 } | 8483 } |
8312 break; | 8484 break; |
8313 | 8485 |
8314 case BIT_AND_EXPR: | 8486 case BIT_AND_EXPR: |
8315 tcode = Bit_And_Expr; | 8487 tcode = Bit_And_Expr; |
8316 /* For negative values in sizetype, build NEGATE_EXPR of the opposite. | 8488 /* For negative values in sizetype, build NEGATE_EXPR of the opposite. |
8317 Such values appear in expressions with aligning patterns. Note that, | 8489 Such values can appear in expressions with aligning patterns. */ |
8318 since sizetype is unsigned, we have to jump through some hoops. */ | |
8319 if (TREE_CODE (TREE_OPERAND (gnu_size, 1)) == INTEGER_CST) | 8490 if (TREE_CODE (TREE_OPERAND (gnu_size, 1)) == INTEGER_CST) |
8320 { | 8491 { |
8321 tree op1 = TREE_OPERAND (gnu_size, 1); | 8492 wide_int wop1 = -wi::to_wide (TREE_OPERAND (gnu_size, 1)); |
8322 wide_int signed_op1 = wi::sext (wi::to_wide (op1), | 8493 tree op1 = wide_int_to_tree (sizetype, wop1); |
8323 TYPE_PRECISION (sizetype)); | 8494 ops[1] = annotate_value (build1 (NEGATE_EXPR, sizetype, op1)); |
8324 if (wi::neg_p (signed_op1)) | |
8325 { | |
8326 op1 = wide_int_to_tree (sizetype, wi::neg (signed_op1)); | |
8327 ops[1] = annotate_value (build1 (NEGATE_EXPR, sizetype, op1)); | |
8328 } | |
8329 } | 8495 } |
8330 break; | 8496 break; |
8331 | 8497 |
8332 case CALL_EXPR: | 8498 case CALL_EXPR: |
8333 /* In regular mode, inline back only if symbolic annotation is requested | 8499 /* In regular mode, inline back only if symbolic annotation is requested |
8334 in order to avoid memory explosion on big discriminated record types. | 8500 in order to avoid memory explosion on big discriminated record types. |
8335 But not in ASIS mode, as symbolic annotation is required for DDA. */ | 8501 But not in ASIS mode, as symbolic annotation is required for DDA. */ |
8336 if (List_Representation_Info == 3 || type_annotate_only) | 8502 if (List_Representation_Info >= 3 || type_annotate_only) |
8337 { | 8503 { |
8338 tree t = maybe_inline_call_in_expr (gnu_size); | 8504 tree t = maybe_inline_call_in_expr (gnu_size); |
8339 return t ? annotate_value (t) : No_Uint; | 8505 return t ? annotate_value (t) : No_Uint; |
8340 } | 8506 } |
8341 else | 8507 else |
8671 } | 8837 } |
8672 | 8838 |
8673 return gnu_list; | 8839 return gnu_list; |
8674 } | 8840 } |
8675 | 8841 |
8842 /* If SIZE has overflowed, return the maximum valid size, which is the upper | |
8843 bound of the signed sizetype in bits; otherwise return SIZE unmodified. */ | |
8844 | |
8845 static tree | |
8846 maybe_saturate_size (tree size) | |
8847 { | |
8848 if (TREE_CODE (size) == INTEGER_CST && TREE_OVERFLOW (size)) | |
8849 size = size_binop (MULT_EXPR, | |
8850 fold_convert (bitsizetype, TYPE_MAX_VALUE (ssizetype)), | |
8851 build_int_cst (bitsizetype, BITS_PER_UNIT)); | |
8852 return size; | |
8853 } | |
8854 | |
8676 /* UINT_SIZE is a Uint giving the specified size for an object of GNU_TYPE | 8855 /* UINT_SIZE is a Uint giving the specified size for an object of GNU_TYPE |
8677 corresponding to GNAT_OBJECT. If the size is valid, return an INTEGER_CST | 8856 corresponding to GNAT_OBJECT. If the size is valid, return an INTEGER_CST |
8678 corresponding to its value. Otherwise, return NULL_TREE. KIND is set to | 8857 corresponding to its value. Otherwise, return NULL_TREE. KIND is set to |
8679 VAR_DECL if we are specifying the size of an object, TYPE_DECL for the | 8858 VAR_DECL if we are specifying the size of an object, TYPE_DECL for the |
8680 size of a type, and FIELD_DECL for the size of a field. COMPONENT_P is | 8859 size of a type, and FIELD_DECL for the size of a field. COMPONENT_P is |
8681 true if we are being called to process the Component_Size of GNAT_OBJECT; | 8860 true if we are being called to process the Component_Size of GNAT_OBJECT; |
8682 this is used only for error messages. ZERO_OK is true if a size of zero | 8861 this is used only for error messages. ZERO_OK is true if a size of zero |
8683 is permitted; if ZERO_OK is false, it means that a size of zero should be | 8862 is permitted; if ZERO_OK is false, it means that a size of zero should be |
8684 treated as an unspecified size. */ | 8863 treated as an unspecified size. S1 and S2 are used for error messages. */ |
8685 | 8864 |
8686 static tree | 8865 static tree |
8687 validate_size (Uint uint_size, tree gnu_type, Entity_Id gnat_object, | 8866 validate_size (Uint uint_size, tree gnu_type, Entity_Id gnat_object, |
8688 enum tree_code kind, bool component_p, bool zero_ok) | 8867 enum tree_code kind, bool component_p, bool zero_ok, |
8868 const char *s1, const char *s2) | |
8689 { | 8869 { |
8690 Node_Id gnat_error_node; | 8870 Node_Id gnat_error_node; |
8691 tree type_size, size; | 8871 tree old_size, size; |
8692 | 8872 |
8693 /* Return 0 if no size was specified. */ | 8873 /* Return 0 if no size was specified. */ |
8694 if (uint_size == No_Uint) | 8874 if (uint_size == No_Uint) |
8695 return NULL_TREE; | 8875 return NULL_TREE; |
8696 | 8876 |
8703 || Ekind (gnat_object) == E_Discriminant) | 8883 || Ekind (gnat_object) == E_Discriminant) |
8704 && Present (Component_Clause (gnat_object))) | 8884 && Present (Component_Clause (gnat_object))) |
8705 gnat_error_node = Last_Bit (Component_Clause (gnat_object)); | 8885 gnat_error_node = Last_Bit (Component_Clause (gnat_object)); |
8706 else if (Present (Size_Clause (gnat_object))) | 8886 else if (Present (Size_Clause (gnat_object))) |
8707 gnat_error_node = Expression (Size_Clause (gnat_object)); | 8887 gnat_error_node = Expression (Size_Clause (gnat_object)); |
8888 else if (Has_Object_Size_Clause (gnat_object)) | |
8889 gnat_error_node = Expression (Object_Size_Clause (gnat_object)); | |
8708 else | 8890 else |
8709 gnat_error_node = gnat_object; | 8891 gnat_error_node = gnat_object; |
8710 | 8892 |
8711 /* Get the size as an INTEGER_CST. Issue an error if a size was specified | 8893 /* Get the size as an INTEGER_CST. Issue an error if a size was specified |
8712 but cannot be represented in bitsizetype. */ | 8894 but cannot be represented in bitsizetype. */ |
8729 /* The size of objects is always a multiple of a byte. */ | 8911 /* The size of objects is always a multiple of a byte. */ |
8730 if (kind == VAR_DECL | 8912 if (kind == VAR_DECL |
8731 && !integer_zerop (size_binop (TRUNC_MOD_EXPR, size, bitsize_unit_node))) | 8913 && !integer_zerop (size_binop (TRUNC_MOD_EXPR, size, bitsize_unit_node))) |
8732 { | 8914 { |
8733 if (component_p) | 8915 if (component_p) |
8734 post_error_ne ("component size for& is not a multiple of Storage_Unit", | 8916 post_error_ne ("component size for& must be multiple of Storage_Unit", |
8735 gnat_error_node, gnat_object); | 8917 gnat_error_node, gnat_object); |
8736 else | 8918 else |
8737 post_error_ne ("size for& is not a multiple of Storage_Unit", | 8919 post_error_ne ("size for& must be multiple of Storage_Unit", |
8738 gnat_error_node, gnat_object); | 8920 gnat_error_node, gnat_object); |
8739 return NULL_TREE; | 8921 return NULL_TREE; |
8740 } | 8922 } |
8741 | 8923 |
8742 /* If this is an integral type or a packed array type, the front-end has | 8924 /* If this is an integral type or a packed array type, the front-end has |
8751 template to the specified size. */ | 8933 template to the specified size. */ |
8752 if (TREE_CODE (gnu_type) == RECORD_TYPE | 8934 if (TREE_CODE (gnu_type) == RECORD_TYPE |
8753 && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) | 8935 && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) |
8754 size = size_binop (PLUS_EXPR, DECL_SIZE (TYPE_FIELDS (gnu_type)), size); | 8936 size = size_binop (PLUS_EXPR, DECL_SIZE (TYPE_FIELDS (gnu_type)), size); |
8755 | 8937 |
8756 if (kind == VAR_DECL | 8938 old_size = (kind == VAR_DECL ? TYPE_SIZE (gnu_type) : rm_size (gnu_type)); |
8757 /* If a type needs strict alignment, a component of this type in | 8939 |
8758 a packed record cannot be packed and thus uses the type size. */ | 8940 /* If the old size is self-referential, get the maximum size. */ |
8759 || (kind == TYPE_DECL && Strict_Alignment (gnat_object))) | 8941 if (CONTAINS_PLACEHOLDER_P (old_size)) |
8760 type_size = TYPE_SIZE (gnu_type); | 8942 old_size = max_size (old_size, true); |
8761 else | |
8762 type_size = rm_size (gnu_type); | |
8763 | |
8764 /* Modify the size of a discriminated type to be the maximum size. */ | |
8765 if (type_size && CONTAINS_PLACEHOLDER_P (type_size)) | |
8766 type_size = max_size (type_size, true); | |
8767 | 8943 |
8768 /* If this is an access type or a fat pointer, the minimum size is that given | 8944 /* If this is an access type or a fat pointer, the minimum size is that given |
8769 by the smallest integral mode that's valid for pointers. */ | 8945 by the smallest integral mode that's valid for pointers. */ |
8770 if (TREE_CODE (gnu_type) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (gnu_type)) | 8946 if (TREE_CODE (gnu_type) == POINTER_TYPE || TYPE_IS_FAT_POINTER_P (gnu_type)) |
8771 { | 8947 { |
8772 scalar_int_mode p_mode = NARROWEST_INT_MODE; | 8948 scalar_int_mode p_mode = NARROWEST_INT_MODE; |
8773 while (!targetm.valid_pointer_mode (p_mode)) | 8949 while (!targetm.valid_pointer_mode (p_mode)) |
8774 p_mode = GET_MODE_WIDER_MODE (p_mode).require (); | 8950 p_mode = GET_MODE_WIDER_MODE (p_mode).require (); |
8775 type_size = bitsize_int (GET_MODE_BITSIZE (p_mode)); | 8951 old_size = bitsize_int (GET_MODE_BITSIZE (p_mode)); |
8776 } | 8952 } |
8777 | 8953 |
8778 /* Issue an error either if the default size of the object isn't a constant | 8954 /* Issue an error either if the default size of the object isn't a constant |
8779 or if the new size is smaller than it. */ | 8955 or if the new size is smaller than it. */ |
8780 if (TREE_CODE (type_size) != INTEGER_CST | 8956 if (TREE_CODE (old_size) != INTEGER_CST |
8781 || TREE_OVERFLOW (type_size) | 8957 || TREE_OVERFLOW (old_size) |
8782 || tree_int_cst_lt (size, type_size)) | 8958 || tree_int_cst_lt (size, old_size)) |
8783 { | 8959 { |
8784 if (component_p) | 8960 char buf[128]; |
8785 post_error_ne_tree | 8961 const char *s; |
8786 ("component size for& too small{, minimum allowed is ^}", | 8962 |
8787 gnat_error_node, gnat_object, type_size); | 8963 if (kind == FIELD_DECL) |
8964 { | |
8965 snprintf (buf, sizeof (buf), s1, s2); | |
8966 s = buf; | |
8967 } | |
8968 else if (component_p) | |
8969 s = "component size for& too small{, minimum allowed is ^}"; | |
8788 else | 8970 else |
8789 post_error_ne_tree | 8971 s = "size for& too small{, minimum allowed is ^}"; |
8790 ("size for& too small{, minimum allowed is ^}", | 8972 post_error_ne_tree (s, gnat_error_node, gnat_object, old_size); |
8791 gnat_error_node, gnat_object, type_size); | 8973 |
8792 return NULL_TREE; | 8974 return NULL_TREE; |
8793 } | 8975 } |
8794 | 8976 |
8795 return size; | 8977 return size; |
8796 } | 8978 } |
8804 Node_Id gnat_attr_node; | 8986 Node_Id gnat_attr_node; |
8805 tree old_size, size; | 8987 tree old_size, size; |
8806 | 8988 |
8807 /* Do nothing if no size was specified. */ | 8989 /* Do nothing if no size was specified. */ |
8808 if (uint_size == No_Uint) | 8990 if (uint_size == No_Uint) |
8809 return; | |
8810 | |
8811 /* Ignore a negative size since that corresponds to our back-annotation. */ | |
8812 if (UI_Lt (uint_size, Uint_0)) | |
8813 return; | 8991 return; |
8814 | 8992 |
8815 /* Only issue an error if a Value_Size clause was explicitly given. | 8993 /* Only issue an error if a Value_Size clause was explicitly given. |
8816 Otherwise, we'd be duplicating an error on the Size clause. */ | 8994 Otherwise, we'd be duplicating an error on the Size clause. */ |
8817 gnat_attr_node | 8995 gnat_attr_node |
9146 | 9324 |
9147 /* If we've exhausted both lists simultaneously, we're done. */ | 9325 /* If we've exhausted both lists simultaneously, we're done. */ |
9148 if (!ada_type && !btin_type) | 9326 if (!ada_type && !btin_type) |
9149 break; | 9327 break; |
9150 | 9328 |
9151 /* If one list is shorter than the other, they fail to match. */ | 9329 /* If the internal builtin uses a variable list, accept anything. */ |
9152 if (!ada_type || !btin_type) | 9330 if (!btin_type) |
9153 return false; | 9331 break; |
9154 | 9332 |
9155 /* If we're done with the Ada args and not with the internal builtin | 9333 /* If we're done with the Ada args and not with the internal builtin |
9156 args, or the other way around, complain. */ | 9334 args, or the other way around, complain. */ |
9157 if (ada_type == void_type_node | 9335 if (ada_type == void_type_node |
9158 && btin_type != void_type_node) | 9336 && btin_type != void_type_node) |
9658 { | 9836 { |
9659 gnu_size = DECL_SIZE (gnu_old_field); | 9837 gnu_size = DECL_SIZE (gnu_old_field); |
9660 if (RECORD_OR_UNION_TYPE_P (gnu_field_type) | 9838 if (RECORD_OR_UNION_TYPE_P (gnu_field_type) |
9661 && !TYPE_FAT_POINTER_P (gnu_field_type) | 9839 && !TYPE_FAT_POINTER_P (gnu_field_type) |
9662 && tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type))) | 9840 && tree_fits_uhwi_p (TYPE_SIZE (gnu_field_type))) |
9663 gnu_field_type = make_packable_type (gnu_field_type, true); | 9841 gnu_field_type = make_packable_type (gnu_field_type, true, 0); |
9664 } | 9842 } |
9665 | 9843 |
9666 else | 9844 else |
9667 gnu_size = TYPE_SIZE (gnu_field_type); | 9845 gnu_size = TYPE_SIZE (gnu_field_type); |
9668 | 9846 |
10013 { | 10191 { |
10014 /* For integral types, we store the RM size explicitly. */ | 10192 /* For integral types, we store the RM size explicitly. */ |
10015 if (INTEGRAL_TYPE_P (gnu_type) && TYPE_RM_SIZE (gnu_type)) | 10193 if (INTEGRAL_TYPE_P (gnu_type) && TYPE_RM_SIZE (gnu_type)) |
10016 return TYPE_RM_SIZE (gnu_type); | 10194 return TYPE_RM_SIZE (gnu_type); |
10017 | 10195 |
10018 /* Return the RM size of the actual data plus the size of the template. */ | 10196 /* If the type contains a template, return the padded size of the template |
10197 plus the RM size of the actual data. */ | |
10019 if (TREE_CODE (gnu_type) == RECORD_TYPE | 10198 if (TREE_CODE (gnu_type) == RECORD_TYPE |
10020 && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) | 10199 && TYPE_CONTAINS_TEMPLATE_P (gnu_type)) |
10021 return | 10200 return |
10022 size_binop (PLUS_EXPR, | 10201 size_binop (PLUS_EXPR, |
10023 rm_size (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type)))), | 10202 bit_position (DECL_CHAIN (TYPE_FIELDS (gnu_type))), |
10024 DECL_SIZE (TYPE_FIELDS (gnu_type))); | 10203 rm_size (TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_type))))); |
10025 | 10204 |
10026 /* For record or union types, we store the size explicitly. */ | 10205 /* For record or union types, we store the size explicitly. */ |
10027 if (RECORD_OR_UNION_TYPE_P (gnu_type) | 10206 if (RECORD_OR_UNION_TYPE_P (gnu_type) |
10028 && !TYPE_FAT_POINTER_P (gnu_type) | 10207 && !TYPE_FAT_POINTER_P (gnu_type) |
10029 && TYPE_ADA_SIZE (gnu_type)) | 10208 && TYPE_ADA_SIZE (gnu_type)) |
10094 strcat (new_name, "___"); | 10273 strcat (new_name, "___"); |
10095 strcat (new_name, suffix); | 10274 strcat (new_name, suffix); |
10096 return get_identifier_with_length (new_name, len); | 10275 return get_identifier_with_length (new_name, len); |
10097 } | 10276 } |
10098 | 10277 |
10099 /* Initialize data structures of the decl.c module. */ | 10278 /* Initialize the data structures of the decl.c module. */ |
10100 | 10279 |
10101 void | 10280 void |
10102 init_gnat_decl (void) | 10281 init_gnat_decl (void) |
10103 { | 10282 { |
10104 /* Initialize the cache of annotated values. */ | 10283 /* Initialize the cache of annotated values. */ |
10106 | 10285 |
10107 /* Initialize the association of dummy types with subprograms. */ | 10286 /* Initialize the association of dummy types with subprograms. */ |
10108 dummy_to_subprog_map = hash_table<dummy_type_hasher>::create_ggc (512); | 10287 dummy_to_subprog_map = hash_table<dummy_type_hasher>::create_ggc (512); |
10109 } | 10288 } |
10110 | 10289 |
10111 /* Destroy data structures of the decl.c module. */ | 10290 /* Destroy the data structures of the decl.c module. */ |
10112 | 10291 |
10113 void | 10292 void |
10114 destroy_gnat_decl (void) | 10293 destroy_gnat_decl (void) |
10115 { | 10294 { |
10116 /* Destroy the cache of annotated values. */ | 10295 /* Destroy the cache of annotated values. */ |