aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2010-10-20 11:02:40 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2010-10-20 11:02:40 +0000
commit0d475ac5b42807b88d77b27bb3762459e6348693 (patch)
tree56cb2bd757966e0e9eda82f1ae634cee00c709ee /gcc
parent73dd5ce0c3b7d284d7ea9e6ee6f60b8ad4f9af3c (diff)
downloadgcc-0d475ac5b42807b88d77b27bb3762459e6348693.zip
gcc-0d475ac5b42807b88d77b27bb3762459e6348693.tar.gz
gcc-0d475ac5b42807b88d77b27bb3762459e6348693.tar.bz2
stor-layout.c (skip_simple_constant_arithmetic): New function.
* stor-layout.c (skip_simple_constant_arithmetic): New function. (self_referential_size): Use it instead of skip_simple_arithmetic. From-SVN: r165716
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/stor-layout.c28
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gnat.dg/discr25.adb11
-rw-r--r--gcc/testsuite/gnat.dg/discr25_pkg.adb24
-rw-r--r--gcc/testsuite/gnat.dg/discr25_pkg.ads15
6 files changed, 87 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 17cc226..a51fad5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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):
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 5796ea1..f366318 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -173,6 +173,32 @@ variable_size (tree size)
/* 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. */
@@ -241,7 +267,7 @@ self_referential_size (tree size)
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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cd27045..12d4bef 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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.
diff --git a/gcc/testsuite/gnat.dg/discr25.adb b/gcc/testsuite/gnat.dg/discr25.adb
new file mode 100644
index 0000000..a1effea
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/discr25.adb
@@ -0,0 +1,11 @@
+-- { dg-do compile }
+
+with Discr25_Pkg;
+
+procedure Discr25 (N : Natural) is
+
+ package Test_Set is new Discr25_Pkg (N);
+
+begin
+ null;
+end;
diff --git a/gcc/testsuite/gnat.dg/discr25_pkg.adb b/gcc/testsuite/gnat.dg/discr25_pkg.adb
new file mode 100644
index 0000000..59792fd
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/discr25_pkg.adb
@@ -0,0 +1,24 @@
+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;
diff --git a/gcc/testsuite/gnat.dg/discr25_pkg.ads b/gcc/testsuite/gnat.dg/discr25_pkg.ads
new file mode 100644
index 0000000..c09634d
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/discr25_pkg.ads
@@ -0,0 +1,15 @@
+generic
+
+ N : Natural;
+
+package Discr25_Pkg is
+
+ type T is private;
+
+ procedure Proc1 (Set : in out T);
+
+private
+ type Obj_T (Size_Max : Natural);
+ type T is access Obj_T;
+
+end Discr25_Pkg;