From 88872b00daeaf461796962afeb8901c172aacc50 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 8 Apr 2011 20:21:36 +0000 Subject: [PATCH] trans.c (Identifier_to_gnu): Do not return initializers of aggregate types that contain a placeholder. * gcc-interface/trans.c (Identifier_to_gnu): Do not return initializers of aggregate types that contain a placeholder. From-SVN: r172209 --- gcc/ada/ChangeLog | 5 +++++ gcc/ada/gcc-interface/trans.c | 8 ++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/aggr17.adb | 28 ++++++++++++++++++++++++++++ gcc/testsuite/gnat.dg/aggr18.adb | 28 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/aggr17.adb create mode 100644 gcc/testsuite/gnat.dg/aggr18.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 155256e068c..2046aa715d9 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Eric Botcazou + + * gcc-interface/trans.c (Identifier_to_gnu): Do not return initializers + of aggregate types that contain a placeholder. + 2011-04-08 Nathan Froyd * gcc-interface/utils.c (handle_sentinel_attribute): Don't use diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 9622625a7ec..378f88c604d 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -1058,10 +1058,14 @@ Identifier_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p) /* If we have a constant declaration and its initializer, try to return the latter to avoid the need to call fold in lots of places and the need for - elaboration code if this identifier is used as an initializer itself. */ + elaboration code if this identifier is used as an initializer itself. + Don't do it for aggregate types that contain a placeholder since their + initializers cannot be manipulated easily. */ if (TREE_CONSTANT (gnu_result) && DECL_P (gnu_result) - && DECL_INITIAL (gnu_result)) + && DECL_INITIAL (gnu_result) + && !(AGGREGATE_TYPE_P (TREE_TYPE (gnu_result)) + && type_contains_placeholder_p (TREE_TYPE (gnu_result)))) { bool constant_only = (TREE_CODE (gnu_result) == CONST_DECL && !DECL_CONST_CORRESPONDING_VAR (gnu_result)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4f5fb0006db..23f95b16e40 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-04-08 Eric Botcazou + + * gnat.dg/aggr17.adb: New test. + * gnat.dg/aggr18.adb: Likewise. + 2011-04-08 Michael Matz PR middle-end/48389 diff --git a/gcc/testsuite/gnat.dg/aggr17.adb b/gcc/testsuite/gnat.dg/aggr17.adb new file mode 100644 index 00000000000..3ba41985f72 --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr17.adb @@ -0,0 +1,28 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +procedure Aggr17 is + + type Enum is (A, B); + + type Rec (D : Enum := Enum'First) is record + case D is + when A => X : Integer; + when B => null; + end case; + end record; + for Rec'Size use 128; + pragma Volatile (Rec); + + type Config_T (D : Enum := Enum'First) is record + N : Natural; + R : Rec (D); + end record; + + C : constant Config_T := (D => A, N => 1, R => (D => A, X => 0)); + + type Arr is array (Natural range 1 .. C.N) of Boolean; + +begin + null; +end; diff --git a/gcc/testsuite/gnat.dg/aggr18.adb b/gcc/testsuite/gnat.dg/aggr18.adb new file mode 100644 index 00000000000..511add8a17d --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr18.adb @@ -0,0 +1,28 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +procedure Aggr18 is + + type Enum is (A, B); + + type Rec (D : Enum := Enum'First) is record + case D is + when A => X : Integer; + when B => null; + end case; + end record; + for Rec'Size use 128; + pragma Volatile (Rec); + + type Config_T (D : Enum := Enum'First) is record + N : Natural; + R : Rec (D); + end record; + + C : Config_T := (D => A, N => 1, R => (D => A, X => 0)); + + type Arr is array (Natural range 1 .. C.N) of Boolean; + +begin + null; +end;