public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1685] [Ada] Zero-size slices
@ 2021-06-21 11:05 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-06-21 11:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:148be9292380a66a81b4dc51ef58e8d5c4d72dcc

commit r12-1685-g148be9292380a66a81b4dc51ef58e8d5c4d72dcc
Author: Bob Duff <duff@adacore.com>
Date:   Fri Mar 26 15:41:31 2021 -0400

    [Ada] Zero-size slices
    
    gcc/ada/
    
            * libgnat/s-bituti.ads (Small_Size): Do not include 0 in this
            type.
            * libgnat/s-bituti.adb (Copy_Bitfield): Do nothing for 0-bit
            bitfields.

Diff:
---
 gcc/ada/libgnat/s-bituti.adb | 11 +++++++++++
 gcc/ada/libgnat/s-bituti.ads |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/libgnat/s-bituti.adb b/gcc/ada/libgnat/s-bituti.adb
index fbb53893f0f..3e584e72bfe 100644
--- a/gcc/ada/libgnat/s-bituti.adb
+++ b/gcc/ada/libgnat/s-bituti.adb
@@ -402,11 +402,22 @@ package body System.Bitfield_Utils is
          pragma Assert (Al_Src_Address mod Val'Alignment = 0);
          pragma Assert (Al_Dest_Address mod Val'Alignment = 0);
       begin
+         --  Optimized small case
+
          if Size in Small_Size then
             Copy_Small_Bitfield
               (Al_Src_Address, Al_Src_Offset,
                Al_Dest_Address, Al_Dest_Offset,
                Size);
+
+         --  Do nothing for zero size. This is necessary to avoid doing invalid
+         --  reads, which are detected by valgrind.
+
+         elsif Size = 0 then
+            null;
+
+         --  Large case
+
          else
             Copy_Large_Bitfield
               (Al_Src_Address, Al_Src_Offset,
diff --git a/gcc/ada/libgnat/s-bituti.ads b/gcc/ada/libgnat/s-bituti.ads
index eb1662df7e9..c9c4b9184b9 100644
--- a/gcc/ada/libgnat/s-bituti.ads
+++ b/gcc/ada/libgnat/s-bituti.ads
@@ -98,9 +98,9 @@ package System.Bitfield_Utils is
       pragma Assert (Val_Array'Component_Size = Val'Size);
 
       subtype Bit_Size is Natural; -- Size in bits of a bit field
-      subtype Small_Size is Bit_Size range 0 .. Val'Size;
+      subtype Small_Size is Bit_Size range 1 .. Val'Size;
       --  Size of a small one
-      subtype Bit_Offset is Small_Size range 0 .. Val'Size - 1;
+      subtype Bit_Offset is Small_Size'Base range 0 .. Val'Size - 1;
       --  Starting offset
       subtype Bit_Offset_In_Byte is Bit_Offset range 0 .. Storage_Unit - 1;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-21 11:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 11:05 [gcc r12-1685] [Ada] Zero-size slices Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).