* [Ada] Add support for scalar types with small alignment
@ 2008-03-08 11:11 Eric Botcazou
2008-03-08 12:13 ` Eric Botcazou
0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2008-03-08 11:11 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 486 bytes --]
It is piggybacked on the padding machinery. This makes it possible to write
type My_Integer is new Integer;
for My_Integer'Alignment use 1;
Tested on i586-suse-linux, applied on the mainline.
2008-03-08 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (gnat_to_gnu_entity) <E_Signed_Integer_Subtype>: Add suppor
for scalar types with small alignment.
2008-03-08 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/small_alignment.adb: New test.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 1778 bytes --]
Index: decl.c
===================================================================
--- decl.c (revision 133014)
+++ decl.c (working copy)
@@ -1520,6 +1520,45 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
copy_alias_set (gnu_type, gnu_field_type);
}
+ /* If the type we are dealing with has got a smaller alignment than the
+ natural one, we need to wrap it up in a record type and under-align
+ the latter. We reuse the padding machinery for this purpose. */
+ else if (Known_Alignment (gnat_entity)
+ && UI_Is_In_Int_Range (Alignment (gnat_entity))
+ && (align = UI_To_Int (Alignment (gnat_entity)) * BITS_PER_UNIT)
+ && align < TYPE_ALIGN (gnu_type))
+ {
+ tree gnu_field_type = gnu_type;
+ tree gnu_field;
+
+ gnu_type = make_node (RECORD_TYPE);
+ TYPE_NAME (gnu_type) = create_concat_name (gnat_entity, "PAD");
+
+ TYPE_ALIGN (gnu_type) = align;
+ TYPE_PACKED (gnu_type) = 1;
+
+ /* Create a stripped-down declaration of the original type, mainly
+ for debugging. */
+ create_type_decl (get_entity_name (gnat_entity), gnu_field_type,
+ NULL, true, debug_info_p, gnat_entity);
+
+ /* Don't notify the field as "addressable", since we won't be taking
+ it's address and it would prevent create_field_decl from making a
+ bitfield. */
+ gnu_field = create_field_decl (get_identifier ("OBJECT"),
+ gnu_field_type, gnu_type, 1, 0, 0, 0);
+
+ finish_record_type (gnu_type, gnu_field, 0, false);
+ TYPE_IS_PADDING_P (gnu_type) = 1;
+ SET_TYPE_ADA_SIZE (gnu_type, bitsize_int (esize));
+
+ copy_alias_set (gnu_type, gnu_field_type);
+ }
+
+ /* Otherwise reset the alignment lest we computed it above. */
+ else
+ align = 0;
+
break;
case E_Floating_Point_Type:
[-- Attachment #3: small_alignment.adb --]
[-- Type: text/x-adasrc, Size: 436 bytes --]
-- { dg-do run }
-- { dg-options "-gnatws" }
procedure Small_Alignment is
type My_Integer is new Integer;
for My_Integer'Alignment use 1;
function Set_A return My_Integer is
begin
return 12;
end;
function Set_B return My_Integer is
begin
return 6;
end;
C : Character;
A : My_Integer := Set_A;
B : My_Integer := Set_B;
begin
A := A * B / 2;
if A /= 36 then
raise Program_Error;
end if;
end;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Ada] Add support for scalar types with small alignment
2008-03-08 11:11 [Ada] Add support for scalar types with small alignment Eric Botcazou
@ 2008-03-08 12:13 ` Eric Botcazou
0 siblings, 0 replies; 2+ messages in thread
From: Eric Botcazou @ 2008-03-08 12:13 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 464 bytes --]
> 2008-03-08 Eric Botcazou <ebotcazou@adacore.com>
>
> * decl.c (gnat_to_gnu_entity) <E_Signed_Integer_Subtype>: Add suppor
> for scalar types with small alignment.
A bit of related housekeeping.
Tested on i586-suse-linux, applied on the mainline.
2008-03-08 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (gnat_to_gnu_entity) <E_Signed_Integer_Subtype>: Do not
bother propagating the TYPE_USER_ALIGN flag when creating a JM type.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-diff, Size: 945 bytes --]
Index: decl.c
===================================================================
--- decl.c (revision 133031)
+++ decl.c (working copy)
@@ -1484,7 +1484,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
such values), we only get the good bits, since the unused bits
are uninitialized. Both goals are accomplished by wrapping the
modular value in an enclosing struct. */
- if (Is_Packed_Array_Type (gnat_entity))
+ if (Is_Packed_Array_Type (gnat_entity))
{
tree gnu_field_type = gnu_type;
tree gnu_field;
@@ -1499,7 +1499,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
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;
/* Create a stripped-down declaration of the original type, mainly
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-03-08 12:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-08 11:11 [Ada] Add support for scalar types with small alignment Eric Botcazou
2008-03-08 12:13 ` Eric Botcazou
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).