aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/decl.cc
AgeCommit message (Collapse)AuthorFilesLines
2024-01-22Update copyright years.Marc Poulhiès1-1/+1
2024-01-09ada: Fix bogus Constraint_Error on allocator for access to array of access typeEric Botcazou1-3/+3
This occurs because the access element type is not its own TYPE_CANONICAL, which creates a discrepancy between the aliasing support code, which deals with types directly, and the middle-end which looks at TYPE_CANONICAL only. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Use the TYPE_CANONICAL of types when it comes to aliasing. * gcc-interface/utils.cc (relate_alias_sets): Likewise.
2024-01-09ada: Preliminary cleanup in aliasing support codeEric Botcazou1-14/+13
This declares an explicit temporary for the fields of the fat pointer type in gnat_to_gnu_entity and removes the GNU_ prefix of the parameters of the relate_alias_sets routine for the sake of brevity. No functional changes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Use a separate FLD local variable to hold the first field of the fat pointer type being built. * gcc-interface/gigi.h (relate_alias_sets): Remove GNU_ prefix on the first two parameters. * gcc-interface/utils.cc (relate_alias_sets): Likewise and adjust.
2024-01-09ada: Add __atomic_store_n binding to System.Atomic_PrimitivesEric Botcazou1-2/+22
This is modeled on the existing binding for __atomic_load_n. gcc/ada/ * libgnat/s-atopri.ads (Atomic_Store): New generic procedure. (Atomic_Store_8): New instantiated procedure. (Atomic_Store_16): Likewise. (Atomic_Store_32): Likewise. (Atomic_Store_64): Likewise. * libgnat/s-atopri__32.ads (Atomic_Store): New generic procedure. (Atomic_Store_8): New instantiated procedure. (Atomic_Store_16): Likewise. (Atomic_Store_32): Likewise. * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Implement the support for __atomic_store_n and __sync_bool_compare_and_swap_n. * gcc-interface/gigi.h (list_second): New inline function.
2023-12-19ada: Rename Is_Constr_Subt_For_UN_Aliased flagEric Botcazou1-24/+20
The flag is set on the constructed subtype of an object with unconstrained nominal subtype that is aliased and is used by the code generator to adjust the layout of the object. But it is actually only used for array subtypes, where it determines whether the object is allocated with its bounds, and this usage could be extended to other cases than the original case. gcc/ada/ * einfo.ads (Is_Constr_Subt_For_UN_Aliased): Rename into... (Is_Constr_Array_Subt_With_Bounds): ...this. * exp_ch3.adb (Expand_N_Object_Declaration): Adjust to above renaming and remove now redundant test. * sem_ch3.adb (Analyze_Object_Declaration): Likewise, but set Is_Constr_Array_Subt_With_Bounds only on arrays. * gen_il-fields.ads (Opt_Field_Enum): Apply same renaming. * gen_il-gen-gen_entities.adb (Entity_Kind): Likewise. * gen_il-internals.adb (Image): Remove specific processing for Is_Constr_Subt_For_UN_Aliased. * treepr.adb (Image): Likewise. * gcc-interface/decl.cc (gnat_to_gnu_entity): Adjust to renaming and remove now redundant tests. * gcc-interface/trans.cc (Identifier_to_gnu): Likewise. (Call_to_gnu): Likewise.
2023-11-28ada: Fix wrong size value output with -gnatR -gnatcEric Botcazou1-0/+1
This happens when a parameter is involved in the computation. gcc/ada/ * gcc-interface/decl.cc (annotate_value): Apply the same processing for parameters as for variables.
2023-11-21ada: Fix issue with indefinite vector of overaligned unconstrained arrayEric Botcazou1-0/+12
The problem is that the aligning machinery is not consistently triggered, depending on whether a constrained view or the nominal unconstrained view of the element type is used to perform the allocations and deallocations. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Subtype>: Put the alignment directly on the type in the constrained case too. * gcc-interface/utils.cc (maybe_pad_type): For an array type, take the alignment of the element type as the original alignment.
2023-11-16Fix internal error on function returning dynamically-sized typeEric Botcazou1-0/+6
This is a tree sharing issue for the internal return type synthesized for a function returning a dynamically-sized type and taking an Out or In/Out parameter passed by copy. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Also create a TYPE_DECL for the return type built for the CI/CO mechanism. gcc/testsuite/ * gnat.dg/varsize4.ads, gnat.dg/varsize4.adb: New test. * gnat.dg/varsize4_pkg.ads: New helper.
2023-11-07ada: Fix debug info for aliased packed array with unconstrained nominal subtypeEric Botcazou1-0/+12
The front-end now rewrites it as a renaming when it is initialized with a function call and the same processing must be applied in the renaming case as in the regular case for this kind of special objects. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Apply the specific rewriting done for an aliased object with an unconstrained array nominal subtype in the renaming case too.
2023-10-10ada: Fix internal error on too large representation clause for small componentEric Botcazou1-1/+13
This is a small bug present on strict-alignment platforms for questionable representation clauses. gcc/ada/ * gcc-interface/decl.cc (inline_status_for_subprog): Minor tweak. (gnat_to_gnu_field): Try harder to get a packable form of the type for a bitfield.
2023-09-19ada: Refine upper array bound for bit packed arrayMarc Poulhiès1-0/+22
When using bit-packed arrays, the compiler creates new array subtypes of 1-bit component indexed by integers. The existing routine checks the index subtype to find the min/max values. Bit-packed arrays being indexed by integers, the routines gives up as returning the maximum possible integer carries no useful information. This change adds a simple max_value routine that can evaluate very simple expressions by substituting variables by their min/max value. Bit-packed array subtypes are currently declared as: subtype bp_array is packed_bytes1 (0 .. integer((1 * Var + 7) / 8 - 1)); The simple max_value evaluator handles the bare minimum for this expression pattern. gcc/ada/ChangeLog: * gcc-interface/utils.cc (max_value): New. * gcc-interface/gigi.h (max_value): New. * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Subtype>: When computing gnu_min/gnu_max, try to use max_value if there is an initial expression.
2023-09-05ada: Fix DWARF for certain arraysTom Tromey1-1/+7
An array whose index type is a nonstandard enum will be marked as "packed", but should not emit DW_AT_bit_stride unless it is also bit-packed. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity): Set bit-packed for constrained and unconstrained array types. * gcc-interface/misc.cc (gnat_get_array_descr_info): Examine BIT_PACKED_ARRAY_TYPE_P.
2023-07-18ada: Use new typedefs in gcc-interfaceTom Tromey1-1/+4
This changes gcc-interface to use the typedefs that were recently introduced in gnat. This is another step toward switching the code generator to emit enums rather than preprocessor defines. In a couple of spots, a 'default' case is also added. These avoid warnings from -Wswitch when the typedefs are changed to be enums. gcc/ada/ * gcc-interface/decl.cc (check_ok_for_atomic_type): Use Pragma_Id. * gcc-interface/trans.cc (lvalue_required_p, Pragma_to_gnu): Use Pragma_Id. (get_type_length, Attribute_to_gnu, get_atomic_access): Use Attribute_Id.
2023-06-29A couple of va_gc_atomic tweaksRichard Sandiford1-11/+0
The only current user of va_gc_atomic is Ada's: vec<Entity_Id, va_gc_atomic> It uses the generic gt_pch_nx routines (with gt_pch_nx being the “note pointers” hooks), such as: template<typename T, typename A> void gt_pch_nx (vec<T, A, vl_embed> *v) { extern void gt_pch_nx (T &); for (unsigned i = 0; i < v->length (); i++) gt_pch_nx ((*v)[i]); } It then defines gt_pch_nx routines for Entity_Id &. The problem is that if we wanted to take the same approach for an array of unsigned ints, we'd need to define: inline void gt_pch_nx (unsigned int &) { } which would then be ambiguous with: inline void gt_pch_nx (unsigned int) { } The point of va_gc_atomic is that the elements don't need to be GCed, and so we have: template<typename T> void gt_ggc_mx (vec<T, va_gc_atomic, vl_embed> *v ATTRIBUTE_UNUSED) { /* Nothing to do. Vectors of atomic types wrt GC do not need to be traversed. */ } I think it's therefore reasonable to assume that no pointers will need to be processed for PCH either. The patch also relaxes the array_slice constructor for vec<T, va_gc> * so that it handles all embedded vectors. gcc/ * vec.h (gt_pch_nx): Add overloads for va_gc_atomic. (array_slice): Relax va_gc constructor to handle all vectors with a vl_embed layout. gcc/ada/ * gcc-interface/decl.cc (gt_pch_nx): Remove overloads for Entity_Id.
2023-06-20ada: Minor tweaksEric Botcazou1-8/+6
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Pass the NULL_TREE explicitly and test imported_p in lieu of Is_Imported. <E_Function>: Remove public_flag local variable and make extern_flag local variable a constant.
2023-06-15ada: Fix wrong finalization for double subtype of bounded vectorEric Botcazou1-4/+10
The special handling of temporaries created for return values and subject to a renaming needs to be restricted to the top level, where it is needed to prevent dangling references to the frame of the elaboration routine from being created, because, at a lower level, the front-end may create implicit renamings of objects as these temporaries, so a copy is not allowed. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Restrict the special handling of temporaries created for return values and subject to a renaming to the top level.
2023-05-30ada: Fix bogus Storage_Error on dynamic array with static zero lengthEric Botcazou1-4/+21
This works around the limitations present for the support of arrays in the middle-end by clearing the TREE_OVERFLOW flag for arrays with zero length. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Use a local variable for the GNAT index type. <E_Array_Subtype>: Likewise. Call Is_Null_Range on the bounds and force the zero on TYPE_SIZE and TYPE_SIZE_UNIT if it returns true.
2023-05-30ada: Minor generic tweaks left and and rightEric Botcazou1-1/+1
No functional changes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Replace integer_zero_node with null_pointer_node for pointer types. * gcc-interface/trans.cc (gnat_gimplify_expr) <NULL_EXPR>: Likewise. * gcc-interface/utils.cc (maybe_pad_type): Do not attempt to make a packable type from a fat pointer type. * gcc-interface/utils2.cc (build_atomic_load): Use a local variable. (build_atomic_store): Likewise.
2023-05-30ada: Make use of Cannot_Be_Superflat flag on N_Range nodesEric Botcazou1-0/+4
gcc/ada/ * gcc-interface/decl.cc (range_cannot_be_superflat): Return true immediately if Cannot_Be_Superflat is set. * gcc-interface/misc.cc (gnat_post_options): Do not override the -Wstringop-overflow setting.
2023-05-18ada: use _P() defines from tree.hBernhard Reutner-Fischer1-9/+8
gcc/ada/ChangeLog: * gcc-interface/decl.cc (gnat_to_gnu_entity): Use _P defines from tree.h. (constructor_address_p): Ditto. (elaborate_expression_1): Ditto. * gcc-interface/trans.cc (Identifier_to_gnu): Ditto. (is_nrv_p): Ditto. (Subprogram_Body_to_gnu): Ditto. (gnat_to_gnu): Ditto. (gnat_to_gnu_external): Ditto. (add_decl_expr): Ditto. (gnat_gimplify_expr): Ditto. * gcc-interface/utils.cc (create_var_decl): Ditto. * gcc-interface/utils2.cc (get_base_type): Ditto. (build_binary_op): Ditto. (build_unary_op): Ditto. (gnat_protect_expr): Ditto. (gnat_invariant_expr): Ditto.
2023-04-15Fix fallout of previous change on x86/LinuxEric Botcazou1-6/+16
gcc/ada/ PR bootstrap/109510 * gcc-interface/decl.cc (gnat_to_gnu_entity) <types>: Do not reset align to zero in any case. Set TYPE_USER_ALIGN on the type only if it is an aggregate type, or else a type whose default alignment is specifically capped on selected platforms.
2023-04-14Fix build failure of Ada runtime for Aarch64 targetsEric Botcazou1-2/+6
The Aarch64 back-end now asserts that the main variant of scalar types has TYPE_USER_ALIGN cleared, and that's not the case for scalar types declared with a confirming alignment clause in Ada. gcc/ada/ PR bootstrap/109510 * gcc-interface/decl.cc (gnat_to_gnu_entity) <types>: Reset align to zero if its value is equal to TYPE_ALIGN and the type is scalar. Set TYPE_USER_ALIGN on the type only if align is positive.
2023-01-16ada: Update copyright years.Marc Poulhiès1-1/+1
gcc/ada/ * gcc-interface/Make-lang.in: Update copyright years. * gcc-interface/Makefile.in: Likewise. * gcc-interface/ada-builtin-types.def: Likewise. * gcc-interface/ada-builtins.def: Likewise. * gcc-interface/ada-tree.def: Likewise. * gcc-interface/ada-tree.h: Likewise. * gcc-interface/ada.h: Likewise. * gcc-interface/config-lang.in: Likewise. * gcc-interface/cuintp.cc: Likewise. * gcc-interface/decl.cc: Likewise. * gcc-interface/gadaint.h: Likewise. * gcc-interface/gigi.h: Likewise. * gcc-interface/lang-specs.h: Likewise. * gcc-interface/lang.opt: Likewise. * gcc-interface/misc.cc: Likewise. * gcc-interface/system.ads: Likewise. * gcc-interface/targtyps.cc: Likewise. * gcc-interface/trans.cc: Likewise. * gcc-interface/utils.cc: Likewise. * gcc-interface/utils2.cc: Likewise.
2022-11-21ada: Adjust recent change for returns involving function callsEric Botcazou1-11/+0
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Constant>: Revert latest change. * gcc-interface/trans.cc (gnat_to_gnu) <N_Object_Declaration>: Tweak latest change.
2022-11-08ada: Move warnings switches -- initial workBob Duff1-1/+1
This patch prepares to move warning switches from Opt into Warnsw. gcc/ada/ * warnsw.ads, warnsw.adb, fe.h, err_vars.ads, errout.ads: Move Warning_Doc_Switch from Err_Vars to Warnsw. Access Warn_On_Questionable_Layout on the C side via a function rather than a variable, because we plan to turn the variables into renamings, and you can't Export renamings. * erroutc.adb, switch-c.adb, errout.adb: Likewise. * gcc-interface/decl.cc: Use Get_Warn_On_Questionable_Layout instead of Warn_On_Questionable_Layout. * gcc-interface/Makefile.in (GNATMAKE_OBJS): Add warnsw.o, because it is indirectly imported via Errout. * gcc-interface/Make-lang.in (GNATBIND_OBJS): Likewise and remove restrict.o (not needed).
2022-10-06ada: Implementation of support for storage models in gigiEric Botcazou1-1/+5
It is based on a new LOAD_EXPR node in GENERIC that is later turned into a bona-fide temporary during gimplification. gcc/ada/ * gcc-interface/ada-tree.def (LOAD_EXPR): New expression code. * gcc-interface/gigi.h (build_storage_model_load): Declare. (build_storage_model_store): Likewise. (instantiate_load_in_expr): Likewise. (INSTANTIATE_LOAD_IN_EXPR): New macro. (instantiate_load_in_array_ref): Declare. * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Record_Type>: Set a fake discriminant number on the fields of the template type. (gnat_to_gnu_field): Use integer for DECL_DISCRIMINANT_NUMBER. * gcc-interface/misc.cc (gnat_init_ts): Mark LOAD_EXPR as typed. * gcc-interface/trans.cc (fold_constant_decl_in_expr) <ARRAY_REF>: Also preserve the 4th operand. (Attribute_to_gnu): Deal with LOAD_EXPR of unconstrained array type. <Attr_Size>: Call INSTANTIATE_LOAD_IN_EXPR for a storage model. <Attr_Length>: Likewise. <Attr_Bit_Position>: Likewise. (get_storage_model): New function. (get_storage_model_access): Likewise. (storage_model_access_required_p): Likewise. (Call_to_gnu): Add GNAT_STORAGE_MODEL parameter and deal with it. Also deal with actual parameters that have a storage model. (gnat_to_gnu) <N_Object_Declaratio>: Adjust call to Call_to_gnu. <N_Explicit_Dereference>: Deal with a storage model access. <N_Indexed_Component>: Likewise. <N_Slice>: Likewise. <N_Selected_Component>: Likewise. <N_Assignment_Statement>: Adjust call to Call_to_gnu. Deal with a storage model access either on the LHS, on the RHS or on both. <N_Function_Cal>: Adjust call to Call_to_gnu. <N_Free_Statement>: Deal with a pool that is a storage model. Replace test for UNCONSTRAINED_ARRAY_REF with test on the type. (gnat_gimplify_expr) <CALL_EXPR>: Tidy up. <LOAD_EXPR>: New case. <UNCONSTRAINED_ARRAY_REF>: Move down. * gcc-interface/utils.cc (maybe_unconstrained_array): Deal with a LOAD_EXPR by recursing on its first operand. * gcc-interface/utils2.cc (build_allocator): Deal with a pool that is a storage model. (build_storage_model_copy): New function. (build_storage_model_load): Likewise. (build_storage_model_store): Likewise. (instantiate_load_in_expr): Likewise. (instantiate_load_in_array_ref): Likewise. (gnat_rewrite_reference) <ARRAY_REF>: Also preserve the 4th operand. (get_inner_constant_reference) <ARRAY_REF>: Remove useless test. (gnat_invariant_expr) <ARRAY_REF>: Rewrite test.
2022-09-12[Ada] Fix immediate assertion failure with -gnatd.1Eric Botcazou1-1/+5
The switch enables the front-end unnesting pass. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity): Relax assertion when front-end unnesting is enabled.
2022-09-06[Ada] Mark artificial formal parameters in the debug infoEric Botcazou1-0/+1
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_param): Set DECL_ARTIFICIAL.
2022-07-13[Ada] Revert recent change in debug info for vector array typesEric Botcazou1-8/+0
It lost too much useful information. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity): Do not set the debug type for vector types.
2022-07-13[Ada] Undo questionable renaming in earlier changeEric Botcazou1-2/+2
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Access_Subtype>: Undo questionable renaming.
2022-07-13[Ada] Also deal with private actual types in latest changeEric Botcazou1-0/+13
gcc/ada/ * gcc-interface/decl.cc (Gigi_Cloned_Subtype): Handle private case.
2022-07-13[Ada] Use actual types instead of formal types consistently in debug infoEric Botcazou1-27/+93
This makes sure that the objects present in instantiations always have the actual type instead of a local variant of the formal type in the debugging information generated by the compiler (this was already the case when the actual type is a record, a protected or a task type). gcc/ada/ * gcc-interface/decl.cc (Gigi_Cloned_Subtype): New function. (gnat_to_gnu_entity) <E_Signed_Integer_Subtype>: Call it to get the cloned subtype, if any. <E_Floating_Point_Subtype>: Likewise. <E_Array_Subtype>: Likewise. <E_Record_Subtype>: Likewise. <E_Access_Subtype>: Likewise. Deal with all cloned subtypes on the main path.
2022-07-13[Ada] Generate debug info entry for user-defined access subtypeEric Botcazou1-7/+6
This is consistent with the other kinds of subtypes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Access_Subtype>: Do not reuse the TYPE_DECL of the base type.
2022-07-13[Ada] Fix wrong access check with access-to-unconstrained-arrayEric Botcazou1-8/+13
The current implementation may create dangling references from a superset of the alias set of the dummy pointer-to-array type when it exists. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Array_Type>: Save and restore the alias set of the dummy pointer-to-array type.
2022-07-06[Ada] Improve code generated for aggregates of VFA typeEric Botcazou1-1/+19
This avoids using a full access for constants internally generated from assignments of aggregates with a Volatile_Full_Access type. gcc/ada/ * gcc-interface/gigi.h (simple_constant_p): Declare. * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Strip the qualifiers from the type of a simple constant. (simple_constant_p): New predicate. * gcc-interface/trans.cc (node_is_atomic): Return true for objects with atomic type except for simple constants. (node_is_volatile_full_access): Return false for simple constants with VFA type.
2022-07-06[Ada] Fix crash on aliased renaming of unconstrained arrayEric Botcazou1-5/+7
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Create a local constant holding the underlying GNAT type of the object. Do not fiddle with the object size for an unconstrained array.
2022-07-06[Ada] Small tweak to gnat_to_gnu_subprog_typeEric Botcazou1-3/+3
No functional changes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Constify a local variable and move a couple of others around.
2022-06-02[Ada] Fix record layout warnings not being taggedGhjuvan Lacambre1-8/+8
This allows tools ingesting GNAT's output to properly classify these messages. gcc/ada/ * gcc-interface/decl.cc (warn_on_field_placement): Add insertion character '.q' to warning string.
2022-06-02[Ada] Couple of small preparatory adjustmentsEric Botcazou1-2/+4
No functional changes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity): Do not check the scope of anonymous access Itypes. * gcc-interface/trans.cc (Identifier_to_gnu): Do not translate the return type of a subprogram here.
2022-06-02[Ada] Get rid of secondary stack for most calls returning tagged typesEric Botcazou1-36/+7
This eliminates the use of the secondary stack to return specific tagged types from functions in calls that are not dispatching on result, which comprises returning controlled types, by introducing thunks whose only purpose is to move the result from the primary to the secondary stack for primitive functions that are controlling on result, and referencing them in the dispatch table in lieu of the primitive functions. The implementation reuses the existing machinery of interface thunks and thus creates another kind of thunks, secondary stack thunks, which only perform a call to the primitive function and return the result. gcc/ada/ * einfo.ads (Has_Controlling_Result): Document new usage. (Is_Thunk): Document secondary stack thunks. (Returns_By_Ref): Adjust. * exp_ch6.adb (Caller_Known_Size): Return true for tagged types. (Expand_N_Extended_Return_Statement): Do not call Set_By_Ref. (Expand_Simple_Function_Return): For a BIP return with an Alloc_Form parameter, mark the node as returning on the secondary stack. Replace call to Is_Limited_Interface with Is_Limited_View. Deal wit secondary stack thunks. Do not call Set_By_Ref. Optimize the case of a call to a function whose type also needs finalization. (Needs_BIP_Task_Actuals): Replace Thunk_Entity with Thunk_Target. (Needs_BIP_Finalization_Master): Cosmetic fixes. (Needs_BIP_Alloc_Form): Check No_Secondary_Stack restriction and return true for tagged types. * exp_ch7.adb (Transient Scope Management): Update description. * exp_disp.adb (Expand_Dispatching_Call): Always set Returns_By_Ref on designated type if the call is dispatching on result. Tidy up. (Expand_Interface_Thunk): Change type of Thunk_Code from Node_Id to List_Id. Change type of local variables from Node_Id to Entity_Id. Propagate Aliased_Present flag to create the formals and explicitly set Has_Controlling_Result to False. Build a secondary stack thunk if necessary in the function case. (Expand_Secondary_Stack_Thunk): New function. (Make_Secondary_DT): Build secondary stack thunks if necessary. (Make_DT): Likewise. (Register_Predefined_Primitive): Likewise. (Register_Primitive): Likewise. * exp_util.ads (Is_Secondary_Stack_Thunk): Declare. (Thunk_Target): Likewise. * exp_util.adb (Is_Secondary_Stack_Thunk): New function. (Thunk_Target): Likewise. * fe.h (Is_Secondary_Stack_Thunk): Declare. (Thunk_Target): Likewise. * gen_il-fields.ads (Opt_Field_Enum): Remove By_Ref. * gen_il-gen-gen_nodes.adb (N_Simple_Return_Statement): Likewise. (N_Extended_Return_Statement): Likewise. * sem_ch6.adb (Analyze_Subprogram_Specification): Skip check for abstract return type in the thunk case. (Create_Extra_Formals): Replace Thunk_Entity with Thunk_Target. * sem_disp.adb (Check_Controlling_Formals): Skip in the thunk case. * sem_util.adb: Add use and with clauses for Exp_Ch6. (Compute_Returns_By_Ref): Do not process procedures and only set the flag for direct return by reference. (Needs_Secondary_Stack): Do not return true for specific tagged types and adjust comments accordingly. * sinfo.ads (By_Ref): Delete. (N_Simple_Return_Statement): Remove By_Ref. (N_Extended_Return_Statement): Likewise. * gcc-interface/ada-tree.h (TYPE_RETURN_UNCONSTRAINED_P): Delete. * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Do not use it. Return by direct reference if the return type needs the secondary stack as well as for secondary stack thunks. * gcc-interface/gigi.h (fntype_same_flags_p): Remove parameter. * gcc-interface/misc.cc (gnat_type_hash_eq): Adjust to above change. * gcc-interface/trans.cc (finalize_nrv): Replace test on TYPE_RETURN_UNCONSTRAINED_P with TYPE_RETURN_BY_DIRECT_REF_P. (Subprogram_Body_to_gnu): Do not call maybe_make_gnu_thunk for secondary stack thunks. (Call_to_gnu): Do not test TYPE_RETURN_UNCONSTRAINED_P. (gnat_to_gnu) <N_Simple_Return_Statement>: In the return by direct reference case, test for the presence of Storage_Pool on the node to build an allocator. (maybe_make_gnu_thunk): Deal with Thunk_Entity and Thunk_Target. * gcc-interface/utils.cc (fntype_same_flags_p): Remove parameter.
2022-06-01[Ada] Rename Returns_On_Secondary_Stack into Needs_Secondary_StackEric Botcazou1-1/+1
The Returns_On_Secondary_Stack predicate is a misnomer because it must be invoked on a type and types do not return; as a matter of fact, the other Returns_XXX predicates apply to functions. gcc/ada/ * exp_ch6.adb (Caller_Known_Size): Invoke Needs_Secondary_Stack in lieu of Returns_On_Secondary_Stack. (Expand_Call_Helper): Likewise. (Expand_Simple_Function_Return): Likewise. (Needs_BIP_Alloc_Form): Likewise. * exp_ch7.adb (Wrap_Transient_Declaration): Likewise. * sem_res.adb (Resolve_Call): Likewise. (Resolve_Entry_Call): Likewise. * sem_util.ads (Returns_On_Secondary_Stack): Rename into... (Needs_Secondary_Stack): ...this. * sem_util.adb (Returns_On_Secondary_Stack): Rename into... (Needs_Secondary_Stack): ...this. * fe.h (Returns_On_Secondary_Stack): Delete. (Needs_Secondary_Stack): New function. * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Replace call to Returns_On_Secondary_Stack with Needs_Secondary_Stack.
2022-05-19[Ada] Avoid copy operation for returns involving function callsEric Botcazou1-0/+11
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Constant>: Deal with a constant related to a return in a function specially. * gcc-interface/trans.cc (Call_to_gnu): Use return slot optimization if the target is a return object. (gnat_to_gnu) <N_Object_Declaration>: Deal with a constant related to a return in a function specially.
2022-05-19[Ada] Add support for "simd" function attributeEric Botcazou1-1/+4
gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Function>: Also call process_attributes for built-in functions. (prepend_one_attribute_pragma): Deal with "simd" attribute. * gcc-interface/utils.cc (handle_simd_attribute): New function. (gnat_internal_attribute_table): Add entry for "simd" attribute.
2022-05-19[Ada] Fix internal error on unchecked union with component clauses (2)Eric Botcazou1-6/+23
The issue arises when the unchecked union contains both a fixed part and a variant part, and is subject to a full representation clause covering all the components in all the variants, when the component clauses do not align the variant boundaries with byte boundaries consistently. gcc/ada/ * gcc-interface/decl.cc (components_to_record): Use NULL recursively as P_GNU_REP_LIST for the innermost variant level in the unchecked union case with a fixed part.
2022-05-19[Ada] Fix internal error on semi-circular record typesEric Botcazou1-8/+11
The front-end properly computes a linear elaboration order for them, but there was a loophole in the handling of the delayed case. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Access_Subtype>: And skip the elaboration of the designated subtype when that of its base type has been delayed.
2022-05-19[Ada] Fix for internal error on semi-circular record aggregateEric Botcazou1-2/+12
This creates a couple of record subtypes pointing to each other through access subtypes, and we break the circularity at the latter subtypes. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Record_Subtype>: If it is a special subtype designated by an access subtype, then defer the completion of incomplete types.
2022-05-19[Ada] Get rid of secondary stack for controlled componentsEric Botcazou1-4/+2
This eliminates the use of the secondary stack to return composite types with controlled components from functions, by exposing the return slot of these functions through the support interface of memory pools, much like for the secondary stack itself. This is piggybacked on the support of a specific intrinsic function by the code generator, and can be disabled if this support is not available, as well with the -gnatd_r debug switch. The change also streamlines a bit the implementation by consistently using the Needs_Finalization predicate, or its derivatives, in various places. gcc/ada/ * Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add s-retsta. * debug.adb (d_r): Document usage. * exp_ch4.adb (Expand_N_Allocato): Deal with the return stack pool. * exp_ch6.adb (Expand_Simple_Function_Return): Replace calls to Requires_Transient_Scope with Returns_On_Secondary_Stack. Deal with types that need finalization returned on the primary stack, use CW_Or_Needs_Finalization for those returned on the secondary. * exp_util.adb (Build_Allocate_Deallocate_Proc): Return early for the return stack pool. (Remove_Side_Effects): Call CW_Or_Needs_Finalization. * fe.h (Requires_Transient_Scope): Delete. (Returns_On_Secondary_Stack): Declare. * gnat1drv.adb (Adjust_Global_Switches): Set Back_End_Return_Slot to False when generating C code or if -gnatd_r is specified. * opt.ads (Back_End_Return_Slot): New boolean variable. * rtsfind.ads (RTU_Id): Add System_Return_Stack. (RE_Id): Add RE_RS_Allocate and RE_RS_Pool. (RE_Unit_Table): Add entries for RE_RS_Allocate and RE_RS_Pool. * sem_util.ads (CW_Or_Has_Controlled_Part): Delete. (CW_Or_Needs_Finalization): Declare. (Requires_Transient_Scope): Adjust description. (Returns_On_Secondary_Stack): Declare. * sem_util.adb (Compute_Returns_By_Ref): Set Returns_By_Ref on types which need finalization if they are returned on the secondary stack. (CW_Or_Has_Controlled_Part): Rename to... (CW_Or_Needs_Finalization): ...this. (Requires_Transient_Scope): Move bulk of implementation to... (Returns_On_Secondary_Stack): ...here. Return true for types which need finalization only if the back-end return slot is not supported. * libgnat/s-retsta.ads: New file. * gcc-interface/ada-builtin-types.def (BT_FN_PTR_SSIZE): Define. * gcc-interface/ada-builtins.def (return_slot): Likewise. * gcc-interface/ada-tree.h (BUILT_IN_RETURN_SLOT): Likewise. * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Replace call to Requires_Transient_Scope with Returns_On_Secondary_Stack. * gcc-interface/trans.cc (gnat_to_gnu) <N_Simple_Return_Statement>: In the return by invisible reference, skip the copy if the source is the same as the destination. * gcc-interface/utils2.cc (build_call_alloc_dealloc_proc): Deal with the return stack pool.
2022-05-19[Ada] Do not override inlining heuristics for expression functions at -OsEric Botcazou1-1/+8
gcc/ada/ * gcc-interface/trans.cc (Subprogram_Body_to_gnu): Do not deal with inlining heuristics for expression functions here but... * gcc-interface/decl.cc (inline_status_for_subprog): ...here instead and do not override them at -Os.
2022-05-19[Ada] Remove dead code for scope entity having E_Subprogram_Body kindPiotr Trojanek1-4/+0
In GNAT AST the Scope field always points to the semantic scope (e.g. subprogram) and never to syntactic scope (e.g. subprogram body). Cleanup related to handling of circular access-to-record types. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity): Remove dead code which expected Scope to return E_Subprogram_Body entity.
2022-05-13ada: gcc-if: build proper String_Pointer for Get_External_NameAlexandre Oliva1-1/+2
The compiler is allowed to assume it can access String bounds, such as the prefix passed to Get_External_Name, even in circumstances in which the prefix is not going to be used and has_prefix is false, so, from the C side, we have to build a proper String_Template for the String_Pointer. for gcc/ada/ChangeLog * gcc-interface/decl.cc (is_cplusplus_method): Build proper String for Get_External_Name.