@@ -76,7 +76,8 @@ package body Range_Check is
7676 case Kind (Bound_Type) is
7777 when I_Bounded_Signedbv_Type
7878 | I_Bounded_Unsignedbv_Type
79- | I_Bounded_Floatbv_Type =>
79+ | I_Bounded_Floatbv_Type
80+ | I_C_Enum_Type =>
8081 return Get_Bound_Of_Bounded_Type (Bound_Type, Pos);
8182 when I_Unsignedbv_Type =>
8283 -- this case is probably unnecessary:
@@ -450,14 +451,18 @@ package body Range_Check is
450451 Bounds_Type : Irep)
451452 return Irep
452453 is
453- Followed_Bound_Type : constant Irep := Follow_Symbol_Type (Bounds_Type,
454- Global_Symbol_Table);
455-
454+ Followed_Bound_Type : constant Irep :=
455+ Follow_Symbol_Type (Bounds_Type,
456+ Global_Symbol_Table);
457+ Lower_Bound : constant Irep :=
458+ Get_Bound (N, Followed_Bound_Type, Bound_Low);
459+ Upper_Bound : constant Irep :=
460+ Get_Bound (N, Followed_Bound_Type, Bound_High);
456461 begin
457462 return Make_Range_Assert_Expr (N => N,
458463 Value => Value,
459- Lower_Bound => Get_Bound (N, Followed_Bound_Type, Bound_Low) ,
460- Upper_Bound => Get_Bound (N, Followed_Bound_Type, Bound_High) ,
464+ Lower_Bound => Lower_Bound ,
465+ Upper_Bound => Upper_Bound ,
461466 Expected_Return_Type => Get_Type (Value),
462467 Check_Name => " __CPROVER_Ada_Range_Check" );
463468
@@ -472,11 +477,36 @@ package body Range_Check is
472477 Upper_Bound : Irep)
473478 return Irep
474479 is
475- Bound_Type : constant Irep :=
480+ -- The bounds and or the value may be enumeration types.
481+ -- If so, they are converted to a bitvector type.
482+ -- When the enumeration is declared each literal s given the
483+ -- value of its position (starting from 0).
484+ Bound_Type_Raw : constant Irep :=
476485 Follow_Symbol_Type (Get_Type (Lower_Bound), Global_Symbol_Table);
477- Value_Expr_Type : constant Irep :=
486+ Value_Expr_Type_Raw : constant Irep :=
478487 Follow_Symbol_Type (Get_Type (Value_Expr), Global_Symbol_Table);
479488
489+ Bound_Type : constant Irep :=
490+ (if Kind (Bound_Type_Raw) = I_C_Enum_Type then
491+ Int32_T
492+ else
493+ Bound_Type_Raw);
494+
495+ Value_Expr_Type : constant Irep :=
496+ (if Kind (Value_Expr_Type_Raw) = I_C_Enum_Type then
497+ Int32_T
498+ else
499+ Value_Expr_Type_Raw);
500+
501+ Resolved_Value_Expr : constant Irep :=
502+ (if Kind (Value_Expr_Type_Raw) = I_C_Enum_Type then
503+ Typecast_If_Necessary
504+ (Expr => Value_Expr,
505+ New_Type => Int32_T,
506+ A_Symbol_Table => Global_Symbol_Table)
507+ else
508+ Value_Expr);
509+
480510 type Adjusted_Value_And_Bounds_T is
481511 record
482512 Value_Expr : Irep;
@@ -494,17 +524,17 @@ package body Range_Check is
494524 begin
495525 if Greater_Width then
496526 return (
497- Value_Expr => Typecast_If_Necessary
498- (Value_Expr , Bound_Type, Global_Symbol_Table),
499- Upper_Bound => Upper_Bound,
500- Lower_Bound => Lower_Bound);
527+ Value_Expr => Typecast_If_Necessary
528+ (Resolved_Value_Expr , Bound_Type, Global_Symbol_Table),
529+ Upper_Bound => Upper_Bound,
530+ Lower_Bound => Lower_Bound);
501531 else
502532 return (
503- Value_Expr => Value_Expr ,
504- Upper_Bound => Typecast_If_Necessary
505- (Upper_Bound, Value_Expr_Type, Global_Symbol_Table),
506- Lower_Bound => Typecast_If_Necessary
507- (Lower_Bound, Value_Expr_Type, Global_Symbol_Table));
533+ Value_Expr => Resolved_Value_Expr ,
534+ Upper_Bound => Typecast_If_Necessary
535+ (Upper_Bound, Value_Expr_Type, Global_Symbol_Table),
536+ Lower_Bound => Typecast_If_Necessary
537+ (Lower_Bound, Value_Expr_Type, Global_Symbol_Table));
508538 end if ;
509539 end Get_Adjusted_Value_And_Bounds ;
510540
0 commit comments