diff mbox

[Ada] Crash processing discriminants of private subtype

Message ID 20170425082954.GA75839@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet April 25, 2017, 8:29 a.m. UTC
The compiler may crash processing a private tagged record type has
some component whose type is a subtype of a private type. After
this patch the following test compiles without errors.

package Other_Type is
   package BS is
      type Bounded_String is private;
   private
      type Super_String (Max_Length : Positive) is record
         null;
      end record;
      type Bounded_String is new Super_String (10);
   end;
   
   type S is new BS.Bounded_String;
end;

with Other_Type;
package Pkg is
   type Key_Type is private;
private
   type Key_Type is new Other_Type.S;
end;

package Pkg.Gen_Instance is
   type T is tagged null record;
private
   subtype A_T is Key_Type;
   type Derived is new T with record   -- Test
      X : A_T;
   end record;
end;

Command: gcc -c pkg-gen_instance.ads

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

2017-04-25  Javier Miranda  <miranda@adacore.com>

	* exp_ch3.adb (Build_Initialization_Call): Handle
	subtypes of private types when searching for the underlying full
	view of a private type.
diff mbox

Patch

Index: exp_ch3.adb
===================================================================
--- exp_ch3.adb	(revision 247143)
+++ exp_ch3.adb	(working copy)
@@ -1451,6 +1451,12 @@ 
             elsif Is_Generic_Actual_Type (Full_Type) then
                Full_Type := Base_Type (Full_Type);
 
+            elsif Ekind (Full_Type) = E_Private_Subtype
+              and then (not Has_Discriminants (Full_Type)
+                         or else No (Discriminant_Constraint (Full_Type)))
+            then
+               Full_Type := Etype (Full_Type);
+
             --  The loop has recovered the [underlying] full view, stop the
             --  traversal.