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] AI 296 and PR ada/25885


Tested on i686-linux, committed on trunk

Change motivated by AI-296: vector and matrix operations.
This is an optimization of front-end inlining: if the call is to
be assigned to an explicit dereference of an entity, this assignment can
be done directly, using the explicit dereference as the target of the
assignment statements generated for each return statement in the original
function. Getting rid of an intermediate temporary and the corresponding
copy is particularly worthwhile for array assignments.

This change also allows concatenation operations with two or three operands to
be fully inlined.

Also: a call within a protected operation may be an internal call to another
protected operation in the same object. Such a call is recognized because
the scope of the operation is a protected type, and it is rewritten as a
call to the corresponding unprotected operation of the type.
In the case of an indirect call through an access parameter of an enclosing
protected operation, the entity being called is the designated type of a
an anonymous access type, and its scope is the protected type. However,
this is a normal indirect call that has no relation to the enclosing type.
--
The following must compile quietly in Ada 2005 mode.
package P is protected L is procedure A (X : access procedure); end; end;
package body P is
   protected body L is
      procedure A (X : access procedure) is
      begin
         X.all;
      end;
   end;
end;

The bounds of a range in an iteration scheme may be overloaded. The
preference rule for ranges of root_integer must be used to disambiguate.
Any remaining ambiguity must be diagnosed, rather than choosing some
interpretation non-deterministically.
--
Compiling loopdemo.adb below must generate the output:
--
loopdemo.adb:17:27: ambiguous bounds in range of iteration
loopdemo.adb:17:27: possible interpretations:
loopdemo.adb:17:27: type "DA" defined at line 7
loopdemo.adb:17:27: type "DAY" defined at line 6
--
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure loopDemo is
    type DAY is (MON,TUE, WED, THU, FRI, SAT, SUN);
    type DA is (MON, WED, THU, FRI, SAT, SUN);
--
    package Da_IO is new Ada.Text_IO.Enumeration_IO(DA);
    use Da_IO;
--
    package Day_IO is new Ada.Text_IO.Enumeration_IO(DAY);
    use Day_IO;
--
begin
    for Day_Of_Week in MON..WED loop
       Put("We are in the workday loop");
       Put(Day_Of_Week);
       New_Line;
    end loop;
  end;

