From patchwork Wed Aug 3 08:11:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 108038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 82FCDB71DE for ; Wed, 3 Aug 2011 18:11:41 +1000 (EST) Received: (qmail 4552 invoked by alias); 3 Aug 2011 08:11:36 -0000 Received: (qmail 4539 invoked by uid 22791); 3 Aug 2011 08:11:33 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Aug 2011 08:11:19 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F01662BB1D6; Wed, 3 Aug 2011 04:11:18 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id pvx4tx6V6O-C; Wed, 3 Aug 2011 04:11:18 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id DC5B22BB13A; Wed, 3 Aug 2011 04:11:18 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id DCAB13FEE8; Wed, 3 Aug 2011 04:11:18 -0400 (EDT) Date: Wed, 3 Aug 2011 04:11:18 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Itype references and generics Message-ID: <20110803081118.GA21537@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Itype references are constructed to force the backend to elaborate itypes at the point of definition, to prevent scope anomalies if the first use of the itype is within some later nested context. Itypes must not be generated for formal generic types, and more generally within a generic unit, because the unit itself is not seen by the backend, and may refer to incomplete types. The following must compile quietly: gcc -c -gnat05 p.adb --- package body P is L: aliased Q.List_Type; function Find return access T'Class is M : Q.Mark_Type (L'Access); begin return T((M.Func.all))'Access; end Find; end P; --- with Q; package P is generic type T is tagged private; function Find return access T'Class; end P; --- package Q is type Object is interface; type List_Type is tagged null record; type Mark_Type (L: access List_Type) is tagged null record; function Func (M : Mark_Type) return access Object'Class; end Q; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-03 Ed Schonberg * sem_ch3.adb (Build_Itype_Reference): do not create an itype reference for an itype created within a generic unit. Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 177237) +++ sem_ch3.adb (working copy) @@ -8631,8 +8631,15 @@ is IR : constant Node_Id := Make_Itype_Reference (Sloc (Nod)); begin - Set_Itype (IR, Ityp); - Insert_After (Nod, IR); + + -- Itype references are only created for use by the back-end. + + if Inside_A_Generic then + return; + else + Set_Itype (IR, Ityp); + Insert_After (Nod, IR); + end if; end Build_Itype_Reference; ------------------------