This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] clean up expansion of tagged types


Tested on i686-linux, committed on trunk

For class-wide allocators, Ada 2005 introduced checks that the type of
the allocated object must have a tag corresponding to a type whose
accessibility level is no deeper than that of the access type of the
allocator. In the specific case where the access type is declared
within a subprogram we know statically that the check must succeed
if the allocator occurs at the same level as the access type. This is
true even when the expression of the allocator originates from a formal
parameter of an enclosing scope, because the tagged type is necessarily
at a shallower accessibility level. The described case was failing in
some situations because the implementation uses static levels to implement
the accessibility check, which won't work if the underlying type of the
class-wide object has a deeper static level than the access type. The
change is simply to compare the scopes of the allocator and the access
type, and the run-time check is suppressed when they're equal.

gnat.dg/access_test.adb must execute without raising an exception.

This patch is also part of an ongoing work
to cleanup the code generated by the frontend to fill the run-time
structures associated with tagged types. The level of abstraction
of the generated code has been raised: instead of expanding the
TSD table into a sequence of Storage_Units plus further code to
initialize each component, the table is now expanded as a record
with a discriminant and it is initialized by means of an aggregate.
This leaves the expanded code more clear but also allows us to
remove undesired extra code compiling under restriction
No_Dispatching_Calls.

In some cases interface conversions require the creation of a local
function that performs a pointer adjustment into a dispatch table. the
body of this function must be inserted immediately before the expression
that contains the conversion, because otherwise the body may end up
referencing prematurely an internal subtype whose declaration is also
generated by the expression.
icp_executors.ads must compile quietly in Ada 2005 mode.
--
package Ifaces is
  type Executor is limited interface;
  type Any_Executor is access all Executor'Class;
--
  type Completion_Service is limited interface and Executor;
--
  type Reusable_Future is synchronized interface;
  type Any_Reusable_Future is access all Reusable_Future'Class;
--
  type Buffer is synchronized interface;
  type Any_Buffer is access all Buffer'Class;
  protected type Mailbox (Max : Positive) is new Buffer with end;
end Ifaces;
--
package body Ifaces is
  protected body Mailbox is end;
end Ifaces;
--
with Ifaces; use Ifaces;
generic
package CP_Executors is
  protected type Completion_Future
    (B  : Any_Buffer;
     Me : Any_Reusable_Future)
    is new Reusable_Future with end;
--
  type Completion_Pool_Executor (Pool_Size : Positive) is
    limited new Completion_Service with
  record
    Buf : aliased Mailbox (Pool_Size);
  end record;
end CP_Executors;
--
package body CP_Executors is
  protected body Completion_Future is end;
--
  function Create(E: Any_Executor) return Any_Reusable_Future is
    Tmp: Any_Reusable_Future;
  begin
      Tmp := new Completion_Future(
              Completion_Pool_Executor(E.all).Buf'Unchecked_Access,
              Tmp);
      return Tmp;
  end Create;
end CP_Executors;
--
with CP_Executors;
package ICP_Executors is new CP_Executors;


This patch also adds missing support for interface type derivations. After
applied, gnat.dg/interface2.adb compiles and executes without errors.

