[Ada] Fix incorrect itype sharing for case expression in limited type return
commitbaa3015d8efebd731701d6985bb7a7083db244a8
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 11 Jun 2022 11:05:39 +0000 (11 13:05 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 6 Jul 2022 13:29:48 +0000 (6 13:29 +0000)
tree2b0106fa74f3849d43088aacaefda7fdc5ce1699
parent56311a3c9f207c83a08f964e65687b2ba302799e
[Ada] Fix incorrect itype sharing for case expression in limited type return

The compiler aborts with an internal error in gigi, but the problem is an
itype incorrectly shared between several branches of an if_statement that
has been created for a Build-In-Place return.

Three branches of this if_statement contain an allocator statement and
the latter two have been obtained as the result of calling New_Copy_Tree
on the first; now the initialization expression of the first had also been
obtained as the result of calling New_Copy_Tree on the original tree, and
these chained calls to New_Copy_Tree run afoul of an issue with the copy
of itypes after the rewrite of an aggregate as an expression with actions.

Fixing this issue looks quite delicate, so this fixes the incorrect sharing
by replacing the chained calls to New_Copy_Tree with repeated calls on the
original expression, which is more elegant in any case.

gcc/ada/

* exp_ch3.adb (Make_Allocator_For_BIP_Return): New local function.
(Expand_N_Object_Declaration): Use it to build the three allocators
for a Build-In-Place return with an unconstrained type.  Update the
head comment after other recent changes.
gcc/ada/exp_ch3.adb