From 16ae1b4293294fe0e73706d2d8f1d633651dc97e Mon Sep 17 00:00:00 2001 From: charlet Date: Tue, 6 Sep 2011 12:03:30 +0000 Subject: [PATCH] 2011-09-06 Hristian Kirtchev * exp_attr.adb (Expand_N_Attribute_Reference): Rewrite the processing for Descriptor_Size. * gnat_rm.texi: Rephrase the wording for attribute Descriptor_Size to account for its broader usage. * sem_attr.adb (Analyze_Attribute): Change the error detection circuitry for Descriptor_Size as the attribute is now applicable to all types. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178590 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ada/ChangeLog | 10 ++++++++++ gcc/ada/exp_attr.adb | 19 ++++++++++++++++--- gcc/ada/gnat_rm.texi | 9 +++++---- gcc/ada/sem_attr.adb | 17 ++++------------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 9451718..02520df 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2011-09-06 Hristian Kirtchev + + * exp_attr.adb (Expand_N_Attribute_Reference): Rewrite the + processing for Descriptor_Size. + * gnat_rm.texi: Rephrase the wording for attribute Descriptor_Size + to account for its broader usage. + * sem_attr.adb (Analyze_Attribute): Change the error detection + circuitry for Descriptor_Size as the attribute is now applicable + to all types. + 2011-09-06 Robert Dewar * sem_attr.adb, prj-nmsc.adb, exp_aggr.adb: Minor reformatting. diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index a98a7b93..c05385e 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -1803,10 +1803,23 @@ package body Exp_Attr is -- Descriptor_Size -- --------------------- - -- This attribute is handled entirely by the back end - when Attribute_Descriptor_Size => - Apply_Universal_Integer_Attribute_Checks (N); + + -- Attribute Descriptor_Size is handled by the back end when applied + -- to an unconstrained array type. + + if Is_Array_Type (Ptyp) + and then not Is_Constrained (Ptyp) + then + Apply_Universal_Integer_Attribute_Checks (N); + + -- For any other type, the descriptor size is 0 because there is no + -- actual descriptor. + + else + Rewrite (N, Make_Integer_Literal (Loc, 0)); + Analyze (N); + end if; --------------- -- Elab_Body -- diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index 7680876..4e74a32 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -5941,9 +5941,10 @@ as a @code{Pos} value (0 for @code{High_Order_First}, 1 for @findex Descriptor_Size @noindent Attribute @code{Descriptor_Size} returns the size in bits of the descriptor -allocated for an unconstrained array type. An array descriptor contains bounds -information and is located immediately before the first element of the array. -The value of attribute @code{Descriptor_Size} is of type universal integer. +allocated for a type. The result is non-zero only for unconstrained array +types and the returned value is of type universal integer. In GNAT, an array +descriptor contains bounds information and is located immediately before the +first element of the array. @smallexample @c ada type Unconstr_Array is array (Positive range <>) of Boolean; @@ -5953,7 +5954,7 @@ Put_Line ("Descriptor size = " & Unconstr_Array'Descriptor_Size'Img); @noindent The attribute takes into account any additional padding due to type alignment. In the example above, the descriptor contains two values of type -@code{Positive} representing the low and high bound. Since @code{Positive} has +@code{Positive} representing the low and high bound. Since @code{Positive} has a size of 31 bits and an alignment of 4, the descriptor size is @code{2 * Positive'Size + 2} or 64 bits. diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index eca9836..738edda 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -1906,7 +1906,7 @@ package body Sem_Attr is end if; end Validate_Non_Static_Attribute_Function_Call; - -- Start of processing for Analyze_Attribute + -- Start of processing for Analyze_Attribute begin -- Immediate return if unrecognized attribute (already diagnosed @@ -3021,19 +3021,10 @@ package body Sem_Attr is when Attribute_Descriptor_Size => Check_E0; - -- Attribute Descriptor_Size is relevant only in the context of an - -- unconstrained array type. - - -- Shouldn't it just return zero for types other than arrays or - -- constrained arrays ??? - - if Is_Entity_Name (P) - and then Is_Array_Type (Entity (P)) - and then not Is_Constrained (Entity (P)) + if not Is_Entity_Name (P) + or else not Is_Type (Entity (P)) then - null; - else - Error_Attr_P ("invalid prefix for % attribute"); + Error_Attr_P ("prefix of attribute % must denote a type"); end if; Set_Etype (N, Universal_Integer); -- 2.7.4