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] Add missing implicit type conversion


Test on i686-linux, committed on trunk.

There was an implicit type conversion missing in case of allocation
of an object implementing an abstract interface. As a consequence the
secondary dispatch table is not referenced and any dispatching call
that uses the secondary dispatch table fails. After this patch the
 execution of the following test is correct.
--
with Ada.Finalization; use Ada.Finalization;
package Demo is
   type I is interface;
   type I_Ptr is access all I'Class;
   procedure M (Self : in out I) is abstract;
   type Impl is new Controlled and I with null record;
   type Impl_Ptr is access all Impl'Class;
   overriding procedure M (Self : in out Impl);
end Demo;
with Ada.Text_IO; use Ada.Text_IO;
package body Demo is
   overriding procedure M (Self : in out Impl) is begin Put ("OK "); end M;
end Demo;
with Demo;        use Demo;
with Ada.Text_IO; use Ada.Text_IO;
procedure Do_Test is
   procedure Test (Ptr : access I'Class) is
   begin
      M (Ptr.all);
      Ptr.M;
   end Test;
   P : constant I_Ptr := new Impl;  --  test 1
begin
   Put ("Test 1: ");
   M (P.all);
   P.M;
   New_Line;
   Put ("Test 2: ");
   Test (new Impl);                 --  test 2
end Do_Test;
--
Command: gnatmake do_test.adb
Output:
  Test 1: OK OK
  Test 2: OK OK

This patch also fixes missing validity checks for type conversions and
qualified expressions. These checks are under control of -gnatVo
(validity checking for operands).

A test program is:

pragma Validity_Checks ("a");
pragma Initialize_Scalars;
procedure B is
  X, Y : Natural;
  I : Integer;
begin
  I := Integer (X);
  I := Integer'(X);
  I := Y;
end;

Compiling this with -gnatG should show three validity checks, one
for each assignment (previously only the third generated a check).
When run, an exception is raised at the first assignment.

Finally, this patch also corrects an error in configurable run-time mode of
not allowing 64-bit divides by the constant 8 on some targets when using the
configurable run-time with 64-bit divides not supported.

The following should compile clean using a version of system.ads
that has Configurable_Run_Time set True, and Support_LonG_Shifts
set True, and Support_64_Bit_Divides set False.

   procedure Bit_Arrays (Length : Integer) is
      Len : constant Integer := Length;
      type Bit_Array_Type is array (1 .. Len) of Boolean;
      pragma Pack (Bit_Array_Type);
      Bit_Array : Bit_Array_Type := (others => False);
   begin
      null;
   end Bit_Arrays;

Note: this program does 64-bit divides by 8 when computing the
length of the packed array type.

2006-02-17  Javier Miranda  <miranda@adacore.com>
	    Robert Dewar  <dewar@adacore.com>

	* exp_ch4.adb (Expand_N_Allocator): If the allocated object is accessed
	through an access to class-wide interface we force the displacement of
	the pointer to the allocated object to reference the corresponding
	secondary dispatch table.
	(Expand_N_Op_Divide): Allow 64 bit divisions by small power of 2,
	if Long_Shifts are supported on the target, even if 64 bit divides
	are not supported (configurable run time mode).
	(Expand_N_Type_Conversion): Do validity check if validity checks on
	operands are enabled.
	(Expand_N_Qualified_Expression): Do validity check if validity checks
	on operands are enabled.

Attachment: difs.4
Description: Text document


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