diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2022-12-05 17:22:19 +0100 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2022-12-06 14:58:48 +0100 |
commit | 188965afb10a2bf14527f2aa9f9cb0f8fcc991e9 (patch) | |
tree | 901c6ed83703c0963add1354912927fe5419b25d | |
parent | 0cb36c85ab0c9876dde207d5b93aad7398539c7e (diff) | |
download | gcc-188965afb10a2bf14527f2aa9f9cb0f8fcc991e9.zip gcc-188965afb10a2bf14527f2aa9f9cb0f8fcc991e9.tar.gz gcc-188965afb10a2bf14527f2aa9f9cb0f8fcc991e9.tar.bz2 |
ada: Suppress warning for specific constant valid condition
Like in Exp_Ch4, we do not want to give warnings in Sem_Warn on a membership
test with a mark for a subtype that is predicated.
gcc/ada/
* sem_warn.adb (Warn_On_Constant_Valid_Condition): Bail out for a
membership test with a mark for a subtype that is predicated.
-rw-r--r-- | gcc/ada/sem_warn.adb | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb index 1311916..cb2a381 100644 --- a/gcc/ada/sem_warn.adb +++ b/gcc/ada/sem_warn.adb @@ -3290,6 +3290,44 @@ package body Sem_Warn is Left : constant Node_Id := Left_Opnd (Op); Right : constant Node_Id := Right_Opnd (Op); + function Comes_From_Simple_Condition_In_Source + (Op : Node_Id) return Boolean; + -- Return True if Op comes from a simple condition present in the source + + ------------------------------------------- + -- Comes_From_Simple_Condition_In_Source -- + ------------------------------------------- + + function Comes_From_Simple_Condition_In_Source + (Op : Node_Id) return Boolean + is + Orig_Op : constant Node_Id := Original_Node (Op); + + begin + if not Comes_From_Source (Orig_Op) then + return False; + end if; + + -- We do not want to give warnings on a membership test with a mark + -- for a subtype that is predicated, see also Exp_Ch4.Expand_N_In. + + if Nkind (Orig_Op) = N_In then + declare + Orig_Rop : constant Node_Id := + Original_Node (Right_Opnd (Orig_Op)); + begin + if Is_Entity_Name (Orig_Rop) + and then Is_Type (Entity (Orig_Rop)) + and then Present (Predicate_Function (Entity (Orig_Rop))) + then + return False; + end if; + end; + end if; + + return True; + end Comes_From_Simple_Condition_In_Source; + True_Result : Boolean; False_Result : Boolean; @@ -3298,7 +3336,7 @@ package body Sem_Warn is -- scalar operands are valid. if Constant_Condition_Warnings - and then Comes_From_Source (Original_Node (Op)) + and then Comes_From_Simple_Condition_In_Source (Op) and then Is_Scalar_Type (Etype (Left)) and then Is_Scalar_Type (Etype (Right)) |