From patchwork Mon Sep 18 09:53:26 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: 814845 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-462372-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="OZBXrf3u"; 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 3xwhCk3DFwz9ryv for ; Mon, 18 Sep 2017 19:53:38 +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=gb7Mekjr4cjgtDmdBLk1wlHp/eBfgwQ3PWABjCZ+94aaDtTD2o BYhqP69sTrRpWpSYEQwF2/7LmZSPKsRWUgqlZLwyFZddlD0ms6Ru5sfULMhUvJl7 7XqHRzqzybU2F0fsGM6Xw/0s1A/YY4CQlR/7f4F5U2XgrHIO9ghpx94SE= 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=Xj2r0BOLXf3egaQdQW+Hv4DgP88=; b=OZBXrf3uPt4ejPVu6Xe8 Wp/d7DkDrbU8esj2xVrLp3YDsjApLVt1Q7ysV3O3TqwfwGnc5MbAWnHGjK89n8+6 GUcBWiPc7dKjJrBNxUaIPzHO2Ha0uKsFfKL0m+F4JINDSlpGc7tsk5JkMy+mx1Ug SWqY4TTdor6FzIdCodmJgkY= Received: (qmail 39811 invoked by alias); 18 Sep 2017 09:53:29 -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 39475 invoked by uid 89); 18 Sep 2017 09:53:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Self 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, 18 Sep 2017 09:53:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 52BE556100; Mon, 18 Sep 2017 05:53:26 -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 dKe3jRpgTBzM; Mon, 18 Sep 2017 05:53:26 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 4227E560E6; Mon, 18 Sep 2017 05:53:26 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 39DEB4FC; Mon, 18 Sep 2017 05:53:26 -0400 (EDT) Date: Mon, 18 Sep 2017 05:53:26 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Implicit_Dereference with access to access and prefix notation Message-ID: <20170918095326.GA75372@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Fix a bug in which a call of the form X.Y (the prefix notation of Y(X)) where X is of a reference type (i.e. a type with the Implicit_Dereference aspect specified), and the access discriminant of X has a designated type that is also an access type, incorrectly gets compilation errors. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ 2017-09-18 Bob Duff * sem_ch4.adb (Complete_Object_Operation): Do not insert 'Access for reference types in the access-to-access case. gcc/testsuite/ 2017-09-18 Bob Duff * gnat.dg/tagged_prefix_call.adb: New testcase. Index: sem_ch4.adb =================================================================== --- sem_ch4.adb (revision 252913) +++ sem_ch4.adb (working copy) @@ -8554,14 +8554,21 @@ ("expect variable in call to&", Prefix (N), Entity (Subprog)); end if; - -- Conversely, if the formal is an access parameter and the object - -- is not, replace the actual with a 'Access reference. Its analysis - -- will check that the object is aliased. + -- Conversely, if the formal is an access parameter and the object is + -- not an access type or a reference type (i.e. a type with the + -- Implicit_Dereference aspect specified), replace the actual with a + -- 'Access reference. Its analysis will check that the object is + -- aliased. elsif Is_Access_Type (Formal_Type) and then not Is_Access_Type (Etype (Obj)) + and then (not Has_Implicit_Dereference (Etype (Obj)) + or else + not Is_Access_Type + (Designated_Type + (Etype (Get_Reference_Discriminant (Etype (Obj)))))) then - -- A special case: A.all'access is illegal if A is an access to a + -- A special case: A.all'Access is illegal if A is an access to a -- constant and the context requires an access to a variable. if not Is_Access_Constant (Formal_Type) then Index: ../testsuite/gnat.dg/tagged_prefix_call.adb =================================================================== --- ../testsuite/gnat.dg/tagged_prefix_call.adb (revision 0) +++ ../testsuite/gnat.dg/tagged_prefix_call.adb (revision 0) @@ -0,0 +1,24 @@ +-- { dg-do compile } + +procedure Tagged_Prefix_Call is + + package Defs is + type Database_Connection_Record is abstract tagged null record; + type Database_Connection is access all Database_Connection_Record'Class; + + procedure Start_Transaction + (Self : not null access Database_Connection_Record'Class) + is null; + + type DB_Connection (Elem : access Database_Connection) + is null record + with Implicit_Dereference => Elem; + end Defs; + + use Defs; + + DB : DB_Connection(null); + +begin + DB.Start_Transaction; +end Tagged_Prefix_Call;