[Ada] Fix small regression with others choice in array aggregate

Pierre-Marie de Rodat derodat@adacore.com
Wed Nov 14 11:46:00 GMT 2018


This change is aimed at fixing a fallout of bumping the default value of
the Max_Others_Replicate parameter of the Convert_To_Positional routine.
This parameter is responsible for taming the duplication of the
expression of an others choice in an array aggregate so that it doesn't
result in a code size explosion.

Unfortunately a fine-grained control based on the analysis of the
expression is not really possible because this analysis has not been
done yet by the time the decision is made in most cases, so the usual
syntactic ambiguities of the language come into play and make the
process a bit cumbersome.  For example, it is not possible to
distinguish a simple reference to a static constant declared in another
unit from a call to a parameterless function.

Therefore the change errs on the side of caution and allows the
duplication only if the expression is unambiguously static and
sufficiently simple.

For the following three aggregates, the duplication must be blocked and
the elaboration of the aggregates must be done by means of a loop:

with Q; use Q;

procedure P is

  A : Arr := (others => Get_Value);

  B : Arr := (others => Get_Other_Value (0));

  C : Arr := (others => Q.Get_Other_Value (1));

begin
  null;
end;

package Q is

  type Arr is array (1 .. 32) of Integer;

  function Get_Value return Integer;

  function Get_Other_Value (I : integer) return Integer;

end Q;

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

2018-11-14  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_aggr.adb (Is_Static_Element): New predicate extracted
	from...
	(Check_Static_Components): ...here.  Call Is_Static_Element on
	each element of the component association list, if any.
	(Flatten): Duplicate the expression of an others choice only if
	it is static or is an aggregate which can itself be flattened.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 6151 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20181114/96482019/attachment.bin>


More information about the Gcc-patches mailing list