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] Constraint_Error raised for slice indexed by logical negation with -gnato


When overflow checking is enabled, the front end generates range checks
on the indexing of a slice with a bound of the form Boolean'Pos (not X)
that get mistranslated by gigi when optimization is enabled. The checks
should not have been generated in the first place (one is a tautological
full range check and the other redundantly tests that the result of
Boolean'Pos is >= 1), and were only generated because of a missing guard
in Checks.Determine_Range that resulted in a bogus comparison of bounds
against No_Uint.

The following test must compile and execute quietly with -gnato and -O:

$ gnatmake -gnato -O boolean_slice_bound_bug

procedure Boolean_Slice_Bound_Bug is

   procedure Proc (B : Boolean) is
      S : constant String (1 .. 1) := (others => 'X');
   begin
      if S (1 .. Boolean'Pos (not B)) /= "X" then
         raise Program_Error;
      end if;
   end Proc;

begin
   Proc (False);
end Boolean_Slice_Bound_Bug;

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

2011-09-02  Gary Dismukes  <dismukes@adacore.com>

	* checks.adb: (Determine_Range): Add test of OK1 to prevent the early
	return done when overflow checks are enabled, since comparisons against
	Lor and Hir should not be done when OK1 is False.

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]