From patchwork Mon Oct 4 08:47:45 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: 1535998 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=EMAmbv0W; 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 (ip-8-43-85-97.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 4HNF244qyNz9t25 for ; Mon, 4 Oct 2021 19:56:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 667CF3858423 for ; Mon, 4 Oct 2021 08:56:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 667CF3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633337786; bh=99VbUVlG8ZdxthcdKWic9K2EI9nn7cxtX539MdarhF8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=EMAmbv0WT3F4pJ2bwP5NOcf9Q1+W3ipRqLgyEWK25lf5FdmrzfKYbvE5i2F84ukoJ bmdaddsaTzH09pFWw87pbIiAK2Jida0T4fHtqSwYrbW+c8X9eA8AR7pIwyVmvEB4ke xMxsf4oUUvwwLi7rWICwlFGh8IbPJ+AsUX6V/K5E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 038D53858432 for ; Mon, 4 Oct 2021 08:47:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 038D53858432 Received: by mail-lf1-x12b.google.com with SMTP id y15so2665638lfk.7 for ; Mon, 04 Oct 2021 01:47:48 -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=99VbUVlG8ZdxthcdKWic9K2EI9nn7cxtX539MdarhF8=; b=zJ0fRjqbUZszjeYV2TmW8++d1x0+vLT3tO0Mxe1kWBuHAaVAvnmPCIqji0km5Vff38 c2GiqMlZKcThiOIwO284c3oD4mc3ackU3buZXF/UHu30uxGDMoS94I2RsyzFVc17QyLo fMpF47uhGma0ZpaQ/QQCj/OOfDA2eZRNgMGVv+a2aL3qz1YLfjJULJDFPL/O5M0BTej0 54oWrFuI9uaY7b8rkX/7p1O3OEq8n3urEkCxSBgrnZheGf/quXzt0fFEDmU5UM1e8J+Q GOSIG3esbzUEpPRtT4N+lD/4Gn281cw+ADx6RCil1Aj2Ty6EIwK3uxNnhHip9f4OMPJ3 qpRw== X-Gm-Message-State: AOAM53032ZsDckAHmubfz6w95vZy/H55CSsNkxZ9wU0u+tvaT47oDGKw Akv+sp0ilNTlFcL+1blJqFU2y9kiHgvFbA== X-Google-Smtp-Source: ABdhPJwxIJItj43bZyoMrUI4QUbV4W3dpusL9CA46o3/iaxAAIyA414UYAW1YElygtbcjAbP2v106A== X-Received: by 2002:a2e:760d:: with SMTP id r13mr15288722ljc.271.1633337267881; Mon, 04 Oct 2021 01:47:47 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id n7sm1541393lft.309.2021.10.04.01.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 01:47:47 -0700 (PDT) Date: Mon, 4 Oct 2021 08:47:45 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Spurious non-variable error on implicitly dereferenced in-mode formal Message-ID: <20211004084745.GA1536629@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, 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: Justin Squirek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch corrects an issue in the compiler whereby taking 'Access of a protected subprogram based on an implicitly dereferenced protected object causes a spurious non-variable error when such an object is an in-mode access type formal. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Is_Variable): Add check for implicitly dereferenced access types (Is_Dependent_Component_Of_Mutable_Object): Set Prefix_Type when not specified. 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 @@ -16868,6 +16868,15 @@ package body Sem_Util is end if; if Is_Entity_Name (P) then + -- The Etype may not be set on P (which is wrong) in certain + -- corner cases involving the deprecated front-end inlining of + -- subprograms (via -gnatN), so use the Etype set on the + -- the entity for these instances since we know it is present. + + if No (Prefix_Type) then + Prefix_Type := Etype (Entity (P)); + end if; + if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then Prefix_Type := Base_Type (Prefix_Type); end if; @@ -21145,6 +21154,9 @@ package body Sem_Util is -- Is_Variable -- ----------------- + -- Should Is_Variable be refactored to better handle dereferences and + -- technical debt ??? + function Is_Variable (N : Node_Id; Use_Original_Node : Boolean := True) return Boolean @@ -21313,6 +21325,10 @@ package body Sem_Util is and then Nkind (Parent (E)) /= N_Exception_Handler) or else (K = E_Component and then not In_Protected_Function (E)) + or else (Present (Etype (E)) + and then Is_Access_Object_Type (Etype (E)) + and then Is_Access_Variable (Etype (E)) + and then Is_Dereferenced (N)) or else K = E_Out_Parameter or else K = E_In_Out_Parameter or else K = E_Generic_In_Out_Parameter