From patchwork Tue Jan 11 13:31:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1578469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nUVLKCfc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JYBmm5qmBz9s0r for ; Wed, 12 Jan 2022 00:46:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F0C8385781F for ; Tue, 11 Jan 2022 13:46:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F0C8385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641908773; bh=XhBmdk90bBT1U32+b2XQ08cRo2/AopZ9UJaK7jpN9ZI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nUVLKCfcnEEIHKXBMjAMywP3dRSm1H+pa9rbAECNxq0jWe76mxlbPEt2tc7zWVSB7 6Ddij0I13GddwU3x09aKt3cysV5IWLo0z9g7O1NfmClrzUDTmqAkVYkV7QuW5R1SFJ a1LHZ6cS7v96eKK31BaI/QbKGRoZeVrBy4GCRPo4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 9F3C838A9435 for ; Tue, 11 Jan 2022 13:32:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9F3C838A9435 Received: by mail-wm1-x332.google.com with SMTP id p18so4254995wmg.4 for ; Tue, 11 Jan 2022 05:32:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=XhBmdk90bBT1U32+b2XQ08cRo2/AopZ9UJaK7jpN9ZI=; b=4QsGwdTZkjgjQ9ajMmjNH3mxmvGkLHOaHqeVFchtSKJm8bZLv/uZPvnrIL8/1faxz8 EUtLyaXjVFdRrEkVIBpHOzRulS3Q+ppYamhAX45/LETQEPf9vuqZYF26HAjj7B4fOpRZ aaT4Xzt8ihrGnf2MV10dsX0MuNuKPD3BpKj62ZMPZkAYUUQr6BPUmP1khg4bt1rsZvwW wbJ3tDPVMiECm/rynHKjG/zvFeqgb8U6dZEprK/AKZbYZDK0sE6xNHw+2/BUE7ssczz8 Y2BoW1mQEsd9sNVnQjYQ1+lq51bG+eN/L5/6VRlg4mdunmiQ6CrIxqdIj99Tc1cMbCOT WJUA== X-Gm-Message-State: AOAM530STsdQ8H3C9HRpQHdE3yXGTOzRI3R0RAMiQ7UemKg1tOJhHjCN AVdG5PXMbXjnmNkib0sDVuI1zEFkKora/Q== X-Google-Smtp-Source: ABdhPJxid5xjswhNROgtObX6rimM5fixHy4+0QV5o+fYGySjsqo5FozX2ORfTzmikHtn9ulbS5U1Sg== X-Received: by 2002:a1c:f302:: with SMTP id q2mr2458302wmq.107.1641907921515; Tue, 11 Jan 2022 05:32:01 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id az1sm9588670wrb.104.2022.01.11.05.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:32:00 -0800 (PST) Date: Tue, 11 Jan 2022 13:31:59 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Remove warnings-as-errors about constraints error in dead code Message-ID: <20220111133159.GA748519@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" GNAT removes error messages attached to nodes within dead code; in particular, within instances of generic units with alternative branches for different generic formal types and parameters. Now this removal also works for error messages that come from warnings about constraint errors that have been escalated into hard errors due to -gnatwE switch. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * erroutc.ads, erroutc.adb (Is_Runtime_Raise): Global flag to connect status of initial messages and their continuation; we already have several flags like this. (Error_Msg_Object): Add field Warn_Runtime_Raise to connect error reporting (when problematic code is found) and removal (when problematic code is determined to be dead). * errout.adb (Error_Msg_Internal): Handle new field when recording a continuation message; propagate status from continuation to the preceding messages. (To_Be_Removed): For dead code remove both simple warnings and warnings about constraint errors that have been escalated to hard errors. (Set_Msg_Text): Recognize warnings about constraint errors that are escalated to hard errors. * errutil.adb (Error_Msg): Handle added field when recording a new message. diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -1224,6 +1224,7 @@ package body Errout is Check => Is_Check_Msg, Warn_Err => False, -- reset below Warn_Chr => Warning_Msg_Char, + Warn_Runtime_Raise => Is_Runtime_Raise, Style => Is_Style_Msg, Serious => Is_Serious_Error, Uncond => Is_Unconditional_Msg, @@ -1241,12 +1242,14 @@ package body Errout is Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg))); -- Propagate Warn_Err to this message and preceding continuations. - -- Likewise, propagate Is_Warning_Msg, because the current continued - -- message could have been escalated from warning to error. + -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the + -- current continued message could have been escalated from warning to + -- error. for J in reverse 1 .. Errors.Last loop - Errors.Table (J).Warn_Err := Warn_Err; - Errors.Table (J).Warn := Is_Warning_Msg; + Errors.Table (J).Warn_Err := Warn_Err; + Errors.Table (J).Warn := Is_Warning_Msg; + Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise; exit when not Errors.Table (J).Msg_Cont; end loop; @@ -3290,13 +3293,17 @@ package body Errout is -- not remove style messages here. They are warning messages -- but not ones we want removed in this context. - and then Errors.Table (E).Warn + and then (Errors.Table (E).Warn + or else + Errors.Table (E).Warn_Runtime_Raise) -- Don't remove unconditional messages and then not Errors.Table (E).Uncond then - Warnings_Detected := Warnings_Detected - 1; + if Errors.Table (E).Warn then + Warnings_Detected := Warnings_Detected - 1; + end if; if Errors.Table (E).Info then Warning_Info_Messages := Warning_Info_Messages - 1; @@ -4072,7 +4079,8 @@ package body Errout is if Is_Warning_Msg and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors then - Is_Warning_Msg := False; + Is_Warning_Msg := False; + Is_Runtime_Raise := True; end if; if Is_Warning_Msg then diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb --- a/gcc/ada/erroutc.adb +++ b/gcc/ada/erroutc.adb @@ -902,6 +902,7 @@ package body Erroutc is Is_Serious_Error := True; Is_Unconditional_Msg := False; Is_Warning_Msg := False; + Is_Runtime_Raise := False; -- Check style message diff --git a/gcc/ada/erroutc.ads b/gcc/ada/erroutc.ads --- a/gcc/ada/erroutc.ads +++ b/gcc/ada/erroutc.ads @@ -71,6 +71,11 @@ package Erroutc is -- Set True to indicate if current message is warning message (contains ? -- or contains < and Error_Msg_Warn is True). + Is_Runtime_Raise : Boolean := False; + -- Set to True to indicate that the current message is a warning about a + -- constraint error that will be raised at runtime (contains [ and switch + -- -gnatwE was given). + Is_Info_Msg : Boolean := False; -- Set True to indicate that the current message starts with the characters -- "info: " and is to be treated as an information message. This string @@ -239,6 +244,10 @@ package Erroutc is -- True if this is a warning message which is to be treated as an error -- as a result of a match with a Warning_As_Error pragma. + Warn_Runtime_Raise : Boolean; + -- True if this a warning about a constraint error that will be raised + -- at runtime. + Warn_Chr : String (1 .. 2); -- See Warning_Msg_Char diff --git a/gcc/ada/errutil.adb b/gcc/ada/errutil.adb --- a/gcc/ada/errutil.adb +++ b/gcc/ada/errutil.adb @@ -217,6 +217,7 @@ package body Errutil is Info => Is_Info_Msg, Check => Is_Check_Msg, Warn_Err => Warning_Mode = Treat_As_Error, + Warn_Runtime_Raise => Is_Runtime_Raise, Warn_Chr => Warning_Msg_Char, Style => Is_Style_Msg, Serious => Is_Serious_Error,