From patchwork Mon Oct 25 17:18:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 69162 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 B9F99B6EEB for ; Tue, 26 Oct 2010 15:13:22 +1100 (EST) Received: (qmail 26008 invoked by alias); 26 Oct 2010 04:13:20 -0000 Received: (qmail 25996 invoked by uid 22791); 26 Oct 2010 04:13:18 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (140.186.70.92) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 26 Oct 2010 04:13:13 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAQoh-00035v-FM for gcc-patches@gcc.gnu.org; Mon, 25 Oct 2010 13:26:40 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:39505) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAQoh-000357-82 for gcc-patches@gcc.gnu.org; Mon, 25 Oct 2010 13:26:39 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 7348CCB02D8 for ; Mon, 25 Oct 2010 19:26:20 +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 VV9pmX0uNlsf for ; Mon, 25 Oct 2010 19:26:20 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 1E80DCB02D5 for ; Mon, 25 Oct 2010 19:26:20 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix null dereference in loop at -O or above Date: Mon, 25 Oct 2010 19:18:06 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201010251918.06452.ebotcazou@adacore.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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 fixes a crash at run time caused by a dereference of the null pointer. The problem is that we put both TREE_READONLY and TREE_THIS_NOTRAP on the INDIRECT_REF built to access the bounds of fat pointer types. While this fine if it is later instantiated for an unconstrained array, this isn't if it is later instantiated for a pointer to unconstrained array, as the pointer can be null and LIM will hoist everything out of loops, removing any guard before the dereference in the process. So the conservative fix is not to put TREE_THIS_NOTRAP at all. Tested on i586-suse-linux, applied on the mainline. 2010-10-25 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Do not set TREE_THIS_NOTRAP on the INDIRECT_REF node built for the template. 2010-10-25 Eric Botcazou * gnat.dg/loop_optimization8.adb: New test. * gnat.dg/loop_optimization8_pkg1.ad[sb]: New helper. * gnat.dg/loop_optimization8_pkg2.ad[sb]: Likewise. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 165914) +++ gcc-interface/decl.c (working copy) @@ -1942,7 +1942,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entit gnu_template_reference = build_unary_op (INDIRECT_REF, gnu_template_type, tem); TREE_READONLY (gnu_template_reference) = 1; - TREE_THIS_NOTRAP (gnu_template_reference) = 1; /* Now create the GCC type for each index and add the fields for that index to the template. */