From 1d5bfe9720e54fa5b723046046b4a150b1f982e7 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 18 May 2012 20:33:49 +0000 Subject: [PATCH] decl.c (gnat_to_gnu_entity): For an object at global level with unconstrained nominal subtype and a... * gcc-interface/decl.c (gnat_to_gnu_entity) : For an object at global level with unconstrained nominal subtype and a non-fixed size, make a variable for the size. From-SVN: r187666 --- gcc/ada/ChangeLog | 6 ++++++ gcc/ada/gcc-interface/decl.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/specs/lto12.ads | 10 ++++++++++ gcc/testsuite/gnat.dg/specs/lto12_pkg.ads | 14 ++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/specs/lto12.ads create mode 100644 gcc/testsuite/gnat.dg/specs/lto12_pkg.ads diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index b67d659a1276..832317b7ad41 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2012-05-18 Eric Botcazou + + * gcc-interface/decl.c (gnat_to_gnu_entity) : For an object at + global level with unconstrained nominal subtype and a non-fixed size, + make a variable for the size. + 2012-05-15 Andris Pavenis PR ada/52494 diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 97ade5e61590..bb3626946fef 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -760,6 +760,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) gnu_size = max_size (TYPE_SIZE (gnu_type), true); mutable_p = true; } + + /* If we are at global level and the size isn't constant, call + elaborate_expression_1 to make a variable for it rather than + calculating it each time. */ + if (global_bindings_p () && !TREE_CONSTANT (gnu_size)) + gnu_size = elaborate_expression_1 (gnu_size, gnat_entity, + get_identifier ("SIZE"), + definition, false); } /* If the size is zero byte, make it one byte since some linkers have diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 87941bd7aa58..697090fb1510 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-05-18 Eric Botcazou + + * gnat.dg/specs/lto12.ads: New test. + * gnat.dg/specs/lto12_pkg.ads: New helper. + 2012-05-18 Richard Guenther PR tree-optimization/53346 diff --git a/gcc/testsuite/gnat.dg/specs/lto12.ads b/gcc/testsuite/gnat.dg/specs/lto12.ads new file mode 100644 index 000000000000..3914e0f90b3f --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/lto12.ads @@ -0,0 +1,10 @@ +-- { dg-do compile } +-- { dg-options "-flto" { target lto } } + +with Lto12_Pkg; use Lto12_Pkg; + +package Lto12 is + + C : constant R := F; + +end Lto12; diff --git a/gcc/testsuite/gnat.dg/specs/lto12_pkg.ads b/gcc/testsuite/gnat.dg/specs/lto12_pkg.ads new file mode 100644 index 000000000000..02ee491b5db3 --- /dev/null +++ b/gcc/testsuite/gnat.dg/specs/lto12_pkg.ads @@ -0,0 +1,14 @@ +-- { dg-excess-errors "cannot generate code" } + +package Lto12_Pkg is + + type R (Kind : Boolean := False) is record + case Kind is + when True => I : Integer; + when others => null; + end case; + end record; + + function F return R; + +end Lto12_Pkg; -- 2.47.2