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] Fix compiler crash with internal error 305


2001-12-04  Robert Dewar <dewar@gnat.com>

	* sem_attr.adb:
	(Compile_Time_Known_Attribute): New procedure.
	(Eval_Attribute, case Size): Use Compile_Time_Known_Attribute to ensure
	 proper range check.


*** sem_attr.adb	2001/10/16 14:22:34	1.554
--- sem_attr.adb	2001/10/17 01:35:55	1.555
***************
*** 3684,3689 ****
--- 3684,3694 ----
        --  any, of the attribute, are in a non-static context. This procedure
        --  performs the required additional checks.
  
+       procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint);
+       --  This procedure is called when the attribute N has a non-static
+       --  but compile time known value given by Val. It includes the
+       --  necessary checks for out of range values.
+ 
        procedure Float_Attribute_Universal_Integer
          (IEEES_Val : Int;
           IEEEL_Val : Int;
***************
*** 3757,3762 ****
--- 3762,3795 ----
           end loop;
        end Check_Expressions;
  
+       ----------------------------------
+       -- Compile_Time_Known_Attribute --
+       ----------------------------------
+ 
+       procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint) is
+          T : constant Entity_Id := Etype (N);
+ 
+       begin
+          Fold_Uint (N, Val);
+          Set_Is_Static_Expression (N, False);
+ 
+          --  Check that result is in bounds of the type if it is static
+ 
+          if Is_In_Range (N, T) then
+             null;
+ 
+          elsif Is_Out_Of_Range (N, T) then
+             Apply_Compile_Time_Constraint_Error
+               (N, "value not in range of}?");
+ 
+          elsif not Range_Checks_Suppressed (T) then
+             Enable_Range_Check (N);
+ 
+          else
+             Set_Do_Range_Check (N, False);
+          end if;
+       end Compile_Time_Known_Attribute;
+ 
        ---------------------------------------
        -- Float_Attribute_Universal_Integer --
        ---------------------------------------
***************
*** 4067,4074 ****
              if Is_Entity_Name (P)
                and then Known_Esize (Entity (P))
              then
!                Fold_Uint (N, Esize (Entity (P)));
!                Set_Is_Static_Expression (N, False);
                 return;
  
              else
--- 4100,4106 ----
              if Is_Entity_Name (P)
                and then Known_Esize (Entity (P))
              then
!                Compile_Time_Known_Attribute (N, Esize (Entity (P)));
                 return;
  
              else
***************
*** 4180,4187 ****
          and then (not Is_Generic_Type (P_Entity))
          and then Known_Static_RM_Size (P_Entity)
        then
!          Fold_Uint (N, RM_Size (P_Entity));
!          Set_Is_Static_Expression (N, False);
           return;
  
        --  No other cases are foldable (they certainly aren't static, and at
--- 4212,4218 ----
          and then (not Is_Generic_Type (P_Entity))
          and then Known_Static_RM_Size (P_Entity)
        then
!          Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
           return;
  
        --  No other cases are foldable (they certainly aren't static, and at
***************
*** 6272,6277 ****
--- 6303,6309 ----
                 end if;
  
                 if Is_Tagged_Type (Designated_Type (Typ)) then
+ 
                    --  If the attribute is in the context of an access
                    --  parameter, then the prefix is allowed to be of
                    --  the class-wide type (by AI-127).
***************
*** 6280,6286 ****
                       if not Covers (Designated_Type (Typ), Nom_Subt)
                         and then not Covers (Nom_Subt, Designated_Type (Typ))
                       then
- 
                          declare
                             Desig : Entity_Id;
  
--- 6312,6317 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]