From patchwork Thu Jul 8 13:50:06 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: 1502271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=tDv/FxpN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4GLHp92YFVz9sRf for ; Thu, 8 Jul 2021 23:54:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7044F398D043 for ; Thu, 8 Jul 2021 13:54:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 83DED398B89B for ; Thu, 8 Jul 2021 13:50:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83DED398B89B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-lf1-x135.google.com with SMTP id p16so15849396lfc.5 for ; Thu, 08 Jul 2021 06:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=MuN4AaedI/1tlMLrjBq/RgSO+ZEqmCo61/p/JsDZ7Xw=; b=tDv/FxpNpj4C47kRwaZvN8+j59/LGG0549r6ePn8k9uK4b1KbHOXTQP9gAL/We6dpK dy93KqYMZJjIH55kUjY7pK2EPR3g9os4jUy0YjN7gKZZWRE+Nc0Vhow3+eIwKCmyFnAm LvNNvKkfM0zA1A8HWhK0EPE/Zeb16fLfXgXoBW6wLnq4jtLa54pKvEhLh6AHzRDB7GYK ISYYu3gUwQtrY5231YaM8PaxKKnPbqZsT6OkbubhUdnlL/F3lg/PMKUGQSYQdfN/SD0L vkMzAZ3hhaXtcfwCxa3f2OJv5fVZJAmWAbXinZ6eAUkqTdfj7nsi/IV4CeK0z9PZ+9Mp LfcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=MuN4AaedI/1tlMLrjBq/RgSO+ZEqmCo61/p/JsDZ7Xw=; b=ZStUez4KD27w5r0SbPzw/+KACOOGHRThobqdRuOV+R19pQ2//9vgAXlfvsRt73bkJa uQuPHdfCULPGE+vEzGS1pOL34/RgjGwnQ5C62ROJ16BinDPm5C4/cws08p+2QN2y8QkT ekTF9eyMXUbmFT7DZLv4773tHG9+QzcoM4jFd2ojnvzXYwJodGBC6XlE3vgIE4AJKLSq 9HRFA5GDoHPsboY5GNo3sJB+aCw7ZCvv6o0WNBDD7ufeqvbNxnCKyCb7Sdh+7Ij7j2+S GhRusJkdVc3UrwWCFk+kiFfrCdicPi4YychS+m9qSensFfgo0F3eqo2U3cqgNYaYE9Yo GDPQ== X-Gm-Message-State: AOAM530JBPccWUcJhmL+4qYRiVcSepw0zw1YdkRTaUNBFdcnk/cSsUqE kj+gOoUJTd5ncykF8AceJhjtKjJppkRWsw== X-Google-Smtp-Source: ABdhPJxpHs7jZP0ecXTj2CX3DBEoIZIwzjF2vDCt1XXvJVKq47eKR+MI83JnaQ7W1h1J+RvIACatow== X-Received: by 2002:a2e:80d2:: with SMTP id r18mr3404710ljg.131.1625752208413; Thu, 08 Jul 2021 06:50:08 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id i23sm201684lfv.142.2021.07.08.06.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 06:50:07 -0700 (PDT) Date: Thu, 8 Jul 2021 13:50:06 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Compute sizes when possible for packed array with Component_Size Message-ID: <20210708135006.GA2465620@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: , Cc: Yannick Moy Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" For a packed constrained array type with a Component_Size clause, it may be possible to compute both its RM_Size and Esize. Do this as it benefits GNATprove for checking validity of overlays. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * layout.adb (Layout_Type): Special case when RM_Size and Esize can be computed for packed arrays. diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb --- a/gcc/ada/layout.adb +++ b/gcc/ada/layout.adb @@ -487,6 +487,48 @@ package body Layout is then Set_Alignment (E, Alignment (Component_Type (E))); end if; + + -- If packing was requested, the one-dimensional array is constrained + -- with static bounds, the component size was set explicitly, and + -- the alignment is known, we can set (if not set explicitly) the + -- RM_Size and the Esize of the array type, as RM_Size is equal to + -- (arr'length * arr'component_size) and Esize is the same value + -- rounded to the next multiple of arr'alignment. This is not + -- applicable to packed arrays that are implemented specially + -- in GNAT, i.e. when Packed_Array_Impl_Type is set. + + if Is_Array_Type (E) + and then Number_Dimensions (E) = 1 + and then not Present (Packed_Array_Impl_Type (E)) + and then Has_Pragma_Pack (E) + and then Is_Constrained (E) + and then Compile_Time_Known_Bounds (E) + and then Known_Component_Size (E) + and then Known_Alignment (E) + then + declare + Abits : constant Int := UI_To_Int (Alignment (E)) * SSU; + Lo, Hi : Node_Id; + Siz : Uint; + + begin + Get_Index_Bounds (First_Index (E), Lo, Hi); + Siz := (Expr_Value (Hi) - Expr_Value (Lo) + 1) + * Component_Size (E); + + -- Do not overwrite a different value of 'Size specified + -- explicitly by the user. In that case, also do not set Esize. + + if Unknown_RM_Size (E) or else RM_Size (E) = Siz then + Set_RM_Size (E, Siz); + + if Unknown_Esize (E) then + Siz := ((Siz + (Abits - 1)) / Abits) * Abits; + Set_Esize (E, Siz); + end if; + end if; + end; + end if; end if; -- Even if the backend performs the layout, we still do a little in