This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Handle others better for string aggregates


This patch improves the handling of an aggregate like (others => 'A')
where the bounds are known, and the effect is almost like a string
literal except that it is not static.

The following test:

     1. package NonSOthers2 is
     2.    B  : constant String (1 .. 6) := (others => 'A');
     3.    DH : constant String (1 .. 8) := B & "BB";
     4.    X : Integer;
     5.    pragma Export (C, X, Link_Name => DH);
                                             |
        >>> argument for pragma "Export" must be a static expression
        >>> "DH" is not a static constant (RM 4.9(5))

     6. end;

correctly flags line 5, since an others aggregate is still not-static.
But with this patch installed, the declaration for line 3 is otherwise
similar to the use of a string literal. If this test is compiled with
-gnatG, the output contains the line:

   dh : constant string (1 .. 8) := "AAAAAABB";

showing this improved handling

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-11  Robert Dewar  <dewar@adacore.com>

	* exp_aggr.adb (Expand_N_Aggregate): Add circuit for handling
	others for string literal case. Also add big ??? comment about
	this new code, which should be redundant, but is not.
	* sem_eval.adb (Eval_Concatenation): Handle non-static case
	properly (Eval_String_Literal): Handle non-static literal properly

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]