From db868e1edfabd88ca30f61e1b8e11155dc2a7ba5 Mon Sep 17 00:00:00 2001 From: Olivier Hainque Date: Mon, 1 Jun 2009 15:27:59 +0000 Subject: utils.c (convert): When converting to the packable version of the type... ada/ * gcc-interface/utils.c (convert) : When converting to the packable version of the type, clear TREE_STATIC/TREE_CONSTANT on the result if at least one of the input fields couldn't be output as a static constant any more. testsuite/ * gnat.dg/nested_float_packed.ads: New test. Co-Authored-By: Eric Botcazou From-SVN: r148049 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/gcc-interface/utils.c | 19 +++++++++++++++++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gnat.dg/nested_float_packed.ads | 24 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/nested_float_packed.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 51be8bf..c3f7219 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,6 +1,14 @@ 2009-06-01 Olivier Hainque Eric Botcazou + * gcc-interface/utils.c (convert) : When converting + to the packable version of the type, clear TREE_STATIC/TREE_CONSTANT + on the result if at least one of the input fields couldn't be output + as a static constant any more. + +2009-06-01 Olivier Hainque + Eric Botcazou + * gcc-interface/utils2.c (gnat_build_constructor): Factor out code. Use initializer_constant_valid_for_bitfield_p and CONSTRUCTOR_BITFIELD_P for bit-fields. diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 6dbd1e7..f3755a0 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3979,6 +3979,10 @@ convert (tree type, tree expr) unsigned HOST_WIDE_INT idx; tree index, value; + /* Whether we need to clear TREE_CONSTANT et al. on the output + constructor when we convert in place. */ + bool clear_constant = false; + FOR_EACH_CONSTRUCTOR_ELT(e, idx, index, value) { constructor_elt *elt = VEC_quick_push (constructor_elt, v, NULL); @@ -3987,15 +3991,30 @@ convert (tree type, tree expr) break; elt->index = field; elt->value = convert (TREE_TYPE (field), value); + + /* If packing has made this field a bitfield and the input + value couldn't be emitted statically any more, we need to + clear TREE_CONSTANT on our output. */ + if (!clear_constant && TREE_CONSTANT (expr) + && !CONSTRUCTOR_BITFIELD_P (efield) + && CONSTRUCTOR_BITFIELD_P (field) + && !initializer_constant_valid_for_bitfield_p (value)) + clear_constant = true; + efield = TREE_CHAIN (efield); field = TREE_CHAIN (field); } + /* If we have been able to match and convert all the input fields + to their output type, convert in place now. We'll fallback to a + view conversion downstream otherwise. */ if (idx == len) { expr = copy_node (expr); TREE_TYPE (expr) = type; CONSTRUCTOR_ELTS (expr) = v; + if (clear_constant) + TREE_CONSTANT (expr) = TREE_STATIC (expr) = false; return expr; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f82565b..69613d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,8 @@ 2009-06-01 Olivier Hainque + + * gnat.dg/nested_float_packed.ads: New test. + +2009-06-01 Olivier Hainque Eric Botcazou * gnat.dg/oconst[1-6].ad[bs]: New tests. Also support for ... diff --git a/gcc/testsuite/gnat.dg/nested_float_packed.ads b/gcc/testsuite/gnat.dg/nested_float_packed.ads new file mode 100644 index 0000000..ae7f523 --- /dev/null +++ b/gcc/testsuite/gnat.dg/nested_float_packed.ads @@ -0,0 +1,24 @@ +-- { dg-do compile } + +package Nested_Float_Packed is + + type Float_Type is record + Value : Float; + Valid : Boolean; + end record; + + type Data_Type is record + Data : Float_Type; + end record; + + Default_Data : constant Data_Type := + (Data => (Value => 1.0, Valid => False)); + + type Range_Type is (RV1, RV2, RV3); + for Range_Type use (1, 2, 3); + + Data_Block : array (Range_Type) + of Data_Type := (others => Default_Data); +end; + + -- cgit v1.1