From patchwork Thu Jul 6 11:38:05 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: 116635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp2493991vqx; Thu, 6 Jul 2023 04:40:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlEx6c2Lzja8tq8SojO3p0oBTHdCZzSc1FAXUhicrotE6pt6IPuhwsNlsIsgU09F3c96pn92 X-Received: by 2002:a2e:9188:0:b0:2b6:cdfb:fe36 with SMTP id f8-20020a2e9188000000b002b6cdfbfe36mr1656528ljg.39.1688643626728; Thu, 06 Jul 2023 04:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688643626; cv=none; d=google.com; s=arc-20160816; b=DyHP4gVrq/20z5TtQZHlBvaGgt6fQYCrOExJKjdE32UXVqKsdJnXRO3msxfotqjSjv M18JRe4+QzatWLdqgaDsxqpAJsojdOQJ/z6DK0aIwAnMgX3TeznfgYmeiGFHKL4AMa8h pKsrG0KaaaE/kQ4agy/FqLeXRoLR/BUd45Z+qwFSY9Hjcun1PB5btq0Lo6CEvs4uphbm NNTDbqSJLdbV9v3lqKYsbc5Pf2s0yWv1NhyYNk3O1YWJAenEVgR0ELxLDLrrEbHaKFu4 VOEjZUvsv8Fv4JWXQokinm87wd1eGF/OaBsjrS0c6aU/fAs9a1hXhR2wqeGZsdUp+kDu B4GA== 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=rysL2/bGN1qKaWB0Ad7/SI8xkBT64ON9V9AHnQn4f1c=; fh=ojS6XItmEm4a6vr30sEw2RcMKF1GS+W4ZCiXypR22Bw=; b=UyA5t+aixeilWFODxdPPYehZ7EMp79QaeAcb4W9621P2nIViGxriWPy6nh6BBbKZMz cD4bL/wFnHWYz0Bt53Bnko4R1dT9nAaj2AR1RaMKlFn5Hssk+uy/VRWpjADlhaTJQMaS jsjkg88H9bDmO2acGYSqt34ZLDuWMBBHsnR4u+K2CP/LU2ebPHNHbjNhWOUY95T/jdR1 vYVwM0Rz3ek4si5gHBuOGwbOWTcsuDBDr9qGOWwXlBkGW0nUHHvSU07H7y13H1I4eBMI kk6f2x3OWohlFP+mZksp03yC4pXAprYCgwCammsl7O2tZquaiI6T+QdtbRjFJ6F2CsN9 d4bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Xq/ejowO"; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g9-20020aa7d1c9000000b0051db0cb645esi699180edp.523.2023.07.06.04.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 04:40:26 -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="Xq/ejowO"; 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 3C57D38555A9 for ; Thu, 6 Jul 2023 11:39:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C57D38555A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688643581; bh=rysL2/bGN1qKaWB0Ad7/SI8xkBT64ON9V9AHnQn4f1c=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Xq/ejowOMSRlHEMAzeDJrsCj5gPX4BIIkyw62OAFcJAfyXjQImDhDies56ACUsNCM Tee//XkigWa778YQRPmNMMV6PfQEK8e6I9KV/LahUH1rkNP2zsw9F9DPsE/ixOkZfi 5xJj4p/QTWNJRfS833I3AvlpC3kgk8GVSaa/96pE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 8A7293858D33 for ; Thu, 6 Jul 2023 11:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A7293858D33 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4fb41682472so683435e87.2 for ; Thu, 06 Jul 2023 04:38:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688643533; x=1691235533; 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=rysL2/bGN1qKaWB0Ad7/SI8xkBT64ON9V9AHnQn4f1c=; b=g1wLXWwXHMZ1ly8NSotzKE6Ncfc29ryB/LoYVE/0pydnWn+vdQGPOzFhcwZKVB2Rqz PF8x9L1SXZfcs8vsUvcmarqmOf7vQ+XtkIWBk/yPSL1fD2KaC+gJ03T9Vkb2xE/SS/8g TIC+oOGMWStzVxbolI5+0fFFG3Jhx03lxBPLjaz0sgzQvVpKf7jp/a7iRSL4RAUGRZsx JX48C4KkYgr4149kPltjJ/sIjSSvuyWG3H/RKAZz36bTftlWnL4KxM5+Km6BatZQwYbP 0gKH0dCsd2gEeE19osjEI7x+9YxhOJmI9nB7WDulMbCenTeXCETtMWATB9PZVwj7f9WT Himw== X-Gm-Message-State: ABy/qLa2kzK5YYTTHgLD9iV0gXwXOICOV4h9nRJPu3PLZ0uEZzs4nga7 oJj9G2cgE5JC9Xia4LS1Rs30mcJy+gFvOFAvDHycEA== X-Received: by 2002:a19:7113:0:b0:4f9:567a:7a59 with SMTP id m19-20020a197113000000b004f9567a7a59mr1662374lfc.30.1688643532668; Thu, 06 Jul 2023 04:38:52 -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 p3-20020a1c7403000000b003fbb1bf7e0fsm1846466wmc.35.2023.07.06.04.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 04:38:51 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Finalization not performed for component of protected type Date: Thu, 6 Jul 2023 13:38:05 +0200 Message-Id: <20230706113805.1765789-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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: =?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?1770671179612264568?= X-GMAIL-MSGID: =?utf-8?q?1770671179612264568?= From: Steve Baird In some cases involving a discriminated protected type with an array component that is subject to a discriminant-dependent index constraint, where the element type of the array requires finalization and the array type has not yet been frozen at the point of the declaration of the protected type, finalization of an object of the protected type may incorrectly omit finalization of the array component. One case where this scenario can arise is an instantiation of Ada.Containers.Bounded_Synchronized_Queues, passing in an Element type that requires finalization. gcc/ada/ * exp_ch7.adb (Make_Final_Call): Add assertion that if no finalization call is generated, then the type of the object being finalized does not require finalization. * freeze.adb (Freeze_Entity): If freezing an already-frozen subtype, do not assume that nothing needs to be done. In the case of a frozen subtype of a non-frozen type or subtype (which is possible), freeze the non-frozen entity. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch7.adb | 2 ++ gcc/ada/freeze.adb | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index 1b16839ddf3..aa16c707887 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -8387,6 +8387,8 @@ package body Exp_Ch7 is Param => Ref, Skip_Self => Skip_Self); else + pragma Assert (Serious_Errors_Detected > 0 + or else not Has_Controlled_Component (Utyp)); return Empty; end if; end Make_Final_Call; diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 83ce0300871..38aeb2456ff 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -6188,7 +6188,20 @@ package body Freeze is -- Do not freeze if already frozen since we only need one freeze node if Is_Frozen (E) then - Result := No_List; + + if Is_Itype (E) + and then not Is_Base_Type (E) + and then not Is_Frozen (Etype (E)) + then + -- If a frozen subtype of an unfrozen type seems impossible + -- then see Analyze_Protected_Definition.Undelay_Itypes. + + Result := Freeze_Entity + (Etype (E), N, Do_Freeze_Profile => Do_Freeze_Profile); + else + Result := No_List; + end if; + goto Leave; -- Do not freeze if we are preanalyzing without freezing