decl.c (change_qualified_type): New static function.

* gcc-interface/decl.c (change_qualified_type): New static function.
	(gnat_to_gnu_entity): Use it throughout to add qualifiers on types.
	<E_Array_Type>: Set TYPE_VOLATILE on the array type directly.
	<E_Array_Subtype>: Likewise.
	Do not set flags on an UNCONSTRAINED_ARRAY_TYPE directly.
	(gnat_to_gnu_component_type): Likewise.
	(gnat_to_gnu_param): Likewise.

From-SVN: r210588
This commit is contained in:
Eric Botcazou 2014-05-18 21:02:59 +00:00 committed by Eric Botcazou
parent 08b8b90cff
commit 4aecc2f8e4
5 changed files with 76 additions and 49 deletions

View File

@ -1,3 +1,13 @@
2014-05-18 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (change_qualified_type): New static function.
(gnat_to_gnu_entity): Use it throughout to add qualifiers on types.
<E_Array_Type>: Set TYPE_VOLATILE on the array type directly.
<E_Array_Subtype>: Likewise.
Do not set flags on an UNCONSTRAINED_ARRAY_TYPE directly.
(gnat_to_gnu_component_type): Likewise.
(gnat_to_gnu_param): Likewise.
2014-05-18 Eric Botcazou <ebotcazou@adacore.com>
* fe.h (Set_Present_Expr): Move around.

View File

