[Ada] Fix crash on taft amendment completion with private

Olivier Hainque hainque@adacore.com
Fri Dec 7 15:45:00 GMT 2007


This fixes a regression compared to the GCC 3.x series, introduced
with the support for "limited with" in Ada 2005.

The patch fixes a discrepency between the code and the intent as conveyed
by a comment in our handling of access types, which leads to a compiler
crash while compiling the body of tamdt below:

   package TAMDT is
      pragma Elaborate_Body;
   private
      type TAMT;
      type TAMT_Access is access TAMT;
   end;

   with Tamdt_Aux;
   package body TAMDT is
      type TAMT is new Tamdt_Aux.Priv (X => 1);
   end;

   package Tamdt_Aux is
      type Priv (X : Integer) is private;
   private
      type Priv (X : Integer) is null record;
   end;

The code at hand is part of our handling for E_Access_Type in
gnat_to_gnu_entity:

>       /* Get the "full view" of this entity.  If this is an incomplete
>          entity from a limited with, treat its non-limited view as the full
>          view.  Otherwise, if this is an incomplete or private type, use the
>          full view.  In the former case, we might point to a private type,
>          in which case, we need its full view.  Also, we want to look at the
>          actual type used for the representation, so this takes a total of
>          three steps.  */
>       Entity_Id gnat_desig_full_direct_first
>         = (is_from_limited_with ? Non_Limited_View (gnat_desig_equiv)
>            : (IN (Ekind (gnat_desig_equiv), Incomplete_Or_Private_Kind)
>               ? Full_View (gnat_desig_equiv) : Empty));
>       Entity_Id gnat_desig_full_direct
>         = ((Present (gnat_desig_full_direct_first)
>             && IN (Ekind (gnat_desig_full_direct_first), Private_Kind))
>            ? Full_View (gnat_desig_full_direct_first)
>            : gnat_desig_full_direct_first);
>       Entity_Id gnat_desig_full
>         = Gigi_Equivalent_Type (gnat_desig_full_direct);

 Note how the code differs from what the comment says, in particular
 how we go to the Full_View a second time for Private_Kind even if not
 from_limited_with, despite the comment saying "In the former case ...".

 We indeed used not to do that before the support for Ada 2005 limited
 withs was added, and this is what is causing the bug at hand.

 By following the second level Full_View for TAMT, we eventually elaborate
 it here when processing the access type, totally overlooking a pending
 freeze node for this designated view.

 The patch fixes this by only following the second level Full_View link
 in the from_limited_with case, hence falling back to the previous situation
 in other situations and getting the code in line with what the comment
 says.

 Bootstrapped and reg tested on x86_64-pc-linux-gnu.

 2007-12-07  Olivier Hainque  <hainque@adacore.com>

	ada/
	* decl.c (gnat_to_gnu_entity) <case E_Access_Type>: When computing
	the designated full view, only follow a second level Full_View link
	for Non_Limited_Views of from_limited_with references.

	testsuite/
	* gnat.dg/tamdt*.ad?: Support for ...
	* gnat.dg/test_tamdt.adb: New test.



More information about the Gcc-patches mailing list