From patchwork Thu Jul 31 09:55:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 375192 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B65F9140175 for ; Thu, 31 Jul 2014 19:55:18 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=G8ltRFHARUUFJVht0f2jaZharQc3/z9I0s9ELFzkfe0xD5i6r+ 6qOSybaQ1FTWPC4lkS/HJhep3TSqruQHPOUWiBZNetQpI6kHR2a8JJ4FDiPy0JD+ cjUUm6JhQpK+bQvNY83bKmVfiBrjaMMQgzcpG+zBb8//NKooSjoh/ISuI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=IdJdOdtrVR18u8xK0eX72JbAdR0=; b=mSZFEStrKrnTAHBHDYBE 1BJLm6NvATbpDUpD/ShaNx7t8dCaGVzzj4dqt03T/0rMSsHHOH+KWaMKWlXYkSbN 14BcHGR7DtydEUE0kXdMsEpaPZDkuotTZsl8GkbZ4bcKwgAaGI5IjOCsbDK40P5A YWin4KCT4DRiv80WfnygEHI= Received: (qmail 24624 invoked by alias); 31 Jul 2014 09:55:12 -0000 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 Received: (qmail 24602 invoked by uid 89); 31 Jul 2014 09:55:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 31 Jul 2014 09:55:07 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 9A29F116321; Thu, 31 Jul 2014 05:55:05 -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 hkjt1mFnCnlw; Thu, 31 Jul 2014 05:55:05 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 8A8ED11631F; Thu, 31 Jul 2014 05:55:05 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 878F191976; Thu, 31 Jul 2014 05:55:05 -0400 (EDT) Date: Thu, 31 Jul 2014 05:55:05 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Crash on complex conditional involving a packed array indexing Message-ID: <20140731095505.GA28139@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) This patch updates the freezing of expressions to account for a case when the freezing expression is part of the Actions list of a N_Expression_With_Actions node. In this case, any freeze nodes must remain in the Actions list. ------------ -- Source -- ------------ -- use_before_decl.adb with Ada.Text_IO; use Ada.Text_IO; procedure Use_Before_Decl is type String_Ptr is access all String; type String_Ptr_Array is array (Positive range <>) of String_Ptr; pragma Pack (String_Ptr_Array); type String_Ptr_Array_Ptr is access all String_Ptr_Array; procedure Print (Data : String_Ptr_Array_Ptr) is begin if Data = null then Put_Line ("Empty"); else for Index in Data.all'Range loop if Data.all (Index) /= null and then Data.all (Index).all'Length > 0 then Put_Line (Data.all (Index).all); end if; end loop; end if; end Print; Data : String_Ptr_Array_Ptr; begin Data := new String_Ptr_Array (1 .. 3); for Index in Data.all'Range loop Data.all (Index) := new String'("Value" & Index'Img); end loop; Print (Data); end Use_Before_Decl; ---------------------------- -- Compilation and output -- ---------------------------- $ gnatmake -q use_before_decl.adb $ ./use_before_decl Value 1 Value 2 Value 3 Tested on x86_64-pc-linux-gnu, committed on trunk 2014-07-31 Hristian Kirtchev * freeze.adb (Freeze_Expression): Update the loop in charge of finding a proper insertion place for freeze nodes to handle N_Expression_With_Actions nodes. Index: freeze.adb =================================================================== --- freeze.adb (revision 213332) +++ freeze.adb (revision 213333) @@ -6143,14 +6143,27 @@ exit when Is_List_Member (P); - -- Note: The N_Loop_Statement is a special case. A type that - -- appears in the source can never be frozen in a loop (this - -- occurs only because of a loop expanded by the expander), so we - -- keep on going. Otherwise we terminate the search. Same is true - -- of any entity which comes from source. (if they have predefined - -- type, that type does not appear to come from source, but the - -- entity should not be frozen here). + -- Freeze nodes produced by an expression coming from the Actions + -- list of a N_Expression_With_Actions node must remain within the + -- Actions list. Inserting the freeze nodes further up the tree + -- may lead to use before declaration issues in the case of array + -- types. + when N_Expression_With_Actions => + if Is_List_Member (P) + and then List_Containing (P) = Actions (Parent_P) + then + exit; + end if; + + -- Note: N_Loop_Statement is a special case. A type that appears + -- in the source can never be frozen in a loop (this occurs only + -- because of a loop expanded by the expander), so we keep on + -- going. Otherwise we terminate the search. Same is true of any + -- entity which comes from source. (if they have predefined type, + -- that type does not appear to come from source, but the entity + -- should not be frozen here). + when N_Loop_Statement => exit when not Comes_From_Source (Etype (N)) and then (No (Nam) or else not Comes_From_Source (Nam));