[Ada] Fix run-time segfault with derived access-to-subprogram type
diff mbox series

Message ID 20190919132819.GA41804@adacore.com
State New
Headers show
Series
  • [Ada] Fix run-time segfault with derived access-to-subprogram type
Related show

Commit Message

Pierre-Marie de Rodat Sept. 19, 2019, 1:28 p.m. UTC
This fixes a segfault at run time for the call to a local subprogram
through an access value if the type of this access value is derived
from an initial access-to-subprogram type and the access value was
originally obtained with the initial type.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-09-19  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* sem_ch3.adb (Build_Derived_Access_Type): If this is an access-
	to-subprogram type, copy Can_Use_Internal_Rep from the parent.

gcc/testsuite/

	* gnat.dg/access9.adb: New testcase.

Patch
diff mbox series

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -6723,6 +6723,11 @@  package body Sem_Ch3 is
                               Has_Private_Component (Derived_Type));
       Conditional_Delay      (Derived_Type, Subt);
 
+      if Is_Access_Subprogram_Type (Derived_Type) then
+         Set_Can_Use_Internal_Rep
+           (Derived_Type, Can_Use_Internal_Rep (Parent_Type));
+      end if;
+
       --  Ada 2005 (AI-231): Set the null-exclusion attribute, and verify
       --  that it is not redundant.
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/access9.adb
@@ -0,0 +1,20 @@ 
+--  { dg-do run }
+
+procedure Access9 is
+
+  type A_Type is access procedure;
+
+  type B_Type is new A_Type;
+
+  procedure Invoke (B : B_Type) is
+  begin
+    B.all;
+  end;
+
+  procedure Nested is begin null; end;
+
+  A : A_Type := Nested'Access;
+
+begin
+  Invoke (B_Type (A));
+end;
\ No newline at end of file