From patchwork Thu Sep 11 09:18:43 2025 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: 120037 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1B503858C2C for ; Thu, 11 Sep 2025 09:29:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 868CF3858C78 for ; Thu, 11 Sep 2025 09:19:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 868CF3858C78 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 868CF3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582365; cv=none; b=fO3bUX6hgHwHRaqrc/8VbeDNrw5KTDJzd2AO+Kx2q7lmNSeYHNumu298NutEE+A0Dw8Aj+kXl9e3OrEQXh/K1MeodyJ4cUmL2raisVkxMQHbFe8Si4TZZJPi636E3g3mVPmeX88dqjvV61x8TzOocqkrZSEflZPPQ3zadVGinoc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582365; c=relaxed/simple; bh=ehmJerw/pR0/S90ooch7KjxpWvik/aPU8jtns7ipbTE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XV2TXRsbc8Atg+RTChnUW4bCkiEK5AbJyCdKH+nWLeGYYuKgRwaFBuxqm8Dtrz34uoVR3jKILzr52oQatEXT5mt0Ikmkx+l1ohFyMWStc0xEbb8qP815JFvcx9LGTlSjCG/D3M/YhHGkxonp/y9sCuTNYL2pnyqMgEFsQKO/FCQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 868CF3858C78 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=jckHPaVB Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3e75fb6b2e2so545915f8f.3 for ; Thu, 11 Sep 2025 02:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582364; x=1758187164; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UbFrMCuJxttHX8fTcEqnHF3fl01hc5kcypQDs//7+5A=; b=jckHPaVBsudQaQn4EX5ZNSGa8rBs3d6VnkKrV1hBRkNz00Wrh/oB2Nj29YyxceC7s0 cdIWNaxQMg64OAIF0E1DLH9FgltyKpfISSsal8O2HzcvGOhYtC5804O4y2CUJu+PDzUS ouZKclJUVOkxesLz+y0LKDP967TY6v52442HctFg241jOtrSpMNIVaNsL+lwkgv1Ex4h 1WUtpNdoEOn4tjBR3zxTtvo3rZvFD1SvsCQKvICNIEhRrhrD9VagTF1uE8nCZNml5GPU R6J2OQ2FafhJFvhOpbayIRJjPkBvmKlDm6fXi+Z3MH+noifg2jUluvQE6t1MbWNdS1+d eMkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582364; x=1758187164; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UbFrMCuJxttHX8fTcEqnHF3fl01hc5kcypQDs//7+5A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fT8txsibuw== X-Received: by 2002:a05:6000:2c05:b0:3de:293c:9377 with SMTP id ffacd0b85a97d-3e64ca76b1fmr15995284f8f.63.1757582364127; Thu, 11 Sep 2025 02:19:24 -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 ffacd0b85a97d-3e7607cd27dsm1649971f8f.41.2025.09.11.02.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:23 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED 11/31] ada: Allow implicit packing of arrays when larger than needed Date: Thu, 11 Sep 2025 11:18:43 +0200 Message-ID: <20250911091904.1505690-11-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911091904.1505690-1-poulhies@adacore.com> References: <20250911091904.1505690-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Bob Duff For Implicit_Packing, do not require the Size clause to exactly match the packed size. For example, an array of 7 Booleans will fit in 7 bits if packed, or 7*8=56 bits if not packed. This patch allows "for T'Size use 8;" to force packing in Implicit_Packing mode; previously, the compiler ignored Implicit_Packing unless it was exactly "use 7". Apparently, customers have that sort of code, and the whole point of Implicit_Packing is to allow such legacy code to work. We already do the right thing for records, at least in cases tested. We deliberately avoid changing the error messages given here. They could possibly use some work, but there are subtle interactions with the messages given in Sem_Ch13 for the same thing. gcc/ada/ChangeLog: * freeze.adb (Freeze_Entity): Change "=" to ">=" in size comparison for Implicit_Packing mode. Keep it as "=" for giving error messages. * opt.ads (Implicit_Packing): Minor: correct obsolete comment. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 43 +++++++++++++++++++++---------------------- gcc/ada/opt.ads | 6 +++--- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 8fa25b3d8510..1bbc24f62fe2 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -7151,31 +7151,30 @@ package body Freeze is Next_Index (Indx); end loop; - -- What we are looking for here is the situation where - -- the RM_Size given would be exactly right if there was - -- a pragma Pack, resulting in the component size being - -- the RM_Size of the component type. + -- In Implicit_Packing mode, if the specified RM_Size + -- would be big enough if there were a pragma Pack, + -- then set the component size as if there were Pack, + -- and Freeze_Array_Type will do the rest. - if RM_Size (E) = Num_Elmts * Rsiz then + if Implicit_Packing + and then RM_Size (E) >= Num_Elmts * Rsiz + then + Set_Component_Size (Btyp, Rsiz); - -- For implicit packing mode, just set the component - -- size and Freeze_Array_Type will do the rest. + -- Otherwise, if pragma Pack would result in exactly the + -- right size, give an error message suggesting packing, + -- except that if the specified Size is zero, there is no + -- need for pragma Pack. Note that size zero is not + -- considered Addressable. - if Implicit_Packing then - Set_Component_Size (Btyp, Rsiz); - - -- Otherwise give an error message, except that if the - -- specified Size is zero, there is no need for pragma - -- Pack. Note that size zero is not considered - -- Addressable. - - elsif RM_Size (E) /= Uint_0 then - Error_Msg_NE - ("size given for& too small", SZ, E); - Error_Msg_N -- CODEFIX - ("\use explicit pragma Pack or use pragma " - & "Implicit_Packing", SZ); - end if; + elsif RM_Size (E) = Num_Elmts * Rsiz + and then RM_Size (E) /= Uint_0 + then + Error_Msg_NE + ("size given for& too small", SZ, E); + Error_Msg_N -- CODEFIX + ("\use explicit pragma Pack or use pragma " + & "Implicit_Packing", SZ); end if; end if; end; diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads index 524a823bb8f6..109d28245de9 100644 --- a/gcc/ada/opt.ads +++ b/gcc/ada/opt.ads @@ -835,9 +835,9 @@ package Opt is Implicit_Packing : Boolean := False; -- GNAT - -- If set True, then a Size attribute clause on an array is allowed to - -- cause implicit packing instead of generating an error message. Set by - -- use of pragma Implicit_Packing. + -- If set True, then a Size attribute clause on an array or record is + -- allowed to cause implicit packing instead of generating an error + -- message. Set by use of pragma Implicit_Packing. Init_Or_Norm_Scalars : Boolean := False; -- GNAT, GNATBIND