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] Concatenation of arrays with modular index types.


For concatenation of arrays other than strings we create a function that
computes the total size of the result and transfers the contents of each
operand into it. If the index of the array type is a modular type the
computation of the upper bound may overflow but the wrap-around evaluation
will fail to raise the appropriate exception. In this case we must generate
an explicit constraint check an use a larger integer type to perform the
computation of the bounds.
Execution of the following program must raise constraint_error:

 procedure R is
    type Byte is mod 256;
    for Byte'Size use 8;
    type Block is array(Byte range <>) of Integer;

    C0: Block(1..1)   := (others => 111);
    C1: Block(0..255) := (others => 111);
    C2: Block := C0 & C1;  --  must raise constraint error
 begin
    null;
 end;

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

2008-05-26  Ed Schonberg  <schonberg@adacore.com>

	* exp_ch4.adb (Expand_Concatenate_Other): Add explicit constraint
	checks on the upper bound if the index type is a modular type, to
	prevent wrap-around computations when size is close to upper bound of
	type.

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]