This patch also adds support to handle entities that override inherited
primitive operations that override several abstract interface primitives.
After this patch the following test compiles and executes well.
--
with Ada.Text_IO; use Ada.Text_IO;
procedure Do_Test is
   package Pkg1 is
      type I1 is interface;
      procedure P (A : in I1; R : out Natural) is abstract;
      type I2 is interface;
      procedure P (A : in I2; R : out Natural) is abstract;
      type T4 is tagged null record;
      procedure P (X : T4; R : out Natural);
      type DT5 is new T4 and I1 and I2 with null record;
      procedure P (X : DT5; R : out Natural);
   end Pkg1;
   package body Pkg1 is
      procedure P (X : T4 ; R : out Natural) is begin raise Program_Error; end;
      procedure P (X : DT5; R : out Natural) is begin Put_Line ("OK"); end;
   end Pkg1;
   use Pkg1;
   procedure I1W_P_Test (IW : in I1'Class; R : out Natural) is
   begin
      P (IW, R);
   end I1W_P_Test;
   O_DT5 : DT5;
   R     : Natural;
begin
   Put ("Direct call .......");
   P (O_DT5, R);
   Put ("Class wide call ...");
   I1W_P_Test (O_DT5, R);
end Do_Test;
--
Command: gnatmake -gnat05 do_test.adb
Output:
  Direct call .......OK
  Class wide call ...OK

Also fix GCC PR ada/25885 (compilation of ASIS under x86-64)

2006-02-13  Ed Schonberg  <schonberg@adacore.com>
	    Javier Miranda  <miranda@adacore.com>
	    Robert Dewar  <dewar@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>

	* exp_ch6.adb (Expand_Inlined_Call): Handle calls to functions that
	return unconstrained arrays.
	Update comments.
	(Expand_Call):  An indirect call through an access parameter of a
	protected operation is not a protected call.
	Add circuit to raise CE in Ada 2005 mode following call
	to Raise_Exception.
	(Register_DT_Entry): Do nothing if
	the run-time does not give support to abstract interfaces.
	(Freeze_Subprogram): In case of dispatching operations, do not generate
	code to register the operation in the dispatch table if the source
	is compiled with No_Dispatching_Calls.
	(Register_Predefined_DT_Entry): Generate code that calls the new
	run-time subprogram Set_Predefined_Prim_Op_Address instead of
	Set_Prim_Op_Address.

	* sem_ch5.adb (Analyze_Assignment_Statement): Do not apply length checks
	on array assignments if the right-hand side is a function call that has
	been inlined. Check is performed on the assignment in the block.
	(Process_Bounds): If bounds and range are overloaded, apply preference
	rule for root operations to disambiguate, and diagnose true ambiguity.
	(Analyze_Assignment): Propagate the tag for a class-wide assignment with
	a tag-indeterminate right-hand side even when Expander_Active is True.
	Needed to ensure that dispatching calls to T'Input are allowed and
	get the tag of the target class-wide object.

	* sem_ch6.adb (New_Overloaded_Entity): Handle entities that override
	an inherited primitive operation that already overrides several
	abstract interface primitives. For transitivity, the new entity must
	also override all the abstract interface primitives covered by the
	inherited overriden primitive.
	Emit warning if new entity differs from homograph in same scope only in
	that one has an access parameter and the other one has a parameter of
	a general access type with the same designated type, at the same
	position in the signature.
	(Make_Inequality_Operator): Use source locations of parameters and
	subtype marks from corresponding equality operator when creating the
	tree structure for the implicit declaration of "/=". This does not
	change anything in behaviour except that the decoration of the
	components of the subtree created for "/=" allows ASIS to get the
	string images of the corresponding identifiers.
	(Analyze_Return_Statement): Remove '!' in warning message.
	(Check_Statement_Sequence): Likewise.
	(Analyze_Subprogram_Body): For an access parameter whose designated type
	is an incomplete type imported through a limited_with clause, use the
	type of the corresponding formal in the body.
	(Check_Returns): Implicit return in No_Return procedure now raises
	Program_Error with a compile time warning, instead of beging illegal.
	(Has_Single_Return):  Function returning unconstrained type cannot be
	inlined if expression in unique return statement is not an identifier.
	(Build_Body_To_Inline): It is possible to inline a function call that
	returns an unconstrained type if all return statements in the function
	return the same local variable. Subsidiary procedure Has_Single_Return
	verifies that the body conforms to this restriction.

	* sem_res.adb (Resolve_Equality_Op): If the operands do not have the
	same type, and  one of them is of an anonymous access type, convert
	the other operand to it, so that this is a valid binary operation for
	gigi.
	(Resolve_Type_Conversion): Handle subtypes of protected types and
	task types when accessing to the corresponding record type.
	(Resolve_Allocator): Add '\' in 2-line warning message.
	Remove '!' in warning message.
	(Resolve_Call): Add '\' in 2-line warning message.
	(Valid_Conversion): Likewise.
	(Resolve_Overloaded_Selected_Component): If disambiguation succeeds, the
	resulting type may be an access type with an implicit dereference.
	Obtain the proper component from the designated type.
	(Make_Call_Into_Operator): Handle properly a call to predefined equality
	given by an expanded name with prefix Standard, when the operands are
	of an anonymous access type.
	(Check_Fully_Declared_Prefix): New procedure, subsidiary of Resolve_
	Explicit_Dereference and Resolve_Selected_Component, to verify that the
	prefix of the expression is not of an incomplete type. Allows full
	diagnoses of all semantic errors.
	(Resolve_Actuals): If the actual is an allocator whose directly
	designated type is a class-wide interface we build an anonymous
	access type to use it as the type of the allocator. Later, when
	the subprogram call is expanded, if the interface has a secondary
	dispatch table the expander will add a type conversion to force
	the displacement of the pointer.
	(Resolve_Call): If a function that returns an unconstrained type is
	marked Inlined_Always and inlined, the call will be inlined and does
	not require the creation of a transient scope.
	(Check_Direct_Boolean_Op): Removed
	(Resolve_Comparison_Op): Remove call to above
	(Resolve_Equality_Op): Remove call to above
	(Resolve_Logical_Op): Inline above, since this is only call.
	(Valid_Conversion): Handle properly conversions between arrays of
	convertible anonymous access types.

	PR ada/25885

	(Set_Literal_String_Subtype): If the lower bound is not static, wrap
	the literal in an unchecked conversion, because GCC 4.x needs a static
	value for a string bound.

Attachment: difs.43
Description: Text document


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