diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-03-13 12:03:47 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-26 09:29:15 +0200 |
commit | da7b4b08f13b89752941f51651dcd5109d9be925 (patch) | |
tree | 74b6fc3355e8e72d688969d5c06a90fb7a87d010 | |
parent | 0368fc54bc11f15bfa0ed9913fd0017815dfaa5d (diff) | |
download | gcc-da7b4b08f13b89752941f51651dcd5109d9be925.zip gcc-da7b4b08f13b89752941f51651dcd5109d9be925.tar.gz gcc-da7b4b08f13b89752941f51651dcd5109d9be925.tar.bz2 |
ada: Enhance Is_Null_Range and Not_Null_Range predicates
Both predicates bail out if the bounds of the range are not known at compile
time, whereas Compile_Time_Compare can deal with them in specific cases.
gcc/ada/
* sem_eval.ads (Is_Null_Range): Remove requirements of compile-time
known bounds and add WARNING line.
(Not_Null_Range): Remove requirements of compile-time known bounds.
* sem_eval.adb (Is_Null_Range): Fall back to Compile_Time_Compare.
(Not_Null_Range): Likewise.
* fe.h (Is_Null_Range): New predicate.
-rw-r--r-- | gcc/ada/fe.h | 2 | ||||
-rw-r--r-- | gcc/ada/sem_eval.adb | 8 | ||||
-rw-r--r-- | gcc/ada/sem_eval.ads | 10 |
3 files changed, 11 insertions, 9 deletions
diff --git a/gcc/ada/fe.h b/gcc/ada/fe.h index 2d8f299..f283064 100644 --- a/gcc/ada/fe.h +++ b/gcc/ada/fe.h @@ -300,8 +300,10 @@ extern Boolean Is_Derived_Type (Entity_Id); /* sem_eval: */ #define Compile_Time_Known_Value sem_eval__compile_time_known_value +#define Is_Null_Range sem_eval__is_null_range extern Boolean Compile_Time_Known_Value (Node_Id); +extern Boolean Is_Null_Range (Node_Id, Node_Id); /* sem_util: */ diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 905e7ff..4608b1b 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -5416,8 +5416,9 @@ package body Sem_Eval is return Expr_Value_R (Lo) > Expr_Value_R (Hi); end if; end; + else - return False; + return Compile_Time_Compare (Lo, Hi, Assume_Valid => False) = GT; end if; end Is_Null_Range; @@ -6028,10 +6029,11 @@ package body Sem_Eval is return Expr_Value_R (Lo) <= Expr_Value_R (Hi); end if; end; + else - return False; + return + Compile_Time_Compare (Lo, Hi, Assume_Valid => False) in Compare_LE; end if; - end Not_Null_Range; ------------- diff --git a/gcc/ada/sem_eval.ads b/gcc/ada/sem_eval.ads index c2e2b45..5cb97ba 100644 --- a/gcc/ada/sem_eval.ads +++ b/gcc/ada/sem_eval.ads @@ -409,9 +409,9 @@ package Sem_Eval is -- an entity with Is_Known_Valid set, or Assume_No_Invalid_Values is True. function Is_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean; - -- Returns True if it can guarantee that Lo .. Hi is a null range. If it - -- cannot (because the value of Lo or Hi is not known at compile time) then - -- it returns False. + -- Returns True if it can guarantee that Lo .. Hi is a null range + + -- WARNING: There is a matching C declaration of this subprogram in fe.h function Is_OK_Static_Expression (N : Node_Id) return Boolean; -- An OK static expression is one that is static in the RM definition sense @@ -485,9 +485,7 @@ package Sem_Eval is -- per RM 4.9(38/2). N is a node only used to post warnings. function Not_Null_Range (Lo : Node_Id; Hi : Node_Id) return Boolean; - -- Returns True if it can guarantee that Lo .. Hi is not a null range. If - -- it cannot (because the value of Lo or Hi is not known at compile time) - -- then it returns False. + -- Returns True if it can guarantee that Lo .. Hi is not a null range function Predicates_Compatible (T1, T2 : Entity_Id) return Boolean; -- In Ada 2012, subtypes are statically compatible if the predicates are |