+2009-06-01 Olivier Hainque <hainque@adacore.com>
+ Eric Botcazou <botcazou@adacore.com>
+
+ * gcc-interface/utils.c (convert) <CONSTRUCTOR case>: When converting
+ to the packable version of the type, clear TREE_STATIC/TREE_CONSTANT
+ on the result if at least one of the input fields couldn't be output
+ as a static constant any more.
+
2009-06-01 Olivier Hainque <hainque@adacore.com>
Eric Botcazou <botcazou@adacore.com>
unsigned HOST_WIDE_INT idx;
tree index, value;
+ /* Whether we need to clear TREE_CONSTANT et al. on the output
+ constructor when we convert in place. */
+ bool clear_constant = false;
+
FOR_EACH_CONSTRUCTOR_ELT(e, idx, index, value)
{
constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL);
break;
elt->index = field;
elt->value = convert (TREE_TYPE (field), value);
+
+ /* If packing has made this field a bitfield and the input
+ value couldn't be emitted statically any more, we need to
+ clear TREE_CONSTANT on our output. */
+ if (!clear_constant && TREE_CONSTANT (expr)
+ && !CONSTRUCTOR_BITFIELD_P (efield)
+ && CONSTRUCTOR_BITFIELD_P (field)
+ && !initializer_constant_valid_for_bitfield_p (value))
+ clear_constant = true;
+
efield = TREE_CHAIN (efield);
field = TREE_CHAIN (field);
}
+ /* If we have been able to match and convert all the input fields
+ to their output type, convert in place now. We'll fallback to a
+ view conversion downstream otherwise. */
if (idx == len)
{
expr = copy_node (expr);
TREE_TYPE (expr) = type;
CONSTRUCTOR_ELTS (expr) = v;
+ if (clear_constant)
+ TREE_CONSTANT (expr) = TREE_STATIC (expr) = false;
return expr;
}
}
--- /dev/null
+-- { dg-do compile }
+
+package Nested_Float_Packed is
+
+ type Float_Type is record
+ Value : Float;
+ Valid : Boolean;
+ end record;
+
+ type Data_Type is record
+ Data : Float_Type;
+ end record;
+
+ Default_Data : constant Data_Type :=
+ (Data => (Value => 1.0, Valid => False));
+
+ type Range_Type is (RV1, RV2, RV3);
+ for Range_Type use (1, 2, 3);
+
+ Data_Block : array (Range_Type)
+ of Data_Type := (others => Default_Data);
+end;
+
+