2007-04-06  Javier Miranda  <miranda@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>

	* exp_ch13.adb (Expand_External_Tag_Definition): Replace call to the
	run-time subprogram Set_External_Tag by call to Build_Set_External_Tag.

	* exp_ch4.adb (Expand_Allocator_Expression): Don't perform a run-time
	accessibility on class-wide allocators if the allocator occurs at the
	same scope level as the allocator's type. The check is guaranteed to
	succeed in that case, even when the expression originates from a
	parameter of the containing subprogram.
	(Expand_N_Op_Eq): Do nothing in case of dispatching call if compiling
	under No_Dispatching_Calls restriction. During the semantic analysis
	we already notified such violation.
	(Tagged_Membership): Constant folding. There is no need to check
	the tag at run-time if the type of the right operand is non
	class-wide abstract.
	Replace call to Is_Ancestor by call to Is_Parent
	to support concurrent types with interface types.
	(Expand_N_Allocator): Add an assertion associated with the generation
	of the master_id.
	(Expand_N_Slice): Do not enable range check to nodes associated
	with the frontend expansion of the dispatch table.
	(Is_Local_Access_Discriminant): Subsidiary function to
	Expand_N_Allocator.
	(Tagged_Membership): Replace generation of call to the run-time
	subprogram CW_Membership by call to Build_CW_Membership.
	(Expand_Allocator_Expression): Replace generation of call to the
	run-time subprogram Get_Access_Level by call to Build_Get_Access_Level.

	* exp_disp.ads, exp_disp.adb (Make_DT): Code reorganization to
	initialize most the TSD components by means of an aggregate.
	Modify the declaration of the object containing the TSD
	because we now expand code that has a higher level of abstraction.
	The TSD has a discriminant containing the Inheritance Depth Level,
	value that is used in the membership test but also to fix the size
	of the table of ancestors.
	(Expand_Interface_Conversion): Insert function body at the closest place
	to the conversion expression, to prevent access-before-elaboration
	errors in the backend.
	Code improved to reduce the size of the dispatch table if
	compiling under restriction No_Dispatching_Calls plus code cleanup.
	Code reorganization plus removal of calls to Set_Num_Prim_Ops
	(Make_Secondary_DT): Remove call to Set_Num_Prim_Ops.
	(Expand_Dispatching_Call): Minor code reorganization plus addition of
	code to return immediately if compiling under No_Dispatching_Calls
	restriction.
	(Set_All_DT_Position): Remove code associated with the old CPP pragmas.
	CPP_Virtual and CPP_Vtable are no longer supported.
	(Expand_Interface_Conversion): Add missing support for interface type
	derivations.
	(Expand_Interface_Actuals): Replace calls to Is_Ancestor by calls to
	Is_Parent to support concurrent types with interfaces.
	(Init_Predefined_Interface_Primitives): Removed.
	(Make_Secondary_DT): Modified to support concurrent record types.
	(Set_All_DT_Position): Modified to support concurrent record types.
	(Ada_Actions, Action_Is_Proc, Action_Nb_Arg): Remove entries associated
	with Get_External_Tag, Inherit_TSD, Set_External_Tag.
	(Ada_Actions, Action_Is_Proc, Action_Nb_Arg): Remove entry associated
	with CW_Membership.
	(Ada_Actions, Action_Is_Proc, Action_Nb_Arg): Remove entries associated
	with Get_Access_Level, Get_Predefined_Prim_Op_Address,
	Get_Prim_Op_Address Get_RC_Offset, Get_Remotely_Callable, Inherit_DT,
	Set_Access_Level, Set_Expanded_Name, Set_Predefined_Prim_Op_Address,
	Set_Prim_Op_Address, Set_RC_Offset, Set_Remotely_Callable, Set_TSD.
	(Expand_Dispatching_Call): Replace generation of call to the run-time
	subprograms Get_Predefined_Prim_Op_Address and Get_Prim_Op_Address by
	calls to Build_Get_Predefined_Prim_Op_Address, and Build_Get_Prim_Op_
	Address.
	(Fill_DT_Entry, Fill_Secondary_DT_Entry): Replace generation of call to
	the run-time subprograms Set_Predefined_Prim_Op_Address and Set_Prim_
	Op_Address by calls to Build_Set_Predefined_Prim_Op_Address, and
	Build_Set_Prim_Op_Address.
	(Get_Remotely_Callable): Subprogram removed.
	(Init_Predefined_Interface_Primitives): Replace generation of call to
	the run-time subprograms Inherit_DT by call to Build_Inherit_Predefined_
	Prims.

	* sem_elab.adb (Set_Elaboration_Constraint): Replace the call to
	First (Parameter_Associations ()) with the call to First_Actual that
	returns an actual parameter expression for both named and positional
	associations.

	* sem_disp.adb (Check_Dispatching_Call): In case of dispatching call
	check violation of restriction No_Dispatching_Calls.
	(Check_Controlling_Type): A formal of a tagged incomplete type is a
	controlling argument.

	* exp_util.ads, exp_util.adb (Type_May_Have_Bit_Aligned_Components): Use
	First/Next_Component_Or_Discriminant
	(Insert_Actions): Add entries for new N_Push and N_Pop nodes
	(Find_Implemented_Interface): Removed. All the calls to this subprogram
	specify Any_Limited_Interface, and this functionality is already
	provided by the function Has_Abstract_Interfaces.
	(Find_Interface, Find_Interface_Tag, Find_Interface_ADT): Modified to
	support concurrent types implementing interfaces.
	(Find_Implemented_Interface): Removed. All the calls to this subprogram
	specify kind Any_Limited_Interface, and this functionality is already
	provided by the function Has_Abstract_Interfaces.
	(Remove_Side_Effects): replace Controlled_Type by
	CW_Or_Controlled_Type whenever the issue is related to
	using or not the secondary stack.

	* par-ch12.adb (P_Formal_Type_Definition): Update calls to
	P_Interface_Type_Definition to fulfill the new interface (the formal
	Is_Synchronized is no longer required).

	* Make-lang.in (GNAT_ADA_OBJS): Addition of exp_atag.o
	Update dependencies.

	* exp_atag.ads, exp_atag.adb: New file

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]