From patchwork Tue Nov 8 08:44:00 2022 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: 16955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2575940wru; Tue, 8 Nov 2022 00:59:36 -0800 (PST) X-Google-Smtp-Source: AMsMyM6C90YGx5lRoE9jR5JhHcpDD4W+W4lPS5lFAbumohBZtIr/7tNPQiyhs9rSWO3Hmoi8A6KM X-Received: by 2002:a17:907:6e0d:b0:7ae:2277:9fc9 with SMTP id sd13-20020a1709076e0d00b007ae22779fc9mr23536012ejc.334.1667897976737; Tue, 08 Nov 2022 00:59:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667897976; cv=none; d=google.com; s=arc-20160816; b=hehIYpVJbSEnKC/NGeQsGKsslKDMIvHQkPNICMTnNp5/reYvoR74VMuWDRgU+U7dHl Gd1lWXw+NdtJrFygrFPYbrfBsgdylo2nRvAz2FpweCcAH3lRvHGdwnyJ0m49f+gpwPXZ QCYjSv8QblgwuWbF8TOj4fC6Ef60wYZWI23dmVDq0uFm273B2QDFG0QZegdhMJcobZka tB0l8wYZZyJMkyeXgyIHao5VXbO7oc8kRoGtfN2L237cg9bw0XsTnKn9gUe2nvXmre7L UNgq9S86qy9qLOWchVckCqe3dDkkigBk8IG29TpJj7VXn5rYNoV42og1fEsGQCYymTSM nARw== 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=NxABMzgiER8Gdek6L1aNZtWMZx+iDJwY5L7wNosL1Co=; b=vehqldI6Ezt7xylo5CxQmwuOIPRUDDDKR00qONKVoG2gzSZTJ1S4tMXyCn9murJ0xy ddED9vNWFD7NAyxfbTPMmBibMef6XZ/o5h2sZsqR2QJJo4iGnqbS+RXsMbo75MKycd4y yAEIVUEXCNbVRdbAvBw0fFdsSc31nb0fHsZMfqrpSZoWL31tvksqN46+SxncProd+u05 Z8KvhhZaxG86/IDz+miB8yqZrRG/VlA2oOOpu0n32qJPpik7gW2YJZBJ2xni/9KGkBjq 0Z/wKVY9ZFQ0JyMf+IfqqjBdIFN35942y9NOXdV/ONPe1+XSPsKI19fqw0uruv3/oR7b vvYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PPmnHWap; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jg26-20020a170907971a00b0079d5da30399si12406482ejc.427.2022.11.08.00.59.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:59:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=PPmnHWap; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 21FF7393A412 for ; Tue, 8 Nov 2022 08:53:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 21FF7393A412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667897618; bh=NxABMzgiER8Gdek6L1aNZtWMZx+iDJwY5L7wNosL1Co=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=PPmnHWap7P+KkRRRwo7iCxjhfqt1GFhiCkEvyg10pCOBk9168C7UXN3ddqla4QzNx qtrxBdtfGOhSfh8TCP8c221h9+l++daFXPg17kSgT+uOjYJWUvDvK37HSPxl2/Try8 kdD5kh1Ji6DQsUjG9TeUiKhPkEFCNkFxftQHB5Us= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 2DE403858298 for ; Tue, 8 Nov 2022 08:44:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2DE403858298 Received: by mail-wr1-x430.google.com with SMTP id w14so19775185wru.8 for ; Tue, 08 Nov 2022 00:44:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NxABMzgiER8Gdek6L1aNZtWMZx+iDJwY5L7wNosL1Co=; b=U7daPipZcAW8blCKGRec6lC2re2B2trm1hGlg36Jz7BZbYL192Bb7KvfOZJoaFkXyK xfeN5rIjFWl9jGcy7BY9kSCpj8X9an1IbZVZ5f3hlJbVDJIJiAZrQ0l/dMiU5W5PxqIT G7Rp/cO2jG72SmVxrNHfgeU8PvSVuT3VPYc77YG2k4s+ZP7grWTOQs2sUFs6pJ2f5i1R FrbYnrzhgVmz/xEUWZiTGSGJA7oD14K/pRW1wGe4Sc8LSa+c4+sfyhL14v+X6MjHfZXK MU+7xmrn2sS3Gir/Bx3eKSbAAgCs+dIDPlQKM+O3B7kAaAEVaslC9q4IwK6ySHafkuV3 kFig== X-Gm-Message-State: ACrzQf3noYZ7LdulTyInJ6Cev26QWd/Cn+535/56IiwVHT27XCAC83JT G4bPnaeS+KjJ+obayAVmIXUafGSQl/ggQQ== X-Received: by 2002:adf:f092:0:b0:236:6753:cc3a with SMTP id n18-20020adff092000000b002366753cc3amr35085539wro.62.1667897044085; Tue, 08 Nov 2022 00:44:04 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id t188-20020a1c46c5000000b003cfa622a18asm7162190wma.3.2022.11.08.00.44.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:44:03 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix oversight in implementation of allocators for storage models Date: Tue, 8 Nov 2022 09:44:00 +0100 Message-Id: <20221108084400.302294-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 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.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?1748917788844047862?= X-GMAIL-MSGID: =?utf-8?q?1748917788844047862?= From: Eric Botcazou When the allocator is of an unconstrained array type and has an initializing expression, the copy of the initializing expression must be done separately from that of the bounds. gcc/ada/ * gcc-interface/utils2.cc (build_allocator): For unconstrained array types with a storage model and an initializing expression, copy the initialization expression separately from the bounds. In all cases with a storage model, pass the locally computed size for the store. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/utils2.cc | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc index ef81f8dd56a..80d550c91e1 100644 --- a/gcc/ada/gcc-interface/utils2.cc +++ b/gcc/ada/gcc-interface/utils2.cc @@ -2439,8 +2439,8 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc, tree storage_ptr_type = build_pointer_type (storage_type); tree lhs, rhs; - size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (storage_type), - init); + size = TYPE_SIZE_UNIT (storage_type); + size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, init); /* If the size overflows, pass -1 so Storage_Error will be raised. */ if (TREE_CODE (size) == INTEGER_CST && !valid_constant_size_p (size)) @@ -2454,8 +2454,10 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc, /* If there is an initializing expression, then make a constructor for the entire object including the bounds and copy it into the object. - If there is no initializing expression, just set the bounds. */ - if (init) + If there is no initializing expression, just set the bounds. Note + that, if we have a storage model, we need to copy the initializing + expression separately from the bounds. */ + if (init && !pool_is_storage_model) { vec *v; vec_alloc (v, 2); @@ -2472,11 +2474,28 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc, { lhs = build_component_ref (storage_deref, TYPE_FIELDS (storage_type), false); - rhs = build_template (template_type, type, NULL_TREE); + rhs = build_template (template_type, type, init); } if (pool_is_storage_model) - storage_init = build_storage_model_store (gnat_pool, lhs, rhs); + { + storage_init = build_storage_model_store (gnat_pool, lhs, rhs); + if (init) + { + start_stmt_group (); + add_stmt (storage_init); + lhs + = build_component_ref (storage_deref, + DECL_CHAIN (TYPE_FIELDS (storage_type)), + false); + rhs = init; + size = TYPE_SIZE_UNIT (TREE_TYPE (lhs)); + size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, init); + tree t = build_storage_model_store (gnat_pool, lhs, rhs, size); + add_stmt (t); + storage_init = end_stmt_group (); + } + } else storage_init = build_binary_op (INIT_EXPR, NULL_TREE, lhs, rhs); @@ -2520,7 +2539,7 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc, TREE_THIS_NOTRAP (storage_deref) = 1; if (pool_is_storage_model) storage_init - = build_storage_model_store (gnat_pool, storage_deref, init); + = build_storage_model_store (gnat_pool, storage_deref, init, size); else storage_init = build_binary_op (INIT_EXPR, NULL_TREE, storage_deref, init);