From patchwork Tue May 2 08:18:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 757431 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wHDhL6Mjqz9sD9 for ; Tue, 2 May 2017 18:18:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cL+n7XTG"; dkim-atps=neutral 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=U1hEla8zCe/cjMondkRBkdl2TQ8kwtdFYygqahUO3+Tzd0qMhN f+amGQFv5ptuMuuwBYQVdFDiQ350KIgkzRX9lM03yBrZ6KYTNydTR0RbEnrv77lD m3eZp+V49TvvOdiBAkwi7HsW+tekHq9IhXAo74j4JTwzn4o2Af1Mf8jBo= 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=de7eafvX1RoxLBbksFpQCYHIUbA=; b=cL+n7XTGJwji0JHqDFqR G8RaS+AYRKcAUcefhzmZW3Sxe6FW4OEFNK1JgNPk2PFdj0LmIaNy0LG2r4kn/N7m i185x/MZoSlQtZMomncg9tCEL+jU0DL5UqhYMDGubDx5At/x7byg6hhTqwrBrbX7 6931WNwEcAAbegohqXLlD5M= Received: (qmail 125312 invoked by alias); 2 May 2017 08:18:28 -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 125247 invoked by uid 89); 2 May 2017 08:18:27 -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=Hx-languages-length:1483, Thing 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; Tue, 02 May 2017 08:18:26 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 794229E9C; Tue, 2 May 2017 04:18:27 -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 NlVcWIZY8e+J; Tue, 2 May 2017 04:18:27 -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 673BA9D91; Tue, 2 May 2017 04:18:27 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 633354FF; Tue, 2 May 2017 04:18:27 -0400 (EDT) Date: Tue, 2 May 2017 04:18:27 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Compiler loop on use of a faulty object in an address clause. Message-ID: <20170502081827.GA127823@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes a loop in the compiler when an address clause is used to specify an overlay, and the overlaid object has an illegal object declaration in which the expression is a premature reference to the object itself. Compiling p.ads must yield: p.ads:3:33: object "Nowhere" cannot be used before end of its declaration --- with system; use system; --- with System; use System; package P is Nowhere : constant Address := Nowhere; Thing : Integer; for Thing'Address use Nowhere; end; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-05-02 Ed Schonberg * sem_ch8.adb (Premature_Usage): If the premature usage of an entity is as the expression in its own object decaration, rewrite the reference as Any_Id to prevent cascaded errors or compiler loops when such an entity is used in an address clause. Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 247461) +++ sem_ch8.adb (working copy) @@ -8562,6 +8562,14 @@ else Error_Msg_N ("object& cannot be used before end of its declaration!", N); + + -- If the premature reference appears as the expression in its own + -- declaration, rewrite it to prevent compiler loops in subsequent + -- uses of this mangled declaration in address clauses. + + if Nkind (Parent (N)) = N_Object_Declaration then + Set_Entity (N, Any_Id); + end if; end if; end Premature_Usage;