Commit 5102fac5 by Eric Botcazou Committed by Eric Botcazou

decl.c (ceil_alignment): New function.

	* decl.c (ceil_alignment): New function.
	(gnat_to_gnu_entity): Use it to set the alignment on atomic types.
	(make_packable_type): Likewise.

From-SVN: r130373
parent 96d9bb07
2007-11-23 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (ceil_alignment): New function.
(gnat_to_gnu_entity): Use it to set the alignment on atomic types.
(make_packable_type): Likewise.
2007-11-22 Olivier Hainque <hainque@adacore.com> 2007-11-22 Olivier Hainque <hainque@adacore.com>
* trans.c (gnat_to_gnu) <case N_Free_Statement>: Reformat lines * trans.c (gnat_to_gnu) <case N_Free_Statement>: Reformat lines
...@@ -113,6 +113,7 @@ static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool); ...@@ -113,6 +113,7 @@ static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool);
static void set_rm_size (Uint, tree, Entity_Id); static void set_rm_size (Uint, tree, Entity_Id);
static tree make_type_from_size (tree, tree, bool); static tree make_type_from_size (tree, tree, bool);
static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); static unsigned int validate_alignment (Uint, Entity_Id, unsigned int);
static unsigned int ceil_alignment (unsigned HOST_WIDE_INT);
static void check_ok_for_atomic (tree, Entity_Id, bool); static void check_ok_for_atomic (tree, Entity_Id, bool);
static int compatible_signatures_p (tree ftype1, tree ftype2); static int compatible_signatures_p (tree ftype1, tree ftype2);
...@@ -645,9 +646,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -645,9 +646,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
/* If this is an atomic object with no specified size and alignment, /* If this is an atomic object with no specified size and alignment,
but where the size of the type is a constant, set the alignment to but where the size of the type is a constant, set the alignment to
the lowest power of two greater than the size, or to the the smallest not less than the size, or to the biggest meaningful
biggest meaningful alignment, whichever is smaller. */ alignment, whichever is smaller. */
if (Is_Atomic (gnat_entity) && !gnu_size && align == 0 if (Is_Atomic (gnat_entity) && !gnu_size && align == 0
&& TREE_CODE (TYPE_SIZE (gnu_type)) == INTEGER_CST) && TREE_CODE (TYPE_SIZE (gnu_type)) == INTEGER_CST)
{ {
...@@ -656,10 +656,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -656,10 +656,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
BIGGEST_ALIGNMENT)) BIGGEST_ALIGNMENT))
align = BIGGEST_ALIGNMENT; align = BIGGEST_ALIGNMENT;
else else
align = ((unsigned int) 1 align = ceil_alignment (tree_low_cst (TYPE_SIZE (gnu_type), 1));
<< (floor_log2 (tree_low_cst
(TYPE_SIZE (gnu_type), 1) - 1)
+ 1));
} }
/* If the object is set to have atomic components, find the component /* If the object is set to have atomic components, find the component
...@@ -734,7 +731,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -734,7 +731,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
|| (Is_Exported (gnat_entity) || (Is_Exported (gnat_entity)
/* Exclude exported constants created by the compiler, /* Exclude exported constants created by the compiler,
which should boil down to static dispatch tables and which should boil down to static dispatch tables and
make it possible to put them in read-only memory.  */ make it possible to put them in read-only memory. */
&& (Comes_From_Source (gnat_entity) || !const_flag)) && (Comes_From_Source (gnat_entity) || !const_flag))
|| Is_Imported (gnat_entity) || Is_Imported (gnat_entity)
|| Present (Address_Clause (gnat_entity))) || Present (Address_Clause (gnat_entity)))
...@@ -2468,8 +2465,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -2468,8 +2465,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
= validate_alignment (Alignment (gnat_entity), gnat_entity, 0); = validate_alignment (Alignment (gnat_entity), gnat_entity, 0);
else if (Is_Atomic (gnat_entity)) else if (Is_Atomic (gnat_entity))
TYPE_ALIGN (gnu_type) TYPE_ALIGN (gnu_type)
= (esize >= BITS_PER_WORD ? BITS_PER_WORD = esize >= BITS_PER_WORD ? BITS_PER_WORD : ceil_alignment (esize);
: 1 << (floor_log2 (esize - 1) + 1));
else else
TYPE_ALIGN (gnu_type) = 0; TYPE_ALIGN (gnu_type) = 0;
...@@ -5208,9 +5204,7 @@ make_packable_type (tree type) ...@@ -5208,9 +5204,7 @@ make_packable_type (tree type)
TYPE_SIZE_UNIT (new_type) = TYPE_SIZE_UNIT (type); TYPE_SIZE_UNIT (new_type) = TYPE_SIZE_UNIT (type);
} }
TYPE_ALIGN (new_type) TYPE_ALIGN (new_type) = ceil_alignment (tree_low_cst (TYPE_SIZE (type), 1));
= ((HOST_WIDE_INT) 1
<< (floor_log2 (tree_low_cst (TYPE_SIZE (type), 1) - 1) + 1));
TYPE_USER_ALIGN (new_type) = 1; TYPE_USER_ALIGN (new_type) = 1;
/* Now copy the fields, keeping the position and size. */ /* Now copy the fields, keeping the position and size. */
...@@ -6784,6 +6778,14 @@ validate_alignment (Uint alignment, Entity_Id gnat_entity, unsigned int align) ...@@ -6784,6 +6778,14 @@ validate_alignment (Uint alignment, Entity_Id gnat_entity, unsigned int align)
return align; return align;
} }
/* Return the smallest alignment not less than SIZE. */
static unsigned int
ceil_alignment (unsigned HOST_WIDE_INT size)
{
return (unsigned int) 1 << (floor_log2 (size - 1) + 1);
}
/* Verify that OBJECT, a type or decl, is something we can implement /* Verify that OBJECT, a type or decl, is something we can implement
atomically. If not, give an error for GNAT_ENTITY. COMP_P is true atomically. If not, give an error for GNAT_ENTITY. COMP_P is true
if we require atomic components. */ if we require atomic components. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment