This is the mail archive of the 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] fix bug in handling of elaboration

Tested under i686-linux, commited on mainline.

An initialization call can mention a function F declared in some unit P
that is not in the context of the current compilation. This can also
happen when using object notation with a call to a classwide operation:
the operation is declared in the root package of the class, but the
current compilation only has a with_clause on a package that declares
some other member of the class. In both these cases, the must be some
other unit Q in the context, from which the current unit imports a type
or an object that brings in the function. We locate Q from the subtype
of the object being declared, or from the type of the  first actual in
the call to the classwide operation. An Elaborate_All_Desirable on Q
will ensure that P itself is fully elaborated before the current unit.

The following test case (main procedure try.adb) must compile and execute

package A1 is
   type Rec is tagged record value : Integer := 15; end record;
   function G (X : Rec'Class) return Integer;
end A1;
with B;
package body A1 is
   function G (X : Rec'Class) return Integer is
   begin return X.Value * B.Func; end;
end A1;
with A1;
package A2 is type Rec2 is new A1.Rec with null record; end A2;
with A2;
package a3 is
   Thing: A2.Rec2;
   Val3 : Integer := Thing.G;    --  A1.Thing
package B is function func return integer; end;
with D;
package body B is
   type enum is (this, that, theother);
   table : array (enum) of integer;
   function func return Integer is begin return (table (theother)); end;
   table := (3, 7, 19);
end B;
package D is type unrelated is (it); end;
with a3;
with text_io; use text_io;
procedure try is
   if (a3.val3) /= 285 then put_line ("*** FAILED ***"); end if;

2005-02-09  Ed Schonberg  <>

	* sem_ch4.adb (Analyze_Selected_Component): Create Actual_Subtype even
	with expansion disabled. The actual subtype is needed among other
	places when the selected component appears in the context of a loop
	bound, and denotes a packed array.
	(Operator_Check): Always use the first subtype in the
	error message, to avoid the appearance of internal base types.
	(Transform_Object_Operation): Copy each actual in full
	to the parameter associations of the constructed call, rather than
	using the shallow copy mechanism of New_Copy_List. This ensures that
	the chaining of named associations is done properly.
	(Complete_Object_Operation): Rewrite node, rather than
	replacing it, so that we can trace back to the original selected

	* sem_elab.adb (Set_Elaboration_Constraint): For initialization calls,
	and calls that use object notation, if the called function is not
	declared  in a withed unit, place the elaboration constraint on the
	unit in the context that makes the function accessible.
	(Check_Elab_Subtype_Declaration): Check whether a subtype declaration
	imposes an elaboration constraint between two packages.

Attachment: difs.15
Description: Text document

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