public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Suppress warning for specific constant valid condition
@ 2022-12-06 14:02 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2022-12-06 14:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

From: Eric Botcazou <ebotcazou@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_warn.adb | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/sem_warn.adb b/gcc/ada/sem_warn.adb
index 1311916f19c..cb2a3819df6 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))
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-06 14:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 14:02 [COMMITTED] ada: Suppress warning for specific constant valid condition Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).