From patchwork Thu Jun 17 08:57:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 55990 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 216C41007D4 for ; Thu, 17 Jun 2010 18:57:20 +1000 (EST) Received: (qmail 8940 invoked by alias); 17 Jun 2010 08:57:19 -0000 Received: (qmail 8929 invoked by uid 22791); 17 Jun 2010 08:57:18 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (212.99.106.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Jun 2010 08:57:13 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id DAACBCB026C; Thu, 17 Jun 2010 10:57:18 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G3AIGngKYh2l; Thu, 17 Jun 2010 10:57:18 +0200 (CEST) Received: from saumur.act-europe.fr (saumur.act-europe.fr [10.10.0.183]) by mel.act-europe.fr (Postfix) with ESMTP id C9410CB01B2; Thu, 17 Jun 2010 10:57:18 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 9263FD9AB0; Thu, 17 Jun 2010 10:57:28 +0200 (CEST) Date: Thu, 17 Jun 2010 10:57:28 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Always freeze slice itype Message-ID: <20100617085728.GA18342@adacore.com> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.9i X-IsSubscribed: yes 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 This change ensures that an itype created for a slice is frozen immediately. Otherwise the itype might end up being elaborated in an outer scope than that of the expression, causing difficulties for coverage analysis. Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-17 Thomas Quinot * sem_res.adb (Set_Slice_Subtype): Always freeze the slice's itype. Index: sem_res.adb =================================================================== --- sem_res.adb (revision 160834) +++ sem_res.adb (working copy) @@ -8958,6 +8958,15 @@ package body Sem_Res is Set_Etype (Index_Subtype, Index_Type); Set_Size_Info (Index_Subtype, Index_Type); Set_RM_Size (Index_Subtype, RM_Size (Index_Type)); + + -- Now replace the discrete range in the slice with a reference to + -- its index subtype. This ensures that further expansion (e.g + -- while rewriting a slice assignment into a FOR loop) does not + -- attempt to remove side effects on the bounds again (which would + -- cause the bounds in the index subtype definition to refer to + -- temporaries before they are defined). + + Set_Discrete_Range (N, New_Copy_Tree (Drange)); end if; Slice_Subtype := Create_Itype (E_Array_Subtype, N); @@ -8970,8 +8979,6 @@ package body Sem_Res is Set_Etype (Slice_Subtype, Base_Type (Etype (N))); Set_Is_Constrained (Slice_Subtype, True); - Check_Compile_Time_Size (Slice_Subtype); - -- The Etype of the existing Slice node is reset to this slice subtype. -- Its bounds are obtained from its first index. @@ -8979,15 +8986,10 @@ package body Sem_Res is -- In the packed case, this must be immediately frozen - -- Couldn't we always freeze here??? and if we did, then the above - -- call to Check_Compile_Time_Size could be eliminated, which would - -- be nice, because then that routine could be made private to Freeze. + -- Always freeze subtype. This ensures that the slice subtype is + -- elaborated in the scope of the expression. - -- Why the test for In_Spec_Expression here ??? - - if Is_Packed (Slice_Subtype) and not In_Spec_Expression then - Freeze_Itype (Slice_Subtype, N); - end if; + Freeze_Itype (Slice_Subtype, N); end Set_Slice_Subtype;