[Ada] Improve allocation of constants with discriminated types
Eric Botcazou
ebotcazou@adacore.com
Wed Apr 2 10:07:00 GMT 2008
As demonstrated by the following testcase, the allocation of constants with
discriminated types in Gigi is suboptimal. For
type T (Big : Boolean := False) is record
case Big is
when True =>
Content : Integer;
when False =>
null;
end case;
end record;
D : constant T := (True, 0);
Var : T := D;
Con : constant T := D;
D is allocated statically with exact size, Var is allocated statically with
maximum size, but Con is allocated dynamically (with exact size).
We can do better by propagating the size of D thanks to its constantness.
Tested on i586-suse-linux, applied on the mainline
2008-04-02 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (gnat_to_gnu_entity) <object>: For a constant object whose
type has self-referential size, get the size from the initializing
expression directly if it is also a constant whose nominal type
has self-referential size.
2008-04-02 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/discr_record_constant.ads: New test.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-diff
Size: 1659 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080402/f218890b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: discr_record_constant.ads
Type: text/x-adasrc
Size: 531 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080402/f218890b/attachment-0001.bin>
More information about the Gcc-patches
mailing list