From patchwork Tue Jan 11 13:32:07 2022 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: 1578473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gFsHq4H0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYBr93KTWz9s0r for ; Wed, 12 Jan 2022 00:49:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 032AD385781F for ; Tue, 11 Jan 2022 13:49:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 032AD385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641908951; bh=0TdvVBjsGzLj33KB4io9PEaKLsVQx4Q+rGvXwVltlVg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=gFsHq4H0fnxnU7avai1VpWCFqf53ATn54cJ3lnaMcwv6lUeiOt0S0Lyt91ToYLXjx Csh1HqTMI+Mh8vXVt/xHuK7QKIGx5/NiZaLrfb90tcAqqbx9hK+gYBfRdSHBMRDr21 FxfNugw9C2KHgIAnI0bl10q9KNIWsBFBMRC3TOvQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id E2ECB38A9433 for ; Tue, 11 Jan 2022 13:32:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2ECB38A9433 Received: by mail-wr1-x42a.google.com with SMTP id o3so32967417wrh.10 for ; Tue, 11 Jan 2022 05:32:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=0TdvVBjsGzLj33KB4io9PEaKLsVQx4Q+rGvXwVltlVg=; b=Re9uFao35ysVXqhuCZhQKxaI8cuCF0pCGeGfbgHrjai2vuldgbR29FJtsYNCQNZPuC Jf0SrpcK+yoPmqwMp6VQ/jID8kKErdJL+2rgF9lFDUaIvIqB3WJHP3lqYRXmS1Obb0dC MuLunJ9w77dCBXtamrHdrfZCPBysCUMKx+6aqzT550/iRmPw2E6LrF0QUq+rQCw7cggj hGkgQb1tTrCInQCE3cm1VhVksOa11aKeHHa2uEVo0yM08Zz/nacwDk86XoFYkK696Orl ox3obrZGOJq/DXz89dtMwm6BaEFW+eigDRAQH9cvwUgnBZiB4qTRpbzUn7Ce7b4A8qQT PVfQ== X-Gm-Message-State: AOAM531RVSFQp369tB+ixv+2K8MKbNx0vLQpXL1B7O2xG2xFq0k2qSvD dKjUUE8tcaVwAt6rY1yZn4gC8U8uhyaNIw== X-Google-Smtp-Source: ABdhPJyz5t/or9dMhIiAvaB5Equ+6BCa6L/qsjzXi/kBQGRfnM450JheReGutP+InDS4+iRgPNE44A== X-Received: by 2002:a5d:634e:: with SMTP id b14mr3442396wrw.105.1641907928997; Tue, 11 Jan 2022 05:32:08 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id w17sm1993251wmc.14.2022.01.11.05.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:32:08 -0800 (PST) Date: Tue, 11 Jan 2022 13:32:07 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Conformance error on protected subp with anonymous-access-to-tagged formal Message-ID: <20220111133207.GA748614@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Gary Dismukes Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The compiler incorrectly rejected a protected subprogram with a formal of an anonymous access type that designates a tagged type when the protected type extends an interface and the formal's designated type (a different type) is declared immediately within the same scope as the protected type; an error is issued about the declaration and body not conforming. This occurs in conjunction with the (nonprotected) wrapper subprogram created for the protected subprogram, which is declared in the scope enclosing the protected type. It appears to the compiler that the type of the access formal of the wrapper subprogram doesn't conform with the declaration, due to null exclusions being different. The flag Can_Never_Be_Null gets set on one formal parameter and not the other, because Check_Controlling_Type sees that the formal's designated type is declared in the same scope as the wrapper subprogram, and as a result decides that the access formal is a controlling formal when it really isn't (so sets Can_Never_Be_Null since controlling access-to-tagged formals are defined to exclude null). This problem is fixed by adding a special check in Check_Controlling_Type to prevent treating formals of anonymous-access-to-tagged types as controlling when the subprogram has an associated protected subprogram and the tagged type is not the record type associated with the protected subprogram's enclosing protected type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_disp.adb (Check_Controlling_Type): Add test for the case where Subp is a subprogram associated with a protected subprogram and return Empty, unless Tagged_Type is the corresponding record type of the protected type. diff --git a/gcc/ada/sem_disp.adb b/gcc/ada/sem_disp.adb --- a/gcc/ada/sem_disp.adb +++ b/gcc/ada/sem_disp.adb @@ -478,6 +478,29 @@ package body Sem_Disp is if No (Tagged_Type) or else Is_Class_Wide_Type (Tagged_Type) then return Empty; + -- In the special case of a protected subprogram of a tagged protected + -- type that has a formal of a tagged type (or access formal whose type + -- designates a tagged type), such a formal is not controlling unless + -- it's of the protected type's corresponding record type. The latter + -- can occur for the special wrapper subprograms created for protected + -- subprograms. Such subprograms may occur in the same scope where some + -- formal's tagged type is declared, and we don't want formals of that + -- tagged type being marked as controlling, for one thing because they + -- aren't controlling from the language point of view, but also because + -- this can cause errors for access formals when conformance is checked + -- between the spec and body of the protected subprogram (null-exclusion + -- status of the formals may be set differently, which is the case that + -- led to adding this check). + + elsif Is_Subprogram (Subp) + and then Present (Protected_Subprogram (Subp)) + and then Ekind (Scope (Protected_Subprogram (Subp))) = E_Protected_Type + and then + Base_Type (Tagged_Type) + /= Corresponding_Record_Type (Scope (Protected_Subprogram (Subp))) + then + return Empty; + -- The dispatching type and the primitive operation must be defined in -- the same scope, except in the case of internal operations and formal -- abstract subprograms.