From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 98F323857C78 for ; Wed, 20 Oct 2021 19:27:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 98F323857C78 Received: by mail-lf1-x12d.google.com with SMTP id n8so227546lfk.6 for ; Wed, 20 Oct 2021 12:27:50 -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=SuTxOICVr5V6bUwNzarfKw4Rzqqgg2aQ8OaODm99JRg=; b=NC0qoUg0QLMv10sn/OK5vorJUc3lBi91w2C5WSJdT1YyG6gQx6XJmZggWF458UxQin a98kVjxlerHz9lMTut38RRMbsPuviAff9Vb9sx1CyS9vLjSIZg5fu9tV5VAxIUm5R030 QW+mz8Q4zp7DxklqRRNuoPBsPW2z9O5F+qdEEKME7ZUvhIEo0H2s6cHcPl/U4Mj46WA0 LVowjRCCEbP3PRT/WrIEInVcdxFbkp3FEKvbZgzacfTA4r3f2G3nSTy+hHPtT4o924km DgBOSeM72sOr7Pfs6sYDw+/7fjykW5KNF0TrztpSG0L/jcpLi8rSAP1yGMxnU39bfAFH kdJQ== X-Gm-Message-State: AOAM532xOiKCa87kYYzUObRlgUIixFzrIQli7zBndFQ/bFukbPakNAIx IPhZ1pLV83riXIcZ+2wkTuflve90tLG1XFvR X-Google-Smtp-Source: ABdhPJznFxpa4qvhc8ld6C0PrFhH1KEfxw4RITZs/I2A2S5voU/3OufdqCC+CMZwU24BqdNSnk3uQQ== X-Received: by 2002:a05:6512:1304:: with SMTP id x4mr1019005lfu.591.1634758069396; Wed, 20 Oct 2021 12:27:49 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id p18sm306396ljc.114.2021.10.20.12.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 12:27:48 -0700 (PDT) Date: Wed, 20 Oct 2021 19:27:47 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Justin Squirek Subject: [Ada] Crash on object of protected type with defaulted access component Message-ID: <20211020192747.GA3154238@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="J2SCkAp4GZ/dPZZf" 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-List-Received-Date: Wed, 20 Oct 2021 19:27:52 -0000 --J2SCkAp4GZ/dPZZf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This patch corrects issues in the compiler whereby default initializing a protected type component of an access type containing controlled parts with an allocator causes a crash at compile-time at the point of an object declaration of such protected type. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch7.adb (Make_Final_Call): Detect expanded protected types and use original protected type in order to calculate appropriate finalization routine. --J2SCkAp4GZ/dPZZf Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -8953,11 +8953,12 @@ package body Exp_Ch7 is Typ : Entity_Id; Skip_Self : Boolean := False) return Node_Id is - Loc : constant Source_Ptr := Sloc (Obj_Ref); - Atyp : Entity_Id; - Fin_Id : Entity_Id := Empty; - Ref : Node_Id; - Utyp : Entity_Id; + Loc : constant Source_Ptr := Sloc (Obj_Ref); + Atyp : Entity_Id; + Prot_Typ : Entity_Id := Empty; + Fin_Id : Entity_Id := Empty; + Ref : Node_Id; + Utyp : Entity_Id; begin Ref := Obj_Ref; @@ -9035,6 +9036,19 @@ package body Exp_Ch7 is Set_Assignment_OK (Ref); end if; + -- Detect if Typ is a protected type or an expanded protected type and + -- store the relevant type within Prot_Typ for later processing. + + if Is_Protected_Type (Typ) then + Prot_Typ := Typ; + + elsif Ekind (Typ) = E_Record_Type + and then Present (Corresponding_Concurrent_Type (Typ)) + and then Is_Protected_Type (Corresponding_Concurrent_Type (Typ)) + then + Prot_Typ := Corresponding_Concurrent_Type (Typ); + end if; + -- The underlying type may not be present due to a missing full view. In -- this case freezing did not take place and there is no [Deep_]Finalize -- primitive to call. @@ -9080,7 +9094,7 @@ package body Exp_Ch7 is -- Protected types: these also require finalization even though they -- are not marked controlled explicitly. - elsif Is_Protected_Type (Typ) then + elsif Present (Prot_Typ) then -- Protected objects do not need to be finalized on restricted -- runtimes. @@ -9090,7 +9104,7 @@ package body Exp_Ch7 is -- ??? Only handle the simple case for now. Will not support a record -- or array containing protected objects. - elsif Is_Simple_Protected_Type (Typ) then + elsif Is_Simple_Protected_Type (Prot_Typ) then Fin_Id := RTE (RE_Finalize_Protection); else raise Program_Error; --J2SCkAp4GZ/dPZZf--