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] Incorrect bounds retrieval in range checks


This change reorganizes the circuitry involved in the retrieval of the
bounds of various ranges for the purpose of generating range checks.
This circuitry would previously fail in two different ways:
  - returning an expression that had changed value since the point
    where that value was captured for elaboration of a slice;
  - returning the wrong entity for a bound of an entry family.

We know rely on the established general circuitry for bounds retrieval
consisting in the expansion of the 'First and 'Last attributes to
reliably retrieve these bounds.

The following test case must compile cleanly and display "A" when
executed:

$ gnatmake -q const_slice_with_var_bound
$ ./const_slice_with_var_bound
A

with Ada.Text_IO; use Ada.Text_IO;
procedure Const_Slice_With_Var_Bound is
   type R is record
      S : String (1 .. 2);
      L : Integer;
   end record;
   type A_R is access all R;

   procedure P (X : A_R) is
      Sl : constant String := X.S (X.S'First .. X.L);
      J : constant Natural := 1;
   begin
      X.L := 0;
      Put_Line (Sl (1 .. J));
   end P;

   My_R : aliased R := ("AB", 2);
begin
   P (My_R'Access);
end Const_Slice_With_Var_Bound;

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

2010-06-21  Thomas Quinot  <quinot@adacore.com>

	* sem_ch9.adb, checks.adb, sem_util.adb, sem_util.ads, sem_res.adb,
	sem_attr.adb (Get_E_First_Or_Last): Use attribute references on E to
	extract bounds, to ensure that we get the proper captured values,
	rather than an expression that may have changed value since the point
	where the subtype was elaborated.
	(Find_Body_Discriminal): New utility subprogram to share code between...
	(Eval_Attribute): For the case of a subtype bound that references a
	discriminant of the current concurrent type, insert appropriate
	discriminal reference.
	(Resolve_Entry.Actual_Index_Type.Actual_Discriminant_Ref): For a
	requeue to an entry in a family in the current task, use corresponding
	body discriminal. 
	(Analyze_Accept_Statement): Rely on expansion of attribute references
	to insert proper discriminal references in range check for entry in
	family.

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]