From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 27997384C91C; Tue, 6 Dec 2022 14:01:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27997384C91C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335285; bh=fGtYN4ROJ4lxRIJnREi1b8kQBU1hjdbi/MZneLrCvcY=; h=From:To:Subject:Date:From; b=bbVTw/TS1KefF3vhCkEK59BcecGPYogK9bvmORgWEtqmJqSHcZ7f5Y38/PoCQPRB5 bErI0g7QEER0s0EneI318KLHE4p59FPK1erbuhRF6U9Gp4cc78uOSx+kPR/DK9BH5M 0AkyrzHMHgppd/MUU0tc8h50hCFxamqsaO0k/w2Y= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4513] ada: Suppress warning for specific constant valid condition X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 0cb36c85ab0c9876dde207d5b93aad7398539c7e X-Git-Newrev: 188965afb10a2bf14527f2aa9f9cb0f8fcc991e9 Message-Id: <20221206140125.27997384C91C@sourceware.org> Date: Tue, 6 Dec 2022 14:01:25 +0000 (GMT) List-Id: https://gcc.gnu.org/g:188965afb10a2bf14527f2aa9f9cb0f8fcc991e9 commit r13-4513-g188965afb10a2bf14527f2aa9f9cb0f8fcc991e9 Author: Eric Botcazou Date: Mon Dec 5 17:22:19 2022 +0100 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. Diff: --- 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))