This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] About bitpacked arrays
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 7 Mar 2008 19:41:25 +0100
- Subject: [Ada] About bitpacked arrays
Bitpacked arrays are given "ceil" alignment for their size because they are
implemented by means of integral types. For example:
package P is
type Packed_Type is array (Integer range 1 .. 36) of Boolean;
pragma Pack (Packed_Type);
end P;
Representation information for unit P (spec)
--------------------------------------------
for Packed_Type'Object_Size use 64;
for Packed_Type'Value_Size use 36;
for Packed_Type'Alignment use 8;
for Packed_Type'Component_Size use 1;
This makes it possible to manipulate them efficiently and to overlay them on
an integer. We investigated whether we could nevertheless downgrade their
alignment with an option, but eventually settled on the status quo.
Tested on i586-suse-linux, applied on the mainline.
2008-03-07 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (gnat_to_gnu_entity) <E_Modular_Integer_Subtype>: Add
comment for the packed array type case.
* utils.c (build_template): Use a loop to strip padding or
containing records for justified modular types.
--
Eric Botcazou
Index: decl.c
===================================================================
--- decl.c (revision 133012)
+++ decl.c (working copy)
@@ -1493,6 +1493,11 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
= UI_To_gnu (RM_Size (gnat_entity), bitsizetype);
gnu_type = make_node (RECORD_TYPE);
TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "JM");
+
+ /* Propagate the alignment of the modular type to the record.
+ This means that bitpacked arrays have "ceil" alignment for
+ their size, which may seem counter-intuitive but makes it
+ possible to easily overlay them on modular types. */
TYPE_ALIGN (gnu_type) = TYPE_ALIGN (gnu_field_type);
TYPE_USER_ALIGN (gnu_type) = TYPE_USER_ALIGN (gnu_field_type);
TYPE_PACKED (gnu_type) = 1;
Index: utils.c
===================================================================
--- utils.c (revision 133011)
+++ utils.c (working copy)
@@ -2486,9 +2486,9 @@ build_template (tree template_type, tree
tree bound_list = NULL_TREE;
tree field;
- if (TREE_CODE (array_type) == RECORD_TYPE
- && (TYPE_IS_PADDING_P (array_type)
- || TYPE_JUSTIFIED_MODULAR_P (array_type)))
+ while (TREE_CODE (array_type) == RECORD_TYPE
+ && (TYPE_IS_PADDING_P (array_type)
+ || TYPE_JUSTIFIED_MODULAR_P (array_type)))
array_type = TREE_TYPE (TYPE_FIELDS (array_type));
if (TREE_CODE (array_type) == ARRAY_TYPE