From patchwork Mon Jul 4 07:50:03 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: 1651815 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=TbhWPdMN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Lbydz5XcSz9s5V for ; Mon, 4 Jul 2022 17:50:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 73E9A3851147 for ; Mon, 4 Jul 2022 07:50:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73E9A3851147 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656921026; bh=8+5CG38vmidvDvzRk4caOdG07AGobpq+0SQf328FZvo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TbhWPdMNTzTxh3kQtpUhGKrQA5k9siEnwqbRdaj66Qg8li9cwhVIzDgIt9kskOioz JoO399w46eljqWAFXDK1Rr5DgIfRbqEHYGMX0YGaq21IYgmupNq3JBx8P4/tfAaw/7 caYMDJxnu/xnOxZhFlSEiB5s7++0SbKPzhja8kXk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id D353F385BAD9 for ; Mon, 4 Jul 2022 07:50:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D353F385BAD9 Received: by mail-ej1-x633.google.com with SMTP id h23so15181446ejj.12 for ; Mon, 04 Jul 2022 00:50:05 -0700 (PDT) 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=8+5CG38vmidvDvzRk4caOdG07AGobpq+0SQf328FZvo=; b=ygin4iFQdD1iN60hQC+bz5TaN1lgMMjxYrZp3CiI7fdJpVHP+jtMducRiZtmp4fUmF XcGfTZZ5Mv3rHVlGq8mzPe78a7sS/I+xKui4uUA8telU5tZB+q5wvhS7b86+i6JfPsZd RKMNms+On5ditNbnNgErmYF+XY/EqZETL3kye+m/ttMhFk9bkCHYD+eXGnaTs7HfjFyf CvaXQ/O+L4FPJ+Lq4lwrQIYuCjD9narZlnhrsIjOYGFMkuEw6/tdf/CNdAspShT1xdsC O3plf994qy1IR/+Tqqj9LV7XvUY5ayaK1mTraOCWr3khxw22nmX8fnon/Xr6TtCEwZHM b2IQ== X-Gm-Message-State: AJIora9tYmfz451Q0udAk+HeL+jwVQ3gfjWiqq3q2cbavBlpH7Q7sNRi /H+hLH+6TIYDrpXz6jjZmHC7EMsnwsbvKw== X-Google-Smtp-Source: AGRyM1siDCejvfVVd3d9fvAZCsbv1Mwoy/bsdSxBSJX/d/NweV1dOPprPQISIj466cbBWJ4hBetULg== X-Received: by 2002:a17:907:1623:b0:722:ef86:e25c with SMTP id hb35-20020a170907162300b00722ef86e25cmr27853084ejc.461.1656921004580; Mon, 04 Jul 2022 00:50:04 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id k27-20020a17090632db00b0072ab06bc3b5sm2358516ejk.34.2022.07.04.00.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 00:50:04 -0700 (PDT) Date: Mon, 4 Jul 2022 07:50:03 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Incorrect accessibility check on return of discriminated type Message-ID: <20220704075003.GA98978@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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch corrects an error in the compiler whereby the presence of a call to a function returning a type with an access discriminant within an expanded loop condition caused the wrong value to be supplied for the extra- accessibility-of-result actual, thus causing incorrect checks within the callee at the point of return. This change also corrects a problem where spurious "null value not allowed" warnings were generated for tagged type declarations with an access discriminant specified as "null." Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_disp.adb (Most_Descendant_Use_Clause): Remove call to deprecated Is_Internal. * sem_util.adb (Innermost_Master_Scope_Depth): Use Find_Enclosing_Scope instead of Nearest_Dynamic_Scope to avoid cases where relevant scopes get skipped leading to an incorrect scope depth calculation. 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 @@ -508,12 +508,11 @@ package body Sem_Disp is 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. + -- the same scope, except in the case of abstract formal subprograms. - elsif ((Scope (Subp) = Scope (Tagged_Type) or else Is_Internal (Subp)) - and then (not Is_Generic_Type (Tagged_Type) - or else not Comes_From_Source (Subp))) + elsif (Scope (Subp) = Scope (Tagged_Type) + and then (not Is_Generic_Type (Tagged_Type) + or else not Comes_From_Source (Subp))) or else (Is_Formal_Subprogram (Subp) and then Is_Abstract_Subprogram (Subp)) or else diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -275,9 +275,9 @@ package body Sem_Util is -- with its type set to Natural. function Innermost_Master_Scope_Depth (N : Node_Id) return Uint; - -- Returns the scope depth of the given node's innermost - -- enclosing dynamic scope (effectively the accessibility - -- level of the innermost enclosing master). + -- Returns the scope depth of the given node's innermost enclosing + -- scope (effectively the accessibility level of the innermost + -- enclosing master). function Function_Call_Or_Allocator_Level (N : Node_Id) return Node_Id; -- Centralized processing of subprogram calls which may appear in @@ -301,7 +301,7 @@ package body Sem_Util is begin -- Locate the nearest enclosing node (by traversing Parents) -- that Defining_Entity can be applied to, and return the - -- depth of that entity's nearest enclosing dynamic scope. + -- depth of that entity's nearest enclosing scope. -- The rules that define what a master are defined in -- RM 7.6.1 (3), and include statements and conditions for loops @@ -311,13 +311,13 @@ package body Sem_Util is Ent := Defining_Entity_Or_Empty (Node_Par); if Present (Ent) then - Encl_Scop := Nearest_Dynamic_Scope (Ent); + Encl_Scop := Find_Enclosing_Scope (Ent); -- Ignore transient scopes made during expansion if Comes_From_Source (Node_Par) then return - Scope_Depth_Default_0 (Encl_Scop) + Master_Lvl_Modifier; + Scope_Depth (Encl_Scop) + Master_Lvl_Modifier; end if; -- For a return statement within a function, return