From patchwork Thu Jun 17 08:49:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 55988 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 BC13AB7D85 for ; Thu, 17 Jun 2010 18:49:38 +1000 (EST) Received: (qmail 1739 invoked by alias); 17 Jun 2010 08:49:34 -0000 Received: (qmail 1703 invoked by uid 22791); 17 Jun 2010 08:49:33 -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:49:26 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 6C84ECB0254; Thu, 17 Jun 2010 10:49:31 +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 wZ+Th0jQZ3FT; Thu, 17 Jun 2010 10:49:31 +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 50278CB01B2; Thu, 17 Jun 2010 10:49:31 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id E9CFBD9AB0; Thu, 17 Jun 2010 10:49:40 +0200 (CEST) Date: Thu, 17 Jun 2010 10:49:40 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [Ada] Bug box on object of derived array type with repped enumeration index Message-ID: <20100617084940.GA17066@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 The compiler blows up on an object of a derived array type where the index is of an enumeration type with specified representation and the component is of a floating-point type. In this case, the derived type and its parent type were not considered to have the same representation, because the component size of the parent was not getting set by the front end's layout phase (only array types with discrete components were set), whereas the derived type had its component size set properly in Freeze_Type (because its parent type was treated as packed due to the nonstandard representation of its index). The layout for array types now sets the component size in the case of arrays with components of any scalar type. This change also helps avoid expensive (and unnecessary) representation conversions between derived array types of this kind. The package init_scalar_bug.adb, given below, must compile with only the following warning output (or quietly with -gnatws): init_scalar_bug.adb:13:11: warning: default initialization of "Result" may modify overlaid storage init_scalar_bug.adb:13:11: warning: use pragma Import for "Result" to suppress initialization (RM B.1(24)) pragma Initialize_Scalars; package Float_Arr_Pkg is type Repped_Enum is (Enum_1, Enum_2, Enum_3); for Repped_Enum use (Enum_1 => 1, Enum_2 => 2, Enum_3 => 3); type Float_Array is array (Repped_Enum) of Float; end Float_Arr_Pkg; with System; package Init_Scalar_Bug is procedure Proc (Addr : System.Address); end Init_Scalar_Bug; pragma Initialize_Scalars; with Float_Arr_Pkg; package body Init_Scalar_Bug is type New_Float_Array is new Float_Arr_Pkg.Float_Array; procedure Proc (Addr : System.Address) is Result : New_Float_Array; for Result use at Addr; begin null; end Proc; end Init_Scalar_Bug; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-17 Gary Dismukes * layout.adb (Layout_Type): Broaden test for setting an array type's Component_Size to include all scalar types, not just discrete types (components of real types were missed). * sem_ch3.adb (Constrain_Index): Add missing setting of First_Literal on the itype created for an index (consistent with Make_Index and avoids possible Assert_Failures). Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 160843) +++ sem_ch3.adb (working copy) @@ -11071,6 +11071,7 @@ package body Sem_Ch3 is else Set_Ekind (Def_Id, E_Enumeration_Subtype); Set_Is_Character_Type (Def_Id, Is_Character_Type (T)); + Set_First_Literal (Def_Id, First_Literal (T)); end if; Set_Size_Info (Def_Id, (T)); Index: layout.adb =================================================================== --- layout.adb (revision 160834) +++ layout.adb (working copy) @@ -2560,10 +2560,10 @@ package body Layout is begin -- For some reasons, access types can cause trouble, So let's - -- just do this for discrete types ??? + -- just do this for scalar types ??? if Present (CT) - and then Is_Discrete_Type (CT) + and then Is_Scalar_Type (CT) and then Known_Static_Esize (CT) then declare