From patchwork Thu Oct 13 10:39:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 119412 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 D1DDBB6F88 for ; Thu, 13 Oct 2011 21:39:44 +1100 (EST) Received: (qmail 31529 invoked by alias); 13 Oct 2011 10:39:41 -0000 Received: (qmail 31518 invoked by uid 22791); 13 Oct 2011 10:39:40 -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; Thu, 13 Oct 2011 10:39:23 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E739C2BB04C; Thu, 13 Oct 2011 06:39:22 -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 shkdmSnCHQZ6; Thu, 13 Oct 2011 06:39:22 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id D491F2BB02D; Thu, 13 Oct 2011 06:39:22 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id D299A92BF6; Thu, 13 Oct 2011 06:39:22 -0400 (EDT) Date: Thu, 13 Oct 2011 06:39:22 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [Ada] Entity list of for loop for enumeration with rep gets truncated Message-ID: <20111013103922.GA5409@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 When a for loop for an enumeration type with an enumeration representation clause is expanded, it's rewritten as a loop over an integer loop parameter and the original loop parameter is moved into a new nested block. When the block is analyzed, the moved entity gets appended to the block scope's entity list (as it should), but is left on the loop scope's entity list, and no longer has a successor (because its Next_Entity is set to null). This causes other entities on the loop to get lost from the loop's entity list. The fix is to remove the loop parameter entity from the loop scope's list, leaving any other declarations on that list intact (such as an itype for the loop paramter's subtype). This problem surfaced when generating debugging info with the GNAAMP compiler, due to encountering a loop parameter's itype that was not found on any entity list. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-13 Gary Dismukes * exp_ch5.adb (Expand_N_Loop_Statement): For the transformation of a for loop for an enumeration type with an enumeration rep clause, which involves moving the original loop parameter into a nested block, the loop parameter's entity must be removed from the entity list of the loop scope. Index: exp_ch5.adb =================================================================== --- exp_ch5.adb (revision 179894) +++ exp_ch5.adb (working copy) @@ -3458,6 +3458,20 @@ Statements => Statements (N)))), End_Label => End_Label (N))); + + -- The loop parameter's entity must be removed from the loop + -- scope's entity list, since itw will now be located in the + -- new block scope. Any other entities already associated with + -- the loop scope, such as the loop parameter's subtype, will + -- remain there. + + pragma Assert (First_Entity (Scope (Loop_Id)) = Loop_Id); + + Set_First_Entity (Scope (Loop_Id), Next_Entity (Loop_Id)); + if Last_Entity (Scope (Loop_Id)) = Loop_Id then + Set_Last_Entity (Scope (Loop_Id), Empty); + end if; + Analyze (N); -- Nothing to do with other cases of for loops