[Ada] Fix sharing of expression in array aggregate with others choice

Pierre-Marie de Rodat derodat@adacore.com
Wed Sep 18 08:40:00 GMT 2019


This change fixes a long-standing issue in the compiler that is
generally silent but may lead to wrong code generation in specific
circumstances.  When an others choice in an array aggregate spans
multiple ranges, the compiler may generate multiple (groups of)
assignments for the ranges.

The problem is that it internally reuses the original expression for all
the ranges, which is problematic if this expression gets rewritten
during the processing of one of the ranges and typically causes a new
temporary to be shared between different ranges.

The solution is to duplicate the original expression for each range.

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

2019-09-18  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_aggr.adb (Build_Array_Aggr_Code): In STEP 1 (c), duplicate
	the expression and reset the Loop_Actions for each loop
	generated for an others choice.

gcc/testsuite/

	* gnat.dg/aggr28.adb: New testcase.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 2370 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190918/cbfd0a8a/attachment.bin>


More information about the Gcc-patches mailing list