@ -145,6 +145,7 @@ static tree gnat_to_gnu_component_type (Entity_Id, bool, bool);
static tree gnat_to_gnu_param (Entity_Id, Mechanism_Type, Entity_Id, bool,
bool *);
static tree gnat_to_gnu_field (Entity_Id, tree, int, bool, bool);
static tree change_qualified_type (tree, int);
static bool same_discriminant_p (Entity_Id, Entity_Id);
static bool array_type_has_nonaliased_component (tree, Entity_Id);
static bool compile_time_known_address_p (Node_Id);
@ -1047,9 +1048,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
Note that we need to preserve the volatility of the renamed
object through the indirection. */
if (TREE_THIS_VOLATILE (gnu_expr) && !TYPE_VOLATILE (gnu_type))
gnu_type = build_qualified_type (gnu_type,
(TYPE_QUALS (gnu_type)
| TYPE_QUAL_VOLATILE));
gnu_type
= change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
gnu_type = build_reference_type (gnu_type);
inner_const_flag = TREE_READONLY (gnu_expr);
const_flag = true;
@ -1107,9 +1107,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
|| imported_p
|| Present (Address_Clause (gnat_entity)))))
&& !TYPE_VOLATILE (gnu_type))
gnu_type = build_qualified_type (gnu_type,
(TYPE_QUALS (gnu_type)
| TYPE_QUAL_VOLATILE));
gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
/* If we are defining an aliased object whose nominal subtype is
unconstrained, the object is a record that contains both the
@ -1408,8 +1406,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
}
if (const_flag)
gnu_type = build_qualified_type (gnu_type, (TYPE_QUALS (gnu_type)
| TYPE_QUAL_CONST));
gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_CONST);
/* Convert the expression to the type of the object except in the
case where the object's type is unconstrained or the object's type
@ -2243,6 +2240,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
SET_TYPE_MODE (tem, BLKmode);
}
TYPE_VOLATILE (tem) = Treat_As_Volatile (gnat_entity);
/* If an alignment is specified, use it if valid. But ignore it
for the original type of packed array types. If the alignment
was requested with an explicit alignment clause, state so. */
@ -2595,6 +2594,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
SET_TYPE_MODE (gnu_type, BLKmode);
}
TYPE_VOLATILE (gnu_type) = Treat_As_Volatile (gnat_entity);
/* Attach the TYPE_STUB_DECL in case we have a parallel type. */
TYPE_STUB_DECL (gnu_type)
= create_type_stub_decl (gnu_entity_name, gnu_type);
@ -2725,9 +2726,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
process_attributes (&gnu_type, &attr_list, false, gnat_entity);
if (Treat_As_Volatile (gnat_entity))
gnu_type
= build_qualified_type (gnu_type,
TYPE_QUALS (gnu_type)
| TYPE_QUAL_VOLATILE);
= change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
/* Make it artificial only if the base type was artificial too.
That's sort of "morally" true and will make it possible for
the debugger to look it up by name in DWARF, which is needed
@ -3218,9 +3217,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
&& Is_By_Reference_Type (gnat_entity))
SET_TYPE_MODE (gnu_type, BLKmode);
/* We used to remove the associations of the discriminants and _Parent
for validity checking but we may need them if there's a Freeze_Node
for a subtype used in this record. */
TYPE_VOLATILE (gnu_type) = Treat_As_Volatile (gnat_entity);
/* Fill in locations of fields. */
@ -3917,9 +3913,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
&& TREE_CODE (gnu_desig_type) != UNCONSTRAINED_ARRAY_TYPE)
{
gnu_desig_type
= build_qualified_type
(gnu_desig_type,
TYPE_QUALS (gnu_desig_type) | TYPE_QUAL_CONST);
= change_qualified_type (gnu_desig_type, TYPE_QUAL_CONST);
/* Some extra processing is required if we are building a
pointer to an incomplete type (in the GCC sense). We might
@ -4623,18 +4617,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
if (TREE_CODE (gnu_return_type) == VOID_TYPE)
const_flag = false;
gnu_type
= build_qualified_type (gnu_type,
TYPE_QUALS (gnu_type)
| (TYPE_QUAL_CONST * const_flag)
| (TYPE_QUAL_VOLATILE * volatile_flag));
if (const_flag || volatile_flag)
{
const int quals
= (const_flag ? TYPE_QUAL_CONST : 0)
| (volatile_flag ? TYPE_QUAL_VOLATILE : 0);
if (has_stub)
gnu_stub_type
= build_qualified_type (gnu_stub_type,
TYPE_QUALS (gnu_stub_type)
| (TYPE_QUAL_CONST * const_flag)
| (TYPE_QUAL_VOLATILE * volatile_flag));
gnu_type = change_qualified_type (gnu_type, quals);
if (has_stub)
gnu_stub_type = change_qualified_type (gnu_stub_type, quals);
}
/* If we have a builtin decl for that function, use it. Check if the
profiles are compatible and warn if they are not. The checker is
@ -4900,8 +4893,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
gnu_size = NULL_TREE;
}
/* If the alignment hasn't already been processed and this is
not an unconstrained array, see if an alignment is specified.
/* If the alignment has not already been processed and this is not
an unconstrained array type, see if an alignment is specified.
If not, we pick a default alignment for atomic objects. */
if (align != 0 || TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE)
;
@ -5088,19 +5081,21 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
}
}
if (Treat_As_Volatile (gnat_entity))
gnu_type
= build_qualified_type (gnu_type,
TYPE_QUALS (gnu_type) | TYPE_QUAL_VOLATILE);
if (Is_Atomic (gnat_entity))
check_ok_for_atomic (gnu_type, gnat_entity, false);
if (Present (Alignment_Clause (gnat_entity)))
TYPE_USER_ALIGN (gnu_type) = 1;
/* If this is not an unconstrained array type, set some flags. */
if (TREE_CODE (gnu_type) != UNCONSTRAINED_ARRAY_TYPE)
{
if (Treat_As_Volatile (gnat_entity))
gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
if (Universal_Aliasing (gnat_entity))
TYPE_UNIVERSAL_ALIASING_P (TYPE_MAIN_VARIANT (gnu_type)) = 1;
if (Present (Alignment_Clause (gnat_entity)))
TYPE_USER_ALIGN (gnu_type) = 1;
if (Universal_Aliasing (gnat_entity))
TYPE_UNIVERSAL_ALIASING_P (TYPE_MAIN_VARIANT (gnu_type)) = 1;
}
if (!gnu_decl)
gnu_decl = create_type_decl (gnu_entity_name, gnu_type,
@ -5648,9 +5643,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
}
if (Has_Volatile_Components (gnat_array))
gnu_type
= build_qualified_type (gnu_type,
TYPE_QUALS (gnu_type) | TYPE_QUAL_VOLATILE);
gnu_type = change_qualified_type (gnu_type, TYPE_QUAL_VOLATILE);
return gnu_type;
}
@ -5708,9 +5701,7 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech,
if (ro_param
&& TREE_CODE (gnu_param_type) != UNCONSTRAINED_ARRAY_TYPE
&& !CONTAINS_PLACEHOLDER_P (TYPE_SIZE (gnu_param_type)))
gnu_param_type = build_qualified_type (gnu_param_type,
(TYPE_QUALS (gnu_param_type)
| TYPE_QUAL_CONST));
gnu_param_type = change_qualified_type (gnu_param_type, TYPE_QUAL_CONST);
/* For foreign conventions, pass arrays as pointers to the element type.
First check for unconstrained array and get the underlying array. */
@ -5760,9 +5751,8 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech,
gnu_param_type = TREE_TYPE (gnu_param_type);
if (ro_param)
gnu_param_type = build_qualified_type (gnu_param_type,
(TYPE_QUALS (gnu_param_type)
| TYPE_QUAL_CONST));
gnu_param_type
= change_qualified_type (gnu_param_type, TYPE_QUAL_CONST);
gnu_param_type = build_pointer_type (gnu_param_type);
}
@ -5799,7 +5789,7 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech,
gnu_param_type = build_reference_type (gnu_param_type);
if (restrict_p)
gnu_param_type
= build_qualified_type (gnu_param_type, TYPE_QUAL_RESTRICT);
= change_qualified_type (gnu_param_type, TYPE_QUAL_RESTRICT);
by_ref = true;
}
@ -5865,6 +5855,15 @@ gnat_to_gnu_param (Entity_Id gnat_param, Mechanism_Type mech,
return gnu_param;
}
/* Like build_qualified_type, but TYPE_QUALS is added to the existing
qualifiers on TYPE. */
static tree
change_qualified_type (tree type, int type_quals)
{
return build_qualified_type (type, TYPE_QUALS (type) | type_quals);
}
/* Return true if DISCR1 and DISCR2 represent the same discriminant. */
static bool

View File

@ -1,3 +1,7 @@
2014-05-18 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/volatile12.ad[sb]: New test.
2014-05-18 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/enum3.adb: New test.

View File

@ -0,0 +1,7 @@
-- { dg-do compile }
package body Volatile12 is
procedure Proc (A : Arr) is begin null; end;
end Volatile12;

View File

@ -0,0 +1,7 @@
package Volatile12 is
type Arr is array (Integer range <>) of Integer with Volatile;
procedure Proc (A : Arr);
end Volatile12;