From patchwork Mon Oct 9 20:00:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 823468 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-463810-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="BLQ0EWFa"; 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 3y9rh84bPnz9rxl for ; Tue, 10 Oct 2017 07:00:24 +1100 (AEDT) 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=Bulk7wQSaWCvOEovi8kdl5H16nBNXtC6rr5oD563YOAC3H/21S 2OCaEYIYcouJw6V3osLejKMEZSUuD9Rl9jA1z7EjLE8IlcOp7o36HGFBfIvbN8Nh bFjdT/dFu7CVVAK0mzDlZYN6ZiLaSw6YDDfSXO8PJDxMXE1bELnX9XPVI= 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=zWgouLyj+UGkWNkx1zvhvA5ZO68=; b=BLQ0EWFa5b7/SPHu9p9X EiF1lmJXoqEqwHQFQq8qkkiHq9YaddqtUzBJoohf95E2PqVvewQ8ScE0+5GqFObn Mq+L5xpZTkHoYy3/SDV339M0acT/6GWL7F94ydnKlDsrKN81h4BDaYb1GbB6XwoP FpRg3qMuRj6x/4zneheP3ls= Received: (qmail 15749 invoked by alias); 9 Oct 2017 20:00:16 -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 15701 invoked by uid 89); 9 Oct 2017 20:00:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=typu, vy, our 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; Mon, 09 Oct 2017 20:00:12 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D6590561D5; Mon, 9 Oct 2017 16:00:09 -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 wPY4GTEyG+FX; Mon, 9 Oct 2017 16:00:09 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id B8E4656325; Mon, 9 Oct 2017 16:00:09 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id B7FEB43A; Mon, 9 Oct 2017 16:00:09 -0400 (EDT) Date: Mon, 9 Oct 2017 16:00:09 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Spurious error in use of homograph of type name in predicate Message-ID: <20171009200009.GA43529@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch fixes a spurious error in an expression for a dynamic predicate, when the name of (a homograph of) the type to which the predicate applies is used in a context where the name cannot denote a current occurrence. The following must compile quietly: gcc -c conv.ads --- with Typ; use Typ; package Conv with SPARK_Mode is private type U is new Typ.U with record X : Integer; end record with Dynamic_Predicate => Typ.U(U).Get > 0; end Conv; --- package Typ is type U is tagged private; function Get (V : U) return Integer; private type U is tagged record Y : Integer; end record; function Get (V : U) return Integer is (V.Y); end Typ; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-10-09 Ed Schonberg * sem_ch13.adb (Replace_Type_Ref): In the expression for a dynamic predicate, do not replace an identifier that matches the type if the identifier is a selector in a selected component, because this indicates a reference to some homograph of the type itself, and not to the current occurence in the predicate. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 253546) +++ sem_ch13.adb (working copy) @@ -4415,15 +4415,6 @@ if Present (Default_Element) then Analyze (Default_Element); - - if Is_Entity_Name (Default_Element) - and then not Covers (Entity (Default_Element), Ret_Type) - and then False - then - Illegal_Indexing - ("wrong return type for indexing function"); - return; - end if; end if; -- For variable_indexing the return type must be a reference type @@ -12670,10 +12661,18 @@ return Skip; - -- Otherwise do the replacement and we are done with this node + -- Otherwise do the replacement if this is not a qualified + -- reference to a homograph of the type itself. Note that the + -- current instance could not appear in such a context, e.g. + -- the prefix of a type conversion. else - Replace_Type_Reference (N); + if Nkind (Parent (N)) /= N_Selected_Component + or else N /= Selector_Name (Parent (N)) + then + Replace_Type_Reference (N); + end if; + return Skip; end if; @@ -12682,7 +12681,7 @@ elsif Nkind (N) = N_Selected_Component then - -- If selector name is not our type, keeping going (we might still + -- If selector name is not our type, keep going (we might still -- have an occurrence of the type in the prefix). if Nkind (Selector_Name (N)) /= N_Identifier