From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21721 invoked by alias); 17 Oct 2009 11:06:08 -0000 Received: (qmail 21713 invoked by uid 22791); 17 Oct 2009 11:06:08 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,HK_OBFDOM 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; Sat, 17 Oct 2009 11:06:04 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 5F65F290009 for ; Sat, 17 Oct 2009 13:06:02 +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 54NXGVLaB533 for ; Sat, 17 Oct 2009 13:05:56 +0200 (CEST) Received: from [192.168.1.2] (83-153-83-223.rev.libertysurf.net [83.153.83.223]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 9740E290003 for ; Sat, 17 Oct 2009 13:05:56 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix type consistency problem with slices Date: Sat, 17 Oct 2009 11:10:00 -0000 User-Agent: KMail/1.9.6 (enterprise 20070904.708012) MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_cVa2KjieDZ1+ghz" Message-Id: <200910171307.08169.ebotcazou@adacore.com> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2009-10/txt/msg01119.txt.bz2 --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 983 The more strict type checking on mainline reveals that gigi builds non-type consistent slices in some cases, i.e. slices whose element type is not the same as the element type of the arrays they are part of. This can happen when the original element type is a discriminated record type with default discriminant, because different padded types are built as effective element types for the array's type and for the slice's type. Recycling padded types has turned to be quite tricky, so adding a conversion seems to be the best approach. Tested on i586-suse-linux, applied on the mainline. 2009-10-17 Eric Botcazou * gcc-interface/utils2.c (build_binary_op) : Make sure the element type is consistent. 2009-10-17 Eric Botcazou * gnat.dg/slice8.adb: New test. * gnat.dg/slice8_pkg1.ads: New helper. * gnat.dg/slice8_pkg2.ads: Likewise. * gnat.dg/slice8_pkg3.ad[sb]: Likewise. -- Eric Botcazou --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-adasrc; charset="us-ascii"; name="slice8.adb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slice8.adb" Content-length: 177 -- { dg-do compile } -- { dg-options "-gnatws" } with Slice8_Pkg1; with Slice8_Pkg3; procedure Slice8 is package Bp is new Slice8_Pkg3 (Slice8_Pkg1); begin null; end; --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-adasrc; charset="us-ascii"; name="slice8_pkg1.ads" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slice8_pkg1.ads" Content-length: 99 with Slice8_Pkg2; package Slice8_Pkg1 is new Slice8_Pkg2 (Line_Length => 132, Max_Lines => 1000); --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-adasrc; charset="us-ascii"; name="slice8_pkg3.ads" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slice8_pkg3.ads" Content-length: 154 with Slice8_Pkg2; generic with package Str is new Slice8_Pkg2 (<>); package Slice8_Pkg3 is function Get return Str.Paragraph; end Slice8_Pkg3; --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-adasrc; charset="us-ascii"; name="slice8_pkg2.ads" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slice8_pkg2.ads" Content-length: 457 generic Line_Length : Natural; Max_Lines : Natural; package Slice8_Pkg2 is Subtype Index is Natural Range 0..Line_length; Subtype Line_Count is Natural Range 0..Max_Lines; Type Line (Size : Index := 0) is Record Data : String (1..Size); End Record; Type Lines is Array (Line_Count Range <>) of Line; Type Paragraph (Size : Line_Count) is Record Data : Lines (1..Size); End Record; end Slice8_Pkg2; --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-adasrc; charset="us-ascii"; name="slice8_pkg3.adb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="slice8_pkg3.adb" Content-length: 391 -- { dg-do compile } -- { dg-options "-gnatws" } package body Slice8_Pkg3 is Current : Str.Lines (Str.Line_Count); Last : Natural := 0; function Get return Str.Paragraph is Result : constant Str.Paragraph := (Size => Last, Data => Current (1..Last)); begin Last := 0; return Result; end Get; end Slice8_Pkg3; --Boundary-00=_cVa2KjieDZ1+ghz Content-Type: text/x-diff; charset="us-ascii"; name="p.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="p.diff" Content-length: 777 Index: gcc-interface/utils2.c =================================================================== --- gcc-interface/utils2.c (revision 152917) +++ gcc-interface/utils2.c (working copy) @@ -755,6 +755,12 @@ build_binary_op (enum tree_code op_code, left_type = TREE_TYPE (left_operand); } + /* For a range, make sure the element type is consistent. */ + if (op_code == ARRAY_RANGE_REF + && TREE_TYPE (operation_type) != TREE_TYPE (left_type)) + operation_type = build_array_type (TREE_TYPE (left_type), + TYPE_DOMAIN (operation_type)); + /* Then convert the right operand to its base type. This will prevent unneeded sign conversions when sizetype is wider than integer. */ right_operand = convert (right_base_type, right_operand); --Boundary-00=_cVa2KjieDZ1+ghz--