Commit 86a8ba5b by Eric Botcazou Committed by Eric Botcazou

decl.c (check_ok_for_atomic): Rename into...

	* gcc-interface/decl.c (check_ok_for_atomic): Rename into...
	(check_ok_for_atomic_type): ...this.  When checking the mode, also
	check that the type is sufficient aligned.  Remove useless code and
	tidy up implementation.
	(gnat_to_gnu_entity): Adjust to above renaming.
	(gnat_to_gnu_component_type): Likewise.
	(gnat_to_gnu_field): Likewise.

From-SVN: r219007
parent 9a1e784a
2014-12-22 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (check_ok_for_atomic): Rename into...
(check_ok_for_atomic_type): ...this. When checking the mode, also
check that the type is sufficient aligned. Remove useless code and
tidy up implementation.
(gnat_to_gnu_entity): Adjust to above renaming.
(gnat_to_gnu_component_type): Likewise.
(gnat_to_gnu_field): Likewise.
2014-12-17 Pierre-Marie de Rodat <derodat@adacore.com> 2014-12-17 Pierre-Marie de Rodat <derodat@adacore.com>
* gcc-interface/misc.c (gnat_get_array_descr_info): New. Use it for * gcc-interface/misc.c (gnat_get_array_descr_info): New. Use it for
......
...@@ -191,7 +191,7 @@ static vec<variant_desc> build_variant_list (tree, ...@@ -191,7 +191,7 @@ static vec<variant_desc> build_variant_list (tree,
static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool); 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 unsigned int validate_alignment (Uint, Entity_Id, unsigned int); static unsigned int validate_alignment (Uint, Entity_Id, unsigned int);
static void check_ok_for_atomic (tree, Entity_Id, bool); static void check_ok_for_atomic_type (tree, Entity_Id, bool);
static tree create_field_decl_from (tree, tree, tree, tree, tree, static tree create_field_decl_from (tree, tree, tree, tree, tree,
vec<subst_pair> ); vec<subst_pair> );
static tree create_rep_part (tree, tree, tree); static tree create_rep_part (tree, tree, tree);
...@@ -870,7 +870,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -870,7 +870,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
&& TYPE_MULTI_ARRAY_P (gnu_inner)) && TYPE_MULTI_ARRAY_P (gnu_inner))
gnu_inner = TREE_TYPE (gnu_inner); gnu_inner = TREE_TYPE (gnu_inner);
check_ok_for_atomic (gnu_inner, gnat_entity, true); check_ok_for_atomic_type (gnu_inner, gnat_entity, true);
} }
/* Now check if the type of the object allows atomic access. Note /* Now check if the type of the object allows atomic access. Note
...@@ -880,7 +880,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -880,7 +880,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
always copying via an intermediate value, but it's not clear it's always copying via an intermediate value, but it's not clear it's
worth the effort. */ worth the effort. */
if (Is_Atomic (gnat_entity)) if (Is_Atomic (gnat_entity))
check_ok_for_atomic (gnu_type, gnat_entity, false); check_ok_for_atomic_type (gnu_type, gnat_entity, false);
/* If this is an aliased object with an unconstrained nominal subtype, /* If this is an aliased object with an unconstrained nominal subtype,
make a type that includes the template. */ make a type that includes the template. */
...@@ -5035,7 +5035,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -5035,7 +5035,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
} }
if (Is_Atomic (gnat_entity)) if (Is_Atomic (gnat_entity))
check_ok_for_atomic (gnu_type, gnat_entity, false); check_ok_for_atomic_type (gnu_type, gnat_entity, false);
/* If this is not an unconstrained array type, set some flags. */ /* If this is not an unconstrained array type, set some flags. */
if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE) if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE)
...@@ -5548,7 +5548,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition, ...@@ -5548,7 +5548,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
gnu_type = make_packable_type (gnu_type, false); gnu_type = make_packable_type (gnu_type, false);
if (Has_Atomic_Components (gnat_array)) if (Has_Atomic_Components (gnat_array))
check_ok_for_atomic (gnu_type, gnat_array, true); check_ok_for_atomic_type (gnu_type, gnat_array, true);
/* Get and validate any specified Component_Size. */ /* Get and validate any specified Component_Size. */
gnu_comp_size gnu_comp_size
...@@ -6484,7 +6484,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, ...@@ -6484,7 +6484,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
} }
if (Is_Atomic (gnat_field)) if (Is_Atomic (gnat_field))
check_ok_for_atomic (gnu_field_type, gnat_field, false); check_ok_for_atomic_type (gnu_field_type, gnat_field, false);
if (Present (Component_Clause (gnat_field))) if (Present (Component_Clause (gnat_field)))
{ {
...@@ -8088,78 +8088,63 @@ validate_alignment (Uint alignment, Entity_Id gnat_entity, unsigned int align) ...@@ -8088,78 +8088,63 @@ validate_alignment (Uint alignment, Entity_Id gnat_entity, unsigned int align)
return align; return align;
} }
/* Verify that OBJECT, a type or decl, is something we can implement /* Verify that TYPE is something we can implement atomically. If not, issue
atomically. If not, give an error for GNAT_ENTITY. COMP_P is true an error for GNAT_ENTITY. COMPONENT_P is true if we are being called to
if we require atomic components. */ process a component type. */
static void static void
check_ok_for_atomic (tree object, Entity_Id gnat_entity, bool comp_p) check_ok_for_atomic_type (tree type, Entity_Id gnat_entity, bool component_p)
{ {
Node_Id gnat_error_point = gnat_entity; Node_Id gnat_error_point = gnat_entity;
Node_Id gnat_node; Node_Id gnat_node;
machine_mode mode; machine_mode mode;
enum mode_class mclass;
unsigned int align; unsigned int align;
tree size; tree size;
/* There are three case of what OBJECT can be. It can be a type, in which /* If this is an anonymous base type, nothing to check, the error will be
case we take the size, alignment and mode from the type. It can be a reported on the source type if need be. */
declaration that was indirect, in which case the relevant values are if (!Comes_From_Source (gnat_entity))
that of the type being pointed to, or it can be a normal declaration, return;
in which case the values are of the decl. The code below assumes that
OBJECT is either a type or a decl. */
if (TYPE_P (object))
{
/* If this is an anonymous base type, nothing to check. Error will be
reported on the source type. */
if (!Comes_From_Source (gnat_entity))
return;
mode = TYPE_MODE (object);
align = TYPE_ALIGN (object);
size = TYPE_SIZE (object);
}
else if (DECL_BY_REF_P (object))
{
mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (object)));
align = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (object)));
size = TYPE_SIZE (TREE_TYPE (TREE_TYPE (object)));
}
else
{
mode = DECL_MODE (object);
align = DECL_ALIGN (object);
size = DECL_SIZE (object);
}
/* Consider all floating-point types atomic and any types that that are mode = TYPE_MODE (type);
represented by integers no wider than a machine word. */ mclass = GET_MODE_CLASS (mode);
if (GET_MODE_CLASS (mode) == MODE_FLOAT align = TYPE_ALIGN (type);
|| ((GET_MODE_CLASS (mode) == MODE_INT size = TYPE_SIZE (type);
|| GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
&& GET_MODE_BITSIZE (mode) <= BITS_PER_WORD)) /* Consider all aligned floating-point types atomic and any aligned types
that are represented by integers no wider than a machine word. */
if ((mclass == MODE_FLOAT
|| ((mclass == MODE_INT || mclass == MODE_PARTIAL_INT)
&& GET_MODE_BITSIZE (mode) <= BITS_PER_WORD))
&& align >= GET_MODE_ALIGNMENT (mode))
return; return;
/* For the moment, also allow anything that has an alignment equal /* For the moment, also allow anything that has an alignment equal to its
to its size and which is smaller than a word. */ size and which is smaller than a word. */
if (size && TREE_CODE (size) == INTEGER_CST if (size
&& TREE_CODE (size) == INTEGER_CST
&& compare_tree_int (size, align) == 0 && compare_tree_int (size, align) == 0
&& align <= BITS_PER_WORD) && align <= BITS_PER_WORD)
return; return;
for (gnat_node = First_Rep_Item (gnat_entity); Present (gnat_node); for (gnat_node = First_Rep_Item (gnat_entity);
Present (gnat_node);
gnat_node = Next_Rep_Item (gnat_node)) gnat_node = Next_Rep_Item (gnat_node))
{ if (Nkind (gnat_node) == N_Pragma)
if (!comp_p && Nkind (gnat_node) == N_Pragma {
&& (Get_Pragma_Id (Chars (Pragma_Identifier (gnat_node))) unsigned char pragma_id
== Pragma_Atomic)) = Get_Pragma_Id (Chars (Pragma_Identifier (gnat_node)));
gnat_error_point = First (Pragma_Argument_Associations (gnat_node));
else if (comp_p && Nkind (gnat_node) == N_Pragma if ((pragma_id == Pragma_Atomic && !component_p)
&& (Get_Pragma_Id (Chars (Pragma_Identifier (gnat_node))) || (pragma_id == Pragma_Atomic_Components && component_p))
== Pragma_Atomic_Components)) {
gnat_error_point = First (Pragma_Argument_Associations (gnat_node)); gnat_error_point = First (Pragma_Argument_Associations (gnat_node));
} break;
}
}
if (comp_p) if (component_p)
post_error_ne ("atomic access to component of & cannot be guaranteed", post_error_ne ("atomic access to component of & cannot be guaranteed",
gnat_error_point, gnat_entity); gnat_error_point, gnat_entity);
else else
......
...@@ -662,7 +662,7 @@ gnat_get_array_descr_info (const_tree type, struct array_descr_info *info) ...@@ -662,7 +662,7 @@ gnat_get_array_descr_info (const_tree type, struct array_descr_info *info)
info->ndimensions = i; info->ndimensions = i;
convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (type); convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (type);
/* TODO??? For row major ordering, we probably want to emit nothing and /* TODO: For row major ordering, we probably want to emit nothing and
instead specify it as the default in Dw_TAG_compile_unit. */ instead specify it as the default in Dw_TAG_compile_unit. */
info->ordering = (convention_fortran_p info->ordering = (convention_fortran_p
? array_descr_ordering_column_major ? array_descr_ordering_column_major
......
2014-12-22 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/atomic2.ads: New test.
2014-12-21 Oleg Endo <olegendo@gcc.gnu.org> 2014-12-21 Oleg Endo <olegendo@gcc.gnu.org>
PR target/17280 PR target/17280
......
-- { dg-do compile }
package Atomic2 is
type Rec1 is record
C : Character;
I : Integer;
pragma Atomic (I);
end record;
for Rec1 use record
C at 0 range 0 .. 7;
I at 1 range 0 .. 31; -- { dg-error "position of atomic field" }
end record;
type Rec2 is record
C : Character;
I : Integer;
pragma Atomic (I);
end record;
pragma Pack (Rec2);
type My_Int is new Integer;
for My_Int'Alignment use 1;
pragma Atomic (My_Int); -- { dg-error "atomic access" }
end Atomic2;
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