This is the mail archive of the
mailing list for the GCC project.
[Ada] Fix regression with overlay of discriminated record
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Jun 2009 21:25:14 +0200
- Subject: [Ada] Fix regression with overlay of discriminated record
This patchlet fixes a regression that shows up with an exotic construct,
namely the declaration of an unconstrained discriminated record overlaid on
another object, with a static initialization expression. We may end up
assigning more bytes than we have allocated.
Tested on i586-suse-linux, applied on the mainline and 4.4 branch.
2009-06-30 Eric Botcazou <email@example.com>
* gcc-interface/utils2.c (build_binary_op) <MODIFY_EXPR>: Do not use
the type of the left operand if it pads a self-referential type when
the right operand is a constructor.
--- gcc-interface/utils2.c (revision 149112)
+++ gcc-interface/utils2.c (working copy)
@@ -707,9 +707,10 @@ build_binary_op (enum tree_code op_code,
/* If we are copying between padded objects with compatible types, use
the padded view of the objects, this is very likely more efficient.
- Likewise for a padded that is assigned a constructor, in order to
- avoid putting a VIEW_CONVERT_EXPR on the LHS. But don't do this if
- we wouldn't have actually copied anything. */
+ Likewise for a padded object that is assigned a constructor, if we
+ can convert the constructor to the inner type, to avoid putting a
+ VIEW_CONVERT_EXPR on the LHS. But don't do so if we wouldn't have
+ actually copied anything. */
else if (TREE_CODE (left_type) == RECORD_TYPE
&& TYPE_IS_PADDING_P (left_type)
&& TREE_CONSTANT (TYPE_SIZE (left_type))
@@ -719,9 +720,11 @@ build_binary_op (enum tree_code op_code,
(TREE_TYPE (TREE_OPERAND (right_operand, 0)))
- TREE_TYPE (TREE_OPERAND (right_operand, 0))))
- || TREE_CODE (right_operand) == CONSTRUCTOR)
+ TREE_TYPE (TREE_OPERAND (right_operand, 0))))
+ || (TREE_CODE (right_operand) == CONSTRUCTOR
+ && !CONTAINS_PLACEHOLDER_P
+ (DECL_SIZE (TYPE_FIELDS (left_type)))))
&& !integer_zerop (TYPE_SIZE (right_type)))
operation_type = left_type;