From patchwork Mon Aug 6 07:40:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 175275 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 1B4FA2C009B for ; Mon, 6 Aug 2012 17:40:39 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1344843640; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=tDvt0r4CKxFdecq4ta+b c22xFTU=; b=kUyfiAjqEarJuC3YmbT9LfmLToVgaK+PyZT4Ib8Ur7QdxubAP/h2 y6hP5+7CUZYLSBJ39OA4wa4AGd+mfzIgYhG0zosF3/m6ZLKC7FKnMTDcY0/7sfeK pAwlQIGVW2Jo07ZVtKWY9pgCTLGuDklQJoSi0f9xT7jFdhd80NY2Gfc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=d2f8n+z4nb20+KoO/JOeDZuJ61L99oSGCDWbeSUkL7zTEUrSTp8nM6rLrxeyVE RDd9ucakVZe7ztAfulGbQ7+7tWv5JdO6Syk7idMs8MmNwTTlj7ZElRU9/fNJiBlF epBjLrI5MM5H+r+2O1cHKFxXfo94zpfwtt4tKCP52in4k=; Received: (qmail 635 invoked by alias); 6 Aug 2012 07:40:30 -0000 Received: (qmail 617 invoked by uid 22791); 6 Aug 2012 07:40:28 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO 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; Mon, 06 Aug 2012 07:40:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C78F31C7721; Mon, 6 Aug 2012 03:40:14 -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 lRs5QNyAp7+r; Mon, 6 Aug 2012 03:40:14 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id A1F5A1C770D; Mon, 6 Aug 2012 03:40:14 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id A313692BF6; Mon, 6 Aug 2012 03:40:14 -0400 (EDT) Date: Mon, 6 Aug 2012 03:40:14 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Missing Constraint_Error in illegal conversion to C type Message-ID: <20120806074014.GA18766@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 This patch removes an old range check optimization which incorrectly assumes that the type of an arbitrary expression can always fit in the target type of a conversion. ------------ -- Source -- ------------ -- main.adb with Interfaces; use Interfaces; procedure Main is subtype Small_Positive is Integer_16 range 1 .. Integer_16'Last; type Target_Typ is array (Small_Positive range <>) of Boolean; pragma Convention (C, Target_Typ); subtype Large_Positive is Integer_32 range 1 .. 60_000; type Expr_Typ is array (Large_Positive range <>) of Boolean; type Expr_Typ_Ptr is access Expr_Typ; Expr : constant Expr_Typ := (1 .. 60_000 => True); Expr_Ptr : constant Expr_Typ_Ptr := new Expr_Typ'(Expr); Target : constant Target_Typ := Target_Typ (Expr_Ptr.all); begin null; end Main; ---------------------------- -- Compilation and output -- ---------------------------- $ gnatmake -q main.adb $ ./main.adb raised CONSTRAINT_ERROR : main.adb:16 range check failed Tested on x86_64-pc-linux-gnu, committed on trunk 2012-08-06 Hristian Kirtchev * checks.adb (Discrete_Range_Cond): Do not try to optimize on the assumption that the type of an expression can always fit in the target type of a conversion. Index: checks.adb =================================================================== --- checks.adb (revision 190155) +++ checks.adb (working copy) @@ -6660,12 +6660,6 @@ LB := New_Occurrence_Of (Discriminal (Entity (LB)), Loc); end if; - if Nkind (HB) = N_Identifier - and then Ekind (Entity (HB)) = E_Discriminant - then - HB := New_Occurrence_Of (Discriminal (Entity (HB)), Loc); - end if; - Left_Opnd := Make_Op_Lt (Loc, Left_Opnd => @@ -6677,28 +6671,10 @@ (Base_Type (Typ), Get_E_First_Or_Last (Loc, Typ, 0, Name_First))); - if Base_Type (Typ) = Typ then - return Left_Opnd; - - elsif Compile_Time_Known_Value (High_Bound (Scalar_Range (Typ))) - and then - Compile_Time_Known_Value (High_Bound (Scalar_Range - (Base_Type (Typ)))) + if Nkind (HB) = N_Identifier + and then Ekind (Entity (HB)) = E_Discriminant then - if Is_Floating_Point_Type (Typ) then - if Expr_Value_R (High_Bound (Scalar_Range (Typ))) = - Expr_Value_R (High_Bound (Scalar_Range (Base_Type (Typ)))) - then - return Left_Opnd; - end if; - - else - if Expr_Value (High_Bound (Scalar_Range (Typ))) = - Expr_Value (High_Bound (Scalar_Range (Base_Type (Typ)))) - then - return Left_Opnd; - end if; - end if; + HB := New_Occurrence_Of (Discriminal (Entity (HB)), Loc); end if; Right_Opnd :=