From patchwork Tue Jun 22 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: 56416 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 CD2FEB6EF0 for ; Tue, 22 Jun 2010 18:49:56 +1000 (EST) Received: (qmail 30917 invoked by alias); 22 Jun 2010 08:49:50 -0000 Received: (qmail 30561 invoked by uid 22791); 22 Jun 2010 08:49:45 -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; Tue, 22 Jun 2010 08:49:41 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 24E91CB025E; Tue, 22 Jun 2010 10:49:40 +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 jOfw-HG5E2yw; Tue, 22 Jun 2010 10:49:40 +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 12F42CB022F; Tue, 22 Jun 2010 10:49:40 +0200 (CEST) Received: by saumur.act-europe.fr (Postfix, from userid 525) id 0AB11D9B31; Tue, 22 Jun 2010 10:49:40 +0200 (CEST) Date: Tue, 22 Jun 2010 10:49:40 +0200 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Bad bounds checks on slice of explicit dereference Message-ID: <20100622084940.GA3712@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 For a slice whose prefix is an explicit dereference of an access to unconstrained array, the bounds of the slice must be checked against the actual bounds of the designated object, not the bounds of the index subtype, as was the case prior to this change. The following test must compile and execute silently (i.e. Constraint_Error must be raised at the indicated line): with Ada.Text_IO; use Ada.Text_IO; procedure Bounds_Check_Slice_Of_Deref is type A is array (Positive range <>) of Integer; type AA is access all A; X : AA := new A'(1 .. 2 => 0); Y : A (1 .. 3); begin begin Y := X.all (1 .. 3); -- RAISE Constraint_Error; Put_Line ("FAIL"); exception when Constraint_Error => null; end; end Bounds_Check_Slice_Of_Deref; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-22 Thomas Quinot * sem_res.adb (Resolve_Slice): When the prefix is an explicit dereference, construct actual subtype of designated object to generate proper bounds checks. Index: sem_res.adb =================================================================== --- sem_res.adb (revision 161147) +++ sem_res.adb (working copy) @@ -8105,6 +8105,7 @@ package body Sem_Res is end if; elsif Is_Entity_Name (Name) + or else Nkind (Name) = N_Explicit_Dereference or else (Nkind (Name) = N_Function_Call and then not Is_Constrained (Etype (Name))) then