From patchwork Tue May 23 08:07:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 97828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1972839vqo; Tue, 23 May 2023 01:09:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4qigkuxPA7uKENczHp9V7irI7k/5cxBLvs5lOLVXQtIMaj/B7YBzF3m3CSNCI3dP9X4A4O X-Received: by 2002:aa7:d60c:0:b0:510:daee:46d1 with SMTP id c12-20020aa7d60c000000b00510daee46d1mr10593495edr.10.1684829379876; Tue, 23 May 2023 01:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684829379; cv=none; d=google.com; s=arc-20160816; b=0DMRZs0/e6GZ4YPI/CfpG7USpOGeLfXQ61v6LiCTJ4Cqd86/aunx8NOBHgJEhKJSKV yrUz4cpuw2t1D5eSQysJPLL//436i5TqIr0E4R+JMlC94cG2jfvURFsY2513GuSp771x Zrt9XrVWoZ7ALXOOXgAAVetsWoUP3egY7z7Id7pX46TyVtG93bXN3Vyf8OBmwBFvLzOO cBeVOL4HCUHj/PwQSn3HgQT+cBTH5coSDIfD8LkYtmkU0xXs48K8sbMnhAZTfDICuy5o 7BoWyoqFgY7cjaOetd85VUJCBd2n86feCTAkdn4BZNGMFuLchsP/TYq8IVPOUlVjzQp/ EPKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7RS//HH62Wz+mkOvPaNRHuGWiQR7n7TEBaQR8qCD1oI=; b=aKuUod8n+XXWSyjakVqUCrh5wGOXQUl6L5iQPqjL/MSJCVYwT10g9RoS0cmdrEWvv/ XbGyoTYJzHDK5Fanud8QZosi03sTQZXF4ErraR6/o42LUrfNpqR68SJipRlNzJoK9/Az Q5nxkv+pxo3SqOU32T2W4psMOOxJwGQH7SdS3l3Ox3lwbHZeLqLfNW0dZG3q3c97Tpzw zemwmuRlFh+BlB4RoIXYhsaGC4a5k7CdxO4oCM7bH7yTZmWcU4OSW0djkjTwcfH0chMb pLXO+i8g4pOUy+61scCf8YDjVpZarzgEBD/9zHqFhsrURGG98CJZ67YnDwCaKRhzIKbK Ee/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="SftL3P/j"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f16-20020a50ee90000000b00510b7b71b6dsi5259794edr.520.2023.05.23.01.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:09:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="SftL3P/j"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58E373882020 for ; Tue, 23 May 2023 08:08:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58E373882020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684829311; bh=7RS//HH62Wz+mkOvPaNRHuGWiQR7n7TEBaQR8qCD1oI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SftL3P/j6AQAVCcb+hEwNNEfZzPzK9Zl4olAJSx14Bv5+tS3GatnVdHuhbxyzn3AY uWB4/1FQz75Ekb4Ej0UZyWIYQiApfxHxPf7/SZPAdEPwWGzSbM44JK17z8vTNn5gQz UqAnOQiXv7D3kpXd6JIo6ZWPcwE8UBZABczMm1YU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 9B059385734F for ; Tue, 23 May 2023 08:07:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B059385734F Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-30948709b3cso3807632f8f.3 for ; Tue, 23 May 2023 01:07:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829256; x=1687421256; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7RS//HH62Wz+mkOvPaNRHuGWiQR7n7TEBaQR8qCD1oI=; b=GZrghDugJTLQwDWX8UPBHUGoziS1QmW8CMSi/lOgihjFMp6jBW0Ji8rGgGEj5/vi36 zN/Lq7GfN2vZ/CRcliYvcvnPwAEp6hyHCWEEI02Iw6zOP+Sy+OkhZY/9TCNIUNKZPBgG WH12YPxKEvpNXXMYHuF9a/rAw+tGpN0drjGjV1RFm1pasioQR8GnfYwSKAk8wzNgPOwv HK4X44LG1yXX92XEOKtwVnsCkjvRyICdX84b6G5jLIZNSqY8CAocoj8TeNA++J7qxzsq fCDlpiR+5yP1tJ27dcs+PmqmT0pCoTupmafNNuKX3j8xOeDj370NY7QH02kRGjGtzVJJ 9adw== X-Gm-Message-State: AC+VfDzSW3DU39rK3dMs7JNkCiVfoZE1+9Wjw+ptZlaNWaPlj84qUNSA pnWhJ4uPDz7EoNNLp2FW2UsJEYNXxszIslTlc5sUmg== X-Received: by 2002:adf:ed49:0:b0:309:4642:8792 with SMTP id u9-20020adfed49000000b0030946428792mr10078136wro.65.1684829256240; Tue, 23 May 2023 01:07:36 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id c6-20020a5d4f06000000b002e5f6f8fc4fsm10316506wru.100.2023.05.23.01.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:07:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Crash on dispatching primitive referencing limited-with type Date: Tue, 23 May 2023 10:07:33 +0200 Message-Id: <20230523080733.1872635-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 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, KAM_ASCII_DIVIDERS, 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766671651951187511?= X-GMAIL-MSGID: =?utf-8?q?1766671651951187511?= From: Javier Miranda The compiler crashes processing a compilation unit has limited-with context clauses, and the profile of some dispatching primitive references a type visible through a limited-with clause, and the dispatching primitive has class-wide preconditions. gcc/ada/ * sem_ch10.adb (Analyze_Required_Limited_With_Units): New subprogram. (Depends_On_Limited_Views): New subprogram. (Has_Limited_With_Clauses): New subprogram. (Analyze_Compilation_Unit): Call the new subprogram that performs the full analysis of required limited-with units. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch10.adb | 158 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/gcc/ada/sem_ch10.adb b/gcc/ada/sem_ch10.adb index 13357924e64..c9bbd773424 100644 --- a/gcc/ada/sem_ch10.adb +++ b/gcc/ada/sem_ch10.adb @@ -85,6 +85,14 @@ package body Sem_Ch10 is procedure Analyze_Context (N : Node_Id); -- Analyzes items in the context clause of compilation unit + procedure Analyze_Required_Limited_With_Units (N : Node_Id); + -- Subsidiary of Analyze_Compilation_Unit. Perform full analysis of the + -- limited-with units of N when it is a package declaration that does not + -- require a package body, and the profile of some subprogram defined in N + -- depends on shadow incomplete type entities visible through limited-with + -- context clauses. This analysis is required to provide the backend with + -- the non-limited view of these shadow entities. + procedure Build_Limited_Views (N : Node_Id); -- Build and decorate the list of shadow entities for a package mentioned -- in a limited_with clause. If the package was not previously analyzed @@ -1390,6 +1398,13 @@ package body Sem_Ch10 is -- ensure that the pragma/aspect, if present, has been analyzed. Check_No_Elab_Code_All (N); + + -- If this is a main compilation containing a package declaration that + -- requires no package body, and the profile of some subprogram depends + -- on shadow incomplete entities then perform full analysis of its + -- limited-with units. + + Analyze_Required_Limited_With_Units (N); end Analyze_Compilation_Unit; --------------------- @@ -2024,6 +2039,149 @@ package body Sem_Ch10 is end if; end Analyze_Protected_Body_Stub; + ----------------------------------------- + -- Analyze_Required_Limited_With_Units -- + ----------------------------------------- + + procedure Analyze_Required_Limited_With_Units (N : Node_Id) is + Unit_Node : constant Node_Id := Unit (N); + Spec_Id : constant Entity_Id := Defining_Entity (Unit_Node); + + function Depends_On_Limited_Views (Pkg_Id : Entity_Id) return Boolean; + -- Determines whether the given package has some subprogram with a + -- profile that depends on shadow incomplete type entities of a + -- limited-with unit. + + function Has_Limited_With_Clauses return Boolean; + -- Determines whether the compilation unit N has limited-with context + -- clauses. + + ------------------------------ + -- Has_Limited_With_Clauses -- + ------------------------------ + + function Has_Limited_With_Clauses return Boolean is + Item : Node_Id := First (Context_Items (N)); + + begin + while Present (Item) loop + if Nkind (Item) = N_With_Clause + and then Limited_Present (Item) + and then not Implicit_With (Item) + then + return True; + end if; + + Next (Item); + end loop; + + return False; + end Has_Limited_With_Clauses; + + ------------------------------ + -- Depends_On_Limited_Views -- + ------------------------------ + + function Depends_On_Limited_Views (Pkg_Id : Entity_Id) return Boolean is + + function Has_Limited_View_Types (Subp : Entity_Id) return Boolean; + -- Determines whether the type of some formal of Subp, or its return + -- type, is a shadow incomplete entity of a limited-with unit. + + ---------------------------- + -- Has_Limited_View_Types -- + ---------------------------- + + function Has_Limited_View_Types (Subp : Entity_Id) return Boolean is + Formal : Entity_Id := First_Formal (Subp); + + begin + while Present (Formal) loop + if From_Limited_With (Etype (Formal)) + and then Has_Non_Limited_View (Etype (Formal)) + and then Ekind (Non_Limited_View (Etype (Formal))) + = E_Incomplete_Type + then + return True; + end if; + + Formal := Next_Formal (Formal); + end loop; + + if Ekind (Subp) = E_Function + and then From_Limited_With (Etype (Subp)) + and then Has_Non_Limited_View (Etype (Subp)) + and then Ekind (Non_Limited_View (Etype (Subp))) + = E_Incomplete_Type + then + return True; + end if; + + return False; + end Has_Limited_View_Types; + + -- Local variables + + E : Entity_Id := First_Entity (Pkg_Id); + + begin + while Present (E) loop + if Is_Subprogram (E) + and then Has_Limited_View_Types (E) + then + return True; + + -- Recursion on nested packages skipping package renamings + + elsif Ekind (E) = E_Package + and then No (Renamed_Entity (E)) + and then Depends_On_Limited_Views (E) + then + return True; + end if; + + Next_Entity (E); + end loop; + + return False; + end Depends_On_Limited_Views; + + -- Local variables + + Item : Node_Id; + + -- Start of processing for Analyze_Required_Limited_With_Units + + begin + -- Cases where no action is required + + if not Expander_Active + or else Nkind (Unit_Node) /= N_Package_Declaration + or else Main_Unit_Entity /= Spec_Id + or else Is_Generic_Unit (Spec_Id) + or else Unit_Requires_Body (Spec_Id) + or else not Has_Limited_With_Clauses + or else not Depends_On_Limited_Views (Spec_Id) + then + return; + end if; + + -- Perform full analyis of limited-with units to provide the backend + -- with the full-view of shadow entities. + + Item := First (Context_Items (N)); + while Present (Item) loop + if Nkind (Item) = N_With_Clause + and then Limited_Present (Item) + and then not Implicit_With (Item) + then + Semantics (Library_Unit (Item)); + end if; + + Next (Item); + end loop; + end Analyze_Required_Limited_With_Units; + ---------------------------------- -- Analyze_Subprogram_Body_Stub -- ----------------------------------