public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Crash processing discriminants of private subtype
@ 2017-04-25  8:37 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2017-04-25  8:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Javier Miranda

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 655 bytes --]

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.
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-04-25  8:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  8:37 [Ada] Crash processing discriminants of private subtype Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).