From patchwork Wed Sep 6 11:52:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 810528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461588-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mr6hDgl0"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xnMQq5Y8Hz9sBW for ; Wed, 6 Sep 2017 21:52:51 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=L1pOr1J5lFwVxq9hsC2rliQQVpxksOgKHWRqOjODgCIjjfbDZT mPqJB8Xpc68PLUQQkRBMmcYlNpvyb45wTqgb2gyYrHi7g+kJV9EHsNmJnAXongm4 6u7OKIvXtTPegicga+sYjbVFL0IMjuGMAiR28sV1lIDG8F9lCGTM92xSU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=QoMC9xcgskajtG1ep/ZGtp7r+hM=; b=mr6hDgl0uizb/VS/aBEp dyaJVJdHSnsEcjpKh9UchOvUkEl/N0tbmdr5fdeFzxUIeRPeh59aTzdyaHCEF2eE idrStG4szSkdshb/U8w4zITyBzKTqAGnJFuWx6kH8xwGD/Ezv3TMnFZbC10BjvhB l/pZGm3Yh3dSH5/GdI8V61U= Received: (qmail 93408 invoked by alias); 6 Sep 2017 11:52:45 -0000 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 Received: (qmail 93189 invoked by uid 89); 6 Sep 2017 11:52:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Sep 2017 11:52:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 55BD05614B; Wed, 6 Sep 2017 07:52:38 -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 THvNSi+orVpT; Wed, 6 Sep 2017 07:52:38 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 455A156142; Wed, 6 Sep 2017 07:52:38 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 41A6D4AC; Wed, 6 Sep 2017 07:52:38 -0400 (EDT) Date: Wed, 6 Sep 2017 07:52:38 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Crash when issuing warning on uninitialized value Message-ID: <20170906115238.GA129382@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) When issuing a warning on a read of an uninitialized variable through reading an attribute such as Loop_Entry, GNAT could crash. Now fixed. GNAT issues a warning as expected on the following code: $ gcc -c s.adb 1. package S is 2. 3. type Array_Range is range 1 .. 10; 4. 5. type IntArray is array (Array_Range) of Integer; 6. 7. procedure Move (Dest, Src : aliased out IntArray); 8. 9. end S; 1. package body S is 2. 3. procedure Move (Dest, Src : aliased out IntArray) is 4. begin 5. for Index in Dest'Range loop 6. pragma Assert (for all J in Dest'First .. Index - 1 => 7. Dest (J) = Src'Loop_Entry (J)); 1 2 >>> warning: "Dest" may be referenced before it has a value >>> warning: "Src" may be referenced before it has a value 8. 9. Dest (Index) := Src (Index); 10. Src (Index) := 0; 11. end loop; 12. end Move; 13. 14. end S; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-06 Yannick Moy * sem_warn.adb (Check_References): Take into account possibility of attribute reference as original node. Index: sem_warn.adb =================================================================== --- sem_warn.adb (revision 251773) +++ sem_warn.adb (working copy) @@ -1382,16 +1382,22 @@ -- deal with case where original unset reference has been -- rewritten during expansion. - -- In some cases, the original node may be a type conversion - -- or qualification, and in this case we want the object - -- entity inside. + -- In some cases, the original node may be a type + -- conversion, a qualification or an attribute reference and + -- in this case we want the object entity inside. Same for + -- an expression with actions. UR := Original_Node (UR); while Nkind (UR) = N_Type_Conversion or else Nkind (UR) = N_Qualified_Expression or else Nkind (UR) = N_Expression_With_Actions + or else Nkind (UR) = N_Attribute_Reference loop - UR := Expression (UR); + if Nkind (UR) = N_Attribute_Reference then + UR := Prefix (UR); + else + UR := Expression (UR); + end if; end loop; -- Don't issue warning if appearing inside Initial_Condition