From patchwork Tue Dec 6 14:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 61567 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59A11382B3FB for ; Tue, 6 Dec 2022 14:03:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59A11382B3FB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670335428; bh=0cTdgJlLyliOvReS1XkF1p15y/Z8HIfLlYtYydk6PYs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=ZItx8SrMcFE5/KKKlt5RkYciSUlbJHmKOHOzzqrE0UJVTzGqOfiKip0V76fcpfQy8 n23+BAZg6KS/x3LyP0bDsTlpfy7G9nExTvHq/m83R975sW/6sJquydDn8Q+a2ONsSA hPZW5LaQqVxzkMxEpWiTFD7U6enCHh7a7IzT2tQs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id B13413875B55 for ; Tue, 6 Dec 2022 14:02:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B13413875B55 Received: by mail-wr1-x433.google.com with SMTP id d1so23561367wrs.12 for ; Tue, 06 Dec 2022 06:02:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0cTdgJlLyliOvReS1XkF1p15y/Z8HIfLlYtYydk6PYs=; b=ZIFNIEFx0E/n311p/1QJYi0F4PFYmjVMTpPQuuG3lIW6qp7QyoVbjsxSfTCdgtetkV jkJctj4DrvZSOHywKctMZFctmEqmcCeZ9rYW4Ru+L38ZPzk+XSjQC0RCj8gQy1ZAp59A b6X6Hs1yBMm/NrqeyAM74x+8NNcjD5+7RrDedoBgix/j4f38x+593C1rruEI8loSnGSz RywkrkPcyZ3tQWRTJ4s43Fo0esfwVNaq8kfxThGZtiXjuRFKA3aF64baT2KyKsWolQeD g8ucVfYgHlYGzRrgD5cKlo0/d9syT4iIsrjyUeXkBp1sZDEt4BABrMZVCQUMFWCzA26U 4bWg== X-Gm-Message-State: ANoB5pnpaHo6kex2oXyeEYnlZ+YizqxmRQqK6vY46oxBgdZaQbrDvQLC VU5yq4NK+WBowOPffiAe2XPv+WBKZNGIyYiL X-Google-Smtp-Source: AA0mqf74+ga2YbTxc45X7c9fsOcP1qV6z43olC4C8vmGeiqSTbxz4qHn5Zyf4dHgBvW3fq4TP2VO/g== X-Received: by 2002:a5d:6206:0:b0:241:e3b8:e1a5 with SMTP id y6-20020a5d6206000000b00241e3b8e1a5mr41497493wru.651.1670335341464; Tue, 06 Dec 2022 06:02:21 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id n186-20020a1ca4c3000000b003d1cf67460esm6316339wme.40.2022.12.06.06.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:02:21 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Suppress warning for specific constant valid condition Date: Tue, 6 Dec 2022 15:02:19 +0100 Message-Id: <20221206140219.717392-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Eric Botcazou 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))