Commit 42acad07 by Eric Botcazou Committed by Eric Botcazou

trans.c (assoc_to_constructor): Minor tweaks.

	* gcc-interface/trans.c (assoc_to_constructor): Minor tweaks.
	* gcc-interface/utils2.c (build_simple_component_ref): Fix formatting
	issues.  Use COMPLETE_TYPE_P in assertion.  Also set TREE_READONLY if
	the type of the record is TYPE_READONLY.

From-SVN: r179184
parent a1d72281
2011-09-26 Eric Botcazou <ebotcazou@adacore.com> 2011-09-26 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (assoc_to_constructor): Minor tweaks.
* gcc-interface/utils2.c (build_simple_component_ref): Fix formatting
issues. Use COMPLETE_TYPE_P in assertion. Also set TREE_READONLY if
the type of the record is TYPE_READONLY.
2011-09-26 Eric Botcazou <ebotcazou@adacore.com>
Robert Dewar <dewar@adacore.com> Robert Dewar <dewar@adacore.com>
* sem_ch6.adb (Set_Formal_Mode): Set Can_Never_Be_Null on an IN or IN * sem_ch6.adb (Set_Formal_Mode): Set Can_Never_Be_Null on an IN or IN
......
...@@ -7728,24 +7728,21 @@ process_type (Entity_Id gnat_entity) ...@@ -7728,24 +7728,21 @@ process_type (Entity_Id gnat_entity)
} }
} }
/* GNAT_ENTITY is the type of the resulting constructors, /* GNAT_ENTITY is the type of the resulting constructor, GNAT_ASSOC is the
GNAT_ASSOC is the front of the Component_Associations of an N_Aggregate, front of the Component_Associations of an N_Aggregate and GNU_TYPE is the
and GNU_TYPE is the GCC type of the corresponding record. GCC type of the corresponding record type. Return the CONSTRUCTOR. */
Return a CONSTRUCTOR to build the record. */
static tree static tree
assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type) assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type)
{ {
tree gnu_list, gnu_result; tree gnu_list = NULL_TREE, gnu_result;
/* We test for GNU_FIELD being empty in the case where a variant /* We test for GNU_FIELD being empty in the case where a variant
was the last thing since we don't take things off GNAT_ASSOC in was the last thing since we don't take things off GNAT_ASSOC in
that case. We check GNAT_ASSOC in case we have a variant, but it that case. We check GNAT_ASSOC in case we have a variant, but it
has no fields. */ has no fields. */
for (gnu_list = NULL_TREE; Present (gnat_assoc); for (; Present (gnat_assoc); gnat_assoc = Next (gnat_assoc))
gnat_assoc = Next (gnat_assoc))
{ {
Node_Id gnat_field = First (Choices (gnat_assoc)); Node_Id gnat_field = First (Choices (gnat_assoc));
tree gnu_field = gnat_to_gnu_field_decl (Entity (gnat_field)); tree gnu_field = gnat_to_gnu_field_decl (Entity (gnat_field));
...@@ -7762,8 +7759,8 @@ assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type) ...@@ -7762,8 +7759,8 @@ assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type)
continue; continue;
/* Also ignore discriminants of Unchecked_Unions. */ /* Also ignore discriminants of Unchecked_Unions. */
else if (Is_Unchecked_Union (gnat_entity) if (Is_Unchecked_Union (gnat_entity)
&& Ekind (Entity (gnat_field)) == E_Discriminant) && Ekind (Entity (gnat_field)) == E_Discriminant)
continue; continue;
/* Before assigning a value in an aggregate make sure range checks /* Before assigning a value in an aggregate make sure range checks
...@@ -7780,13 +7777,9 @@ assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type) ...@@ -7780,13 +7777,9 @@ assoc_to_constructor (Entity_Id gnat_entity, Node_Id gnat_assoc, tree gnu_type)
gnu_result = extract_values (gnu_list, gnu_type); gnu_result = extract_values (gnu_list, gnu_type);
#ifdef ENABLE_CHECKING #ifdef ENABLE_CHECKING
{ /* Verify that every entry in GNU_LIST was used. */
tree gnu_field; for (; gnu_list; gnu_list = TREE_CHAIN (gnu_list))
gcc_assert (TREE_ADDRESSABLE (gnu_list));
/* Verify every entry in GNU_LIST was used. */
for (gnu_field = gnu_list; gnu_field; gnu_field = TREE_CHAIN (gnu_field))
gcc_assert (TREE_ADDRESSABLE (gnu_field));
}
#endif #endif
return gnu_result; return gnu_result;
......
...@@ -1756,14 +1756,15 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1756,14 +1756,15 @@ build_simple_component_ref (tree record_variable, tree component,
gcc_assert ((TREE_CODE (record_type) == RECORD_TYPE gcc_assert ((TREE_CODE (record_type) == RECORD_TYPE
|| TREE_CODE (record_type) == UNION_TYPE || TREE_CODE (record_type) == UNION_TYPE
|| TREE_CODE (record_type) == QUAL_UNION_TYPE) || TREE_CODE (record_type) == QUAL_UNION_TYPE)
&& TYPE_SIZE (record_type) && COMPLETE_TYPE_P (record_type)
&& (component != 0) != (field != 0)); && (component == NULL_TREE) != (field == NULL_TREE));
/* If no field was specified, look for a field with the specified name /* If no field was specified, look for a field with the specified name in
in the current record only. */ the current record only. */
if (!field) if (!field)
for (field = TYPE_FIELDS (record_type); field; for (field = TYPE_FIELDS (record_type);
field = TREE_CHAIN (field)) field;
field = DECL_CHAIN (field))
if (DECL_NAME (field) == component) if (DECL_NAME (field) == component)
break; break;
...@@ -1777,7 +1778,8 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1777,7 +1778,8 @@ build_simple_component_ref (tree record_variable, tree component,
tree new_field; tree new_field;
/* First loop thru normal components. */ /* First loop thru normal components. */
for (new_field = TYPE_FIELDS (record_type); new_field; for (new_field = TYPE_FIELDS (record_type);
new_field;
new_field = DECL_CHAIN (new_field)) new_field = DECL_CHAIN (new_field))
if (SAME_FIELD_P (field, new_field)) if (SAME_FIELD_P (field, new_field))
break; break;
...@@ -1797,12 +1799,12 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1797,12 +1799,12 @@ build_simple_component_ref (tree record_variable, tree component,
return ref; return ref;
} }
/* Next, loop thru DECL_INTERNAL_P components if we haven't found /* Next, loop thru DECL_INTERNAL_P components if we haven't found the
the component in the first search. Doing this search in 2 steps component in the first search. Doing this search in two steps is
is required to avoiding hidden homonymous fields in the required to avoid hidden homonymous fields in the _Parent field. */
_Parent field. */
if (!new_field) if (!new_field)
for (new_field = TYPE_FIELDS (record_type); new_field; for (new_field = TYPE_FIELDS (record_type);
new_field;
new_field = DECL_CHAIN (new_field)) new_field = DECL_CHAIN (new_field))
if (DECL_INTERNAL_P (new_field)) if (DECL_INTERNAL_P (new_field))
{ {
...@@ -1811,7 +1813,6 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1811,7 +1813,6 @@ build_simple_component_ref (tree record_variable, tree component,
NULL_TREE, new_field, no_fold_p); NULL_TREE, new_field, no_fold_p);
ref = build_simple_component_ref (field_ref, NULL_TREE, field, ref = build_simple_component_ref (field_ref, NULL_TREE, field,
no_fold_p); no_fold_p);
if (ref) if (ref)
return ref; return ref;
} }
...@@ -1822,16 +1823,15 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1822,16 +1823,15 @@ build_simple_component_ref (tree record_variable, tree component,
if (!field) if (!field)
return NULL_TREE; return NULL_TREE;
/* If the field's offset has overflowed, do not attempt to access it /* If the field's offset has overflowed, do not try to access it, as doing
as doing so may trigger sanity checks deeper in the back-end. so may trigger sanity checks deeper in the back-end. Note that we don't
Note that we don't need to warn since this will be done on trying need to warn since this will be done on trying to declare the object. */
to declare the object. */
if (TREE_CODE (DECL_FIELD_OFFSET (field)) == INTEGER_CST if (TREE_CODE (DECL_FIELD_OFFSET (field)) == INTEGER_CST
&& TREE_OVERFLOW (DECL_FIELD_OFFSET (field))) && TREE_OVERFLOW (DECL_FIELD_OFFSET (field)))
return NULL_TREE; return NULL_TREE;
/* Look through conversion between type variants. Note that this /* Look through conversion between type variants. This is transparent as
is transparent as far as the field is concerned. */ far as the field is concerned. */
if (TREE_CODE (record_variable) == VIEW_CONVERT_EXPR if (TREE_CODE (record_variable) == VIEW_CONVERT_EXPR
&& TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (record_variable, 0))) && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (record_variable, 0)))
== record_type) == record_type)
...@@ -1842,9 +1842,13 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1842,9 +1842,13 @@ build_simple_component_ref (tree record_variable, tree component,
ref = build3 (COMPONENT_REF, TREE_TYPE (field), inner_variable, field, ref = build3 (COMPONENT_REF, TREE_TYPE (field), inner_variable, field,
NULL_TREE); NULL_TREE);
if (TREE_READONLY (record_variable) || TREE_READONLY (field)) if (TREE_READONLY (record_variable)
|| TREE_READONLY (field)
|| TYPE_READONLY (record_type))
TREE_READONLY (ref) = 1; TREE_READONLY (ref) = 1;
if (TREE_THIS_VOLATILE (record_variable) || TREE_THIS_VOLATILE (field)
if (TREE_THIS_VOLATILE (record_variable)
|| TREE_THIS_VOLATILE (field)
|| TYPE_VOLATILE (record_type)) || TYPE_VOLATILE (record_type))
TREE_THIS_VOLATILE (ref) = 1; TREE_THIS_VOLATILE (ref) = 1;
...@@ -1853,8 +1857,8 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1853,8 +1857,8 @@ build_simple_component_ref (tree record_variable, tree component,
/* The generic folder may punt in this case because the inner array type /* The generic folder may punt in this case because the inner array type
can be self-referential, but folding is in fact not problematic. */ can be self-referential, but folding is in fact not problematic. */
else if (TREE_CODE (record_variable) == CONSTRUCTOR if (TREE_CODE (record_variable) == CONSTRUCTOR
&& TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (record_variable))) && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (record_variable)))
{ {
VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (record_variable); VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (record_variable);
unsigned HOST_WIDE_INT idx; unsigned HOST_WIDE_INT idx;
...@@ -1865,8 +1869,7 @@ build_simple_component_ref (tree record_variable, tree component, ...@@ -1865,8 +1869,7 @@ build_simple_component_ref (tree record_variable, tree component,
return ref; return ref;
} }
else return fold (ref);
return fold (ref);
} }
/* Like build_simple_component_ref, except that we give an error if the /* Like build_simple_component_ref, except that we give an error if the
......
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