+2010-10-20 Eric Botcazou <ebotcazou@adacore.com>
+
+ * stor-layout.c (skip_simple_constant_arithmetic): New function.
+ (self_referential_size): Use it instead of skip_simple_arithmetic.
+
2010-10-20 Olivier Hainque <hainque@adacore.com>
* config/rs6000/rs6000.c (rs6000_reg_live_or_pic_offset_p):
/* An array of functions used for self-referential size computation. */
static GTY(()) VEC (tree, gc) *size_functions;
+/* Look inside EXPR into simple arithmetic operations involving constants.
+ Return the outermost non-arithmetic or non-constant node. */
+
+static tree
+skip_simple_constant_arithmetic (tree expr)
+{
+ while (true)
+ {
+ if (UNARY_CLASS_P (expr))
+ expr = TREE_OPERAND (expr, 0);
+ else if (BINARY_CLASS_P (expr))
+ {
+ if (TREE_CONSTANT (TREE_OPERAND (expr, 1)))
+ expr = TREE_OPERAND (expr, 0);
+ else if (TREE_CONSTANT (TREE_OPERAND (expr, 0)))
+ expr = TREE_OPERAND (expr, 1);
+ else
+ break;
+ }
+ else
+ break;
+ }
+
+ return expr;
+}
+
/* Similar to copy_tree_r but do not copy component references involving
PLACEHOLDER_EXPRs. These nodes are spotted in find_placeholder_in_expr
and substituted in substitute_in_expr. */
VEC(tree,gc) *args = NULL;
/* Do not factor out simple operations. */
- t = skip_simple_arithmetic (size);
+ t = skip_simple_constant_arithmetic (size);
if (TREE_CODE (t) == CALL_EXPR)
return size;
+2010-10-20 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gnat.dg/discr25.adb: New test.
+ * gnat.dg/discr25_pkg.ad[sb]: New helper.
+
2010-10-20 Olivier Hainque <hainque@adacore.com>
* gcc.target/powerpc/ehreturn.c: New test.
--- /dev/null
+package body Discr25_Pkg is
+
+ type Arr1 is array (Natural range <>) of Integer;
+
+ B : constant Boolean := N > 0;
+
+ type Arr2 is array (True .. B) of Integer;
+
+ type Obj_T (Size_Max : Natural) is record
+ A2 : Arr2;
+ A1 : Arr1 (0 .. Size_Max);
+ end record;
+
+ procedure Proc1 (Set : in out T) is
+ begin
+ Set := new Obj_T'(Set.all);
+ end;
+
+ procedure Proc2 (Obj : in out T; L : Natural) is
+ begin
+ Obj := new Obj_T (L);
+ end;
+
+end Discr25_Pkg;