From 431cfac1ffb50746d86afbf486f84180d39c54e8 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sat, 17 Oct 2009 11:17:27 +0000 Subject: [PATCH] utils.c (convert): When converting to a padded type with an inner type of self-referential size... * gcc-interface/utils.c (convert): When converting to a padded type with an inner type of self-referential size, pad the expression before doing the unchecked conversion. From-SVN: r152935 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/gcc-interface/utils.c | 13 +++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/aggr11.adb | 17 +++++++++++++++++ gcc/testsuite/gnat.dg/aggr11_pkg.ads | 14 ++++++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/aggr11.adb create mode 100644 gcc/testsuite/gnat.dg/aggr11_pkg.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 80103fb053a..c5388ac456e 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2009-10-17 Eric Botcazou + + * gcc-interface/utils.c (convert): When converting to a padded type + with an inner type of self-referential size, pad the expression before + doing the unchecked conversion. + 2009-10-17 Eric Botcazou * gcc-interface/utils2.c (build_binary_op) : Mak diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 86575b529d9..a8225b0b30a 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3856,12 +3856,17 @@ convert (tree type, tree expr) == TYPE_NAME (TREE_TYPE (TYPE_FIELDS (type)))))) return convert (type, TREE_OPERAND (expr, 0)); - /* If the result type is a padded type with a self-referentially-sized - field and the expression type is a record, do this as an unchecked - conversion. */ + /* If the inner type is of self-referential size and the expression type + is a record, do this as an unchecked conversion. But first pad the + expression if possible to have the same size on both sides. */ if (TREE_CODE (etype) == RECORD_TYPE && CONTAINS_PLACEHOLDER_P (DECL_SIZE (TYPE_FIELDS (type)))) - return unchecked_convert (type, expr, false); + { + if (TREE_CONSTANT (TYPE_SIZE (etype))) + expr = convert (maybe_pad_type (etype, TYPE_SIZE (type), 0, Empty, + false, false, false, true), expr); + return unchecked_convert (type, expr, false); + } /* If we are converting between array types with variable size, do the final conversion as an unchecked conversion, again to avoid the need diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index acbbe361915..2e9f67d46ba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-10-17 Eric Botcazou + + * gnat.dg/aggr11.adb: New test. + * gnat.dg/aggr11_pkg.ads: New helper. + 2009-10-17 Eric Botcazou * gnat.dg/slice8.adb: New test. diff --git a/gcc/testsuite/gnat.dg/aggr11.adb b/gcc/testsuite/gnat.dg/aggr11.adb new file mode 100644 index 00000000000..1771d62cacb --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr11.adb @@ -0,0 +1,17 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +with Aggr11_Pkg; use Aggr11_Pkg; + +procedure Aggr11 is + + A : Arr := ((1 => (Kind => No_Error, B => True), + 2 => (Kind => Error), + 3 => (Kind => Error), + 4 => (Kind => No_Error, B => True), + 5 => (Kind => No_Error, B => True), + 6 => (Kind => No_Error, B => True))); + +begin + null; +end; diff --git a/gcc/testsuite/gnat.dg/aggr11_pkg.ads b/gcc/testsuite/gnat.dg/aggr11_pkg.ads new file mode 100644 index 00000000000..37008605a30 --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr11_pkg.ads @@ -0,0 +1,14 @@ +package Aggr11_Pkg is + + type Error_Type is (No_Error, Error); + + type Rec (Kind : Error_Type := No_Error) is record + case Kind is + when Error => null; + when others => B : Boolean; + end case; + end record; + + type Arr is array (1..6) of Rec; + +end Aggr11_Pkg; -- 2.30.2