From patchwork Fri Jul 9 12:38:10 2021 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: 1503099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=jOJqtlrL; dkim-atps=neutral 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 (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GLtB35PKYz9sRN for ; Fri, 9 Jul 2021 22:43:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EFF49398802D for ; Fri, 9 Jul 2021 12:43:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id B933A3AAB43B for ; Fri, 9 Jul 2021 12:38:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B933A3AAB43B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lj1-x234.google.com with SMTP id u25so7793231ljj.11 for ; Fri, 09 Jul 2021 05:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=yvG2e4jZ6/S6k93dz01Cn67Z3LzarCQzCxIsIK/NJc0=; b=jOJqtlrLshVcqO4I0ojm9sqKh7LemASOlPwj/MiNxNOUVQ1jZAOcofkLLrfAqJ+n0i qu9c+tJdTsnbV3cYRVKQbxTgYfJ1yMHZ7hLMKawOnT+Hh20/6ZIiKGj6uhcPEPYOV1VG q275oJxF8GZ3HoJFRmNAkMIur7aOVxeKKqHiZFBmin8aOp2Y84t4FScr5VLpyUEq6VX/ ifqOJU6PQqR1aQywhHVS1tV33dz6RvZDE4d5bm/JxIOboXbOEByx/QbJ8OKiXYTLD9E1 quybjKW/b0R2E4Cm3DCBVC7Ard2vQukaq9FOra5zgfi77nEo7rBKR0yy2RLkaYnweff6 1tOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=yvG2e4jZ6/S6k93dz01Cn67Z3LzarCQzCxIsIK/NJc0=; b=b0UclB9jRgfMA9naapM/j1z1N1ARpZAjlC6VLTdBoXFVsObEhfeq5jFaGemfehdS1G iGIuTNcC6gP4YVLG/oiQ3xUWG85xJ2wuPY/tHfzLxV44BX9QXU4W0g+KGWkaDPwcAiTL sP7sW4yYqHlOrJeNJ0N3Q9XSg8X00+0q9K82mxJM7E5bmY6u3lYtYkDs3YVRCzYTzNwM 0wtZ+7Waii2So/4PE86jzgNShkrtPJhxI2bmUhNs8vUcawLcIzLmZc5PF2s/8gb1fd95 6w1VFk3Pls/D1xLDjgj321uCwCZzWevz9XKQ98qgzlPo9gtAEjRQJKqLxG+QpQWYgbMO 52Jg== X-Gm-Message-State: AOAM531PXRCrlqTVCJjLRHOX5idk2sS1JxGuQYjSiykiiuNXu8oPSQXm tFx+m/r2im7dNjgl/0ltvQ6y3stn027O9A== X-Google-Smtp-Source: ABdhPJxlhrIaEa58tY726kjBe207BSvdYk6GRX+9OJuu4qvSf1iAGQG8jk7SFdBOXxZIPGVQEREuew== X-Received: by 2002:a2e:a44f:: with SMTP id v15mr28950675ljn.301.1625834291597; Fri, 09 Jul 2021 05:38:11 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id h27sm456529lfk.114.2021.07.09.05.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 05:38:10 -0700 (PDT) Date: Fri, 9 Jul 2021 12:38:10 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Incremental patch for restriction No_Dynamic_Accessibility_Checks Message-ID: <20210709123810.GA3875644@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: , Cc: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch corrects various issues discovered during testing of the No_Dynamic_Accessibility_Checks restriction leading to level miscalculation errors. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.ads (Type_Access_Level): Add new optional parameter Assoc_Ent. * sem_util.adb (Accessibility_Level): Treat access discriminants the same as components when the restriction No_Dynamic_Accessibility_Checks is enabled. (Deepest_Type_Access_Level): Remove exception for Debug_Flag_Underscore_B when returning the result of Type_Access_Level in the case where No_Dynamic_Accessibility_Checks is active. (Function_Call_Or_Allocator_Level): Correctly calculate the level of Expr based on its containing subprogram instead of using Current_Subprogram. * sem_res.adb (Valid_Conversion): Add actual for new parameter Assoc_Ent in call to Type_Access_Level, and add test of No_Dynamic_Accessibility_Checks_Enabled to ensure that static accessibility checks are performed for all anonymous access type conversions. diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -13734,11 +13734,16 @@ package body Sem_Res is -- the target type is anonymous access as well - see RM 3.10.2 -- (10.3/3). - elsif Type_Access_Level (Opnd_Type) > - Deepest_Type_Access_Level (Target_Type) - and then (Nkind (Associated_Node_For_Itype (Opnd_Type)) /= - N_Function_Specification - or else Ekind (Target_Type) in Anonymous_Access_Kind) + -- Note that when the restriction No_Dynamic_Accessibility_Checks + -- is in effect wei also want to proceed with the conversion check + -- described above. + + elsif Type_Access_Level (Opnd_Type, Assoc_Ent => Operand) + > Deepest_Type_Access_Level (Target_Type) + and then (Nkind (Associated_Node_For_Itype (Opnd_Type)) + /= N_Function_Specification + or else Ekind (Target_Type) in Anonymous_Access_Kind + or else No_Dynamic_Accessibility_Checks_Enabled (N)) -- Check we are not in a return value ??? 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 @@ -420,7 +420,7 @@ package body Sem_Util is else return Make_Level_Literal - (Subprogram_Access_Level (Current_Subprogram)); + (Subprogram_Access_Level (Entity (Name (N)))); end if; end if; @@ -791,12 +791,22 @@ package body Sem_Util is -- is an anonymous access type means that its associated -- level is that of the containing type - see RM 3.10.2 (16). + -- Note that when restriction No_Dynamic_Accessibility_Checks is + -- in effect we treat discriminant components as regular + -- components. + elsif Nkind (E) = N_Selected_Component and then Ekind (Etype (E)) = E_Anonymous_Access_Type and then Ekind (Etype (Pre)) /= E_Anonymous_Access_Type - and then not (Nkind (Selector_Name (E)) in N_Has_Entity - and then Ekind (Entity (Selector_Name (E))) - = E_Discriminant) + and then (not (Nkind (Selector_Name (E)) in N_Has_Entity + and then Ekind (Entity (Selector_Name (E))) + = E_Discriminant) + + -- The alternative accessibility models both treat + -- discriminants as regular components. + + or else (No_Dynamic_Accessibility_Checks_Enabled (E) + and then Allow_Alt_Model)) then -- When restriction No_Dynamic_Accessibility_Checks is active -- and -gnatd_b set, the level is that of the designated type. @@ -7215,7 +7225,6 @@ package body Sem_Util is if Allow_Alt_Model and then No_Dynamic_Accessibility_Checks_Enabled (Typ) - and then not Debug_Flag_Underscore_B then return Type_Access_Level (Typ, Allow_Alt_Model); end if; @@ -29157,7 +29166,8 @@ package body Sem_Util is function Type_Access_Level (Typ : Entity_Id; - Allow_Alt_Model : Boolean := True) return Uint + Allow_Alt_Model : Boolean := True; + Assoc_Ent : Entity_Id := Empty) return Uint is Btyp : Entity_Id := Base_Type (Typ); Def_Ent : Entity_Id; @@ -29187,6 +29197,18 @@ package body Sem_Util is (Designated_Type (Btyp), Allow_Alt_Model); end if; + -- When an anonymous access type's Assoc_Ent is specifiedi, + -- calculate the result based on the general accessibility + -- level routine. + + -- We would like to use Associated_Node_For_Itype here instead, + -- but in some cases it is not fine grained enough ??? + + if Present (Assoc_Ent) then + return Static_Accessibility_Level + (Assoc_Ent, Object_Decl_Level); + end if; + -- Otherwise take the context of the anonymous access type into -- account. diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -3267,12 +3267,17 @@ package Sem_Util is function Type_Access_Level (Typ : Entity_Id; - Allow_Alt_Model : Boolean := True) return Uint; + Allow_Alt_Model : Boolean := True; + Assoc_Ent : Entity_Id := Empty) return Uint; -- Return the accessibility level of Typ -- The Allow_Alt_Model parameter allows the alternative level calculation -- under the restriction No_Dynamic_Accessibility_Checks to be performed. + -- Assoc_Ent allows for the optional specification of the entity associated + -- with Typ. This gets utilized mostly for anonymous access type + -- processing, where context matters in interpreting Typ's level. + function Type_Without_Stream_Operation (T : Entity_Id; Op : TSS_Name_Type := TSS_Null) return Entity_Id;