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]

[PATCH] ada/35791: Generate missing Displace


According to exp_ch3.adb comment, Expand_N_Object_Declaration is supposed
to handle the expansion of "CW : I'Class := Obj;" but the classwide
property was tested on Obj rather than on I'Class. As a result, some
"Displace" calls failed to be generated, and the wrong dispatch table could
be used as exposed by the accompanying test program.

Bootstrapped and regtested on i686-pc-linux-gnu. Ok for trunk?

    gcc/ada/
	PR ada/35791
	* exp_ch3.adb (Expand_N_Object_Declaration): Test classwide
	property on Typ rather than on Expr, as described in the
	comment above the test.

    gcc/testsuite/
	PR ada/35791
	* gnat.dg/check_displace_generation.adb: New.
---

 gcc/ada/exp_ch3.adb                                |    2 -
 .../gnat.dg/check_displace_generation.adb          |   50 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/gnat.dg/check_displace_generation.adb

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index 3ec2789..98a5168 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -4387,7 +4387,7 @@ package body Exp_Ch3 is
             --      CW    : I'Class renames Displace (CW__1, I'Tag);
 
             if Is_Interface (Typ)
-              and then Is_Class_Wide_Type (Etype (Expr))
+              and then Is_Class_Wide_Type (Typ)
               and then Comes_From_Source (Def_Id)
               and then VM_Target = No_VM
             then
diff --git a/gcc/testsuite/gnat.dg/check_displace_generation.adb b/gcc/testsuite/gnat.dg/check_displace_generation.adb
new file mode 100644
index 0000000..2ae2ed0
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/check_displace_generation.adb
@@ -0,0 +1,50 @@
+-- { dg-do run }
+procedure Check_Displace_Generation is
+
+   package Stuff is
+
+      type Base_1 is interface;
+      function F_1 (X : Base_1) return Integer is abstract;
+
+      type Base_2 is interface;
+      function F_2 (X : Base_2) return Integer is abstract;
+
+      type Concrete is new Base_1 and Base_2 with null record;
+      function F_1 (X : Concrete) return Integer;
+      function F_2 (X : Concrete) return Integer;
+
+   end Stuff;
+
+   package body Stuff is
+
+      function F_1 (X : Concrete) return Integer is
+      begin
+         return 1;
+      end F_1;
+
+      function F_2 (X : Concrete) return Integer is
+      begin
+         return 2;
+      end F_2;
+
+   end Stuff;
+
+   use Stuff;
+
+   function Make_Concrete return Concrete is
+      C : Concrete;
+   begin
+      return C;
+   end Make_Concrete;
+
+   B_1 : Base_1'Class := Make_Concrete;
+   B_2 : Base_2'Class := Make_Concrete;
+
+begin
+   if B_1.F_1 /= 1 then
+      raise Program_Error with "bad B_1.F_1 call";
+   end if;
+   if B_2.F_2 /= 2 then
+      raise Program_Error with "bad B_2.F_2 call";
+   end if;
+end Check_Displace_Generation;


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