From patchwork Thu Jun 20 08:52:54 2024 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: 1949990 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=Ex8pXb91; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W4ZBk2YK9z20X8 for ; Thu, 20 Jun 2024 18:57:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8017C388A413 for ; Thu, 20 Jun 2024 08:57:48 +0000 (GMT) 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 40FB3388981C for ; Thu, 20 Jun 2024 08:53:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40FB3388981C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 40FB3388981C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873624; cv=none; b=owVr30tHLtd/j52PZDWG/rSMLVQVEejEZIpzncQmZb9wnCMrv+sUe5FCA6OxsvUv7G+eqWK0bwb6BERypaPDrhVqb0ZXs1RaX+JicLWIXMw/ntP8BwqujVR8/XW6WWdWK6HljBf86wFSn7gQ6qSEQ31zGM4IMSNBYABSl64BS+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873624; c=relaxed/simple; bh=bXOg1DqCCDnsJxn/kB+m2iZd6nmHT5Zzjp8FAYbqURo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XHqav+cCa4d7SwaezmUy7CzmRkNNX5eo7B4S7XBguEOxc2PnhLf0HkM5D/bszAYWLP1xzqiqkJAzHg+IxkDD88SSHCzmYPcfmO/wAvFueCW9wwOo2hZb/vkunohXBQHlLcNLIpqpQ4lyYcfFjYWIYmkoMz6DrsnVKa5/kxpjyFU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-354b722fe81so441967f8f.3 for ; Thu, 20 Jun 2024 01:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718873614; x=1719478414; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pFK+uyrT00tGAjseZG99COUWFZoD42g1R94Dwbecuk0=; b=Ex8pXb916mv4sipIEr8w/DtRyb4WPNpUqbdHrNWc5AQUmIX1mKqoskVDweYnuaOL2L UWmEb63545FUpn51Js+OGvdyCexUNDVjb+8C7lVjNnuKU+X4tZdAV+K69KlsVBy05pb0 WPfUo9THILpFBhakDlJ79OaDRbm4l5QsvxMCMSS/iqh2veyEHlee/OOu6S1W807PflpL xAHqnMBa/2rq0ctMxRpGT6ORmL6WGdZVqSFrLRi6GwT6sPzz9mscMe0BdTGf90KrO2+Z wd1BnOlM+j/jh7smXYdVTv4oJ5ddZyGmWXAiCsUnQTNng5Yqmdp1Hw/3WykAB90kNMqQ Rh5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873614; x=1719478414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pFK+uyrT00tGAjseZG99COUWFZoD42g1R94Dwbecuk0=; b=mXP/TmBZqyd3tFLZBDf9P2dmvFbPUfXWr62IGpx38ap4TC982J7BkmBlHVaOWuoDSO 88cHIVs/zlZQMCTcWQdnvY1+g8HNfYUTEcqtZep5pP5oU/36gS6NTOP/YdsVINAdXwhl s1zx0jKWL423BTs5cFQMoAkSKxpqKcbCgDN5AFoTnuQRK7+8NFU7txMHFr3j+6WnWOXX +TcMdZFs/yAHFSsq1OKyKu5H+O4QCEPc3V0DUyyXwKIZaeGJtftrqzcOLve9cbXHeXYE pUSW/rD5s74eTr132S9RuBdtj6w/sorIdp6uvtXkRQA70iKtD8tzBDLSqTigqfgKvFtQ faFA== X-Gm-Message-State: AOJu0YxnNYPFn22JzYHDpWB1I9rMN+ii/9Nj5UGHqIHmANa/YsKWPdj4 fVbfidqa6gPaW0MejwnLAd9523ZAeJyH5o6gmSOforP3oiwDU4VR2fKv+HiaCFYDMQ2S5v3z2fc = X-Google-Smtp-Source: AGHT+IGA2x5//cH9lhr/mv6pc99noabAb7V12W3MXAsvS0I4WctdmwlFvpgmWtpUHg6e0APBB3Qm0A== X-Received: by 2002:a05:6000:114d:b0:362:2db5:b07f with SMTP id ffacd0b85a97d-363195b1987mr3296823f8f.44.1718873613904; Thu, 20 Jun 2024 01:53:33 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-363c795febfsm3305522f8f.104.2024.06.20.01.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 01:53:33 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED 04/30] ada: Treat Info-Warnings as Info messages Date: Thu, 20 Jun 2024 10:52:54 +0200 Message-ID: <20240620085321.2412421-4-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620085321.2412421-1-poulhies@adacore.com> References: <20240620085321.2412421-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Viljar Indus There was a general concept of info messages being a subset of warnings. However that is no longer the case. Messages with an info insertion character should be treated just as info messages. gcc/ada/ * atree.ads: Remove Warning_Info_Messages. * errout.adb: Remove various places where Warning_Info_Messages was used. * erroutc.adb: Remove various places where Warning_Info_Messages was used. Create Error_Msg_Object objects with only an info attribute if the message contained both info and warning insertion characters. New method Has_Switch_Tag for detecting if a message should have an error tag. * errutil.adb: Create Error_Msg_Object objects with only an info attribute if the message contained both info and warning insertion characters. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/atree.ads | 10 ++---- gcc/ada/errout.adb | 80 +++++++++++++++++++++++++-------------------- gcc/ada/erroutc.adb | 51 ++++++++++++++++++++--------- gcc/ada/errutil.adb | 31 ++++++++---------- 4 files changed, 96 insertions(+), 76 deletions(-) diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads index 2ecb386c23b..834cc3150f5 100644 --- a/gcc/ada/atree.ads +++ b/gcc/ada/atree.ads @@ -161,15 +161,11 @@ package Atree is -- Number of warnings detected. Initialized to zero at the start of -- compilation. This count includes the count of style and info messages. - Warning_Info_Messages : Nat := 0; - -- Number of info messages generated as warnings. Info messages are never - -- treated as errors (whether from use of the pragma, or the compiler - -- switch -gnatwe). - - Report_Info_Messages : Nat := 0; + Info_Messages : Nat := 0; -- Number of info messages generated as reports. Info messages are never -- treated as errors (whether from use of the pragma, or the compiler - -- switch -gnatwe). Used under Spark_Mode to report proved checks. + -- switch -gnatwe). Used by GNATprove under SPARK_Mode to report proved + -- checks. Check_Messages : Nat := 0; -- Number of check messages generated. Check messages are neither warnings diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 76c461a2fd7..1e6b0fe4369 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -283,10 +283,6 @@ package body Errout is M.Deleted := True; Warnings_Detected := Warnings_Detected - 1; - if M.Info then - Warning_Info_Messages := Warning_Info_Messages - 1; - end if; - if M.Warn_Err then Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1; end if; @@ -428,7 +424,8 @@ package body Errout is -- that style checks are not considered warning messages for this -- purpose. - if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String + if Is_Warning_Msg + and then Warnings_Suppressed (Orig_Loc) /= No_String then return; @@ -1049,6 +1046,33 @@ package body Errout is return; end if; + if Is_Info_Msg then + + -- If the flag location is in the main extended source unit then for + -- sure we want the message since it definitely belongs. + + if In_Extended_Main_Source_Unit (Sptr) then + null; + + -- Keep info message if message text contains !! + + elsif Has_Double_Exclam then + null; + + -- Here is where we delete a message from a with'ed unit + + else + Cur_Msg := No_Error_Msg; + + if not Continuation then + Last_Killed := True; + end if; + + return; + end if; + + end if; + -- Special check for warning message to see if it should be output if Is_Warning_Msg then @@ -1064,7 +1088,7 @@ package body Errout is end if; -- If the flag location is in the main extended source unit then for - -- sure we want the warning since it definitely belongs + -- sure we want the warning since it definitely belongs. if In_Extended_Main_Source_Unit (Sptr) then null; @@ -1210,6 +1234,11 @@ package body Errout is return; end if; + -- Warning, Style and Info attributes are mutually exclusive + + pragma Assert (Boolean'Pos (Is_Warning_Msg) + Boolean'Pos (Is_Info_Msg) + + Boolean'Pos (Is_Style_Msg) <= 1); + -- Here we build a new error object Errors.Append @@ -1384,15 +1413,7 @@ package body Errout is -- Bump appropriate statistics counts if Errors.Table (Cur_Msg).Info then - - -- Could be (usually is) both "info" and "warning" - - if Errors.Table (Cur_Msg).Warn then - Warning_Info_Messages := Warning_Info_Messages + 1; - Warnings_Detected := Warnings_Detected + 1; - else - Report_Info_Messages := Report_Info_Messages + 1; - end if; + Info_Messages := Info_Messages + 1; elsif Errors.Table (Cur_Msg).Warn or else Errors.Table (Cur_Msg).Style @@ -1648,10 +1669,6 @@ package body Errout is if not Errors.Table (E).Deleted then Errors.Table (E).Deleted := True; Warnings_Detected := Warnings_Detected - 1; - - if Errors.Table (E).Info then - Warning_Info_Messages := Warning_Info_Messages - 1; - end if; end if; end Delete_Warning; @@ -1695,7 +1712,8 @@ package body Errout is Tag : constant String := Get_Warning_Tag (Cur); begin - if (CE.Warn and not CE.Deleted) + if CE.Warn + and then not CE.Deleted and then (Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag) /= No_String @@ -1968,7 +1986,6 @@ package body Errout is Warnings_Treated_As_Errors := 0; Warnings_Detected := 0; - Warning_Info_Messages := 0; Warnings_As_Errors_Count := 0; -- Initialize warnings tables @@ -2640,8 +2657,7 @@ package body Errout is -- are also errors. declare - Warnings_Count : constant Int := - Warnings_Detected - Warning_Info_Messages; + Warnings_Count : constant Int := Warnings_Detected; Compile_Time_Warnings : Int; -- Number of warnings that come from a Compile_Time_Warning @@ -2702,12 +2718,12 @@ package body Errout is end if; end; - if Warning_Info_Messages + Report_Info_Messages /= 0 then + if Info_Messages /= 0 then Write_Str (", "); - Write_Int (Warning_Info_Messages + Report_Info_Messages); + Write_Int (Info_Messages); Write_Str (" info message"); - if Warning_Info_Messages + Report_Info_Messages > 1 then + if Info_Messages > 1 then Write_Char ('s'); end if; end if; @@ -3419,23 +3435,19 @@ package body Errout is Write_Max_Errors; end if; - -- Even though Warning_Info_Messages are a subclass of warnings, they - -- must not be treated as errors when -gnatwe is in effect. - if Warning_Mode = Treat_As_Error then declare Compile_Time_Pragma_Warnings : constant Nat := Count_Compile_Time_Pragma_Warnings; Total : constant Int := Total_Errors_Detected + Warnings_Detected - - Warning_Info_Messages - Compile_Time_Pragma_Warnings; + - Compile_Time_Pragma_Warnings; -- We need to protect against a negative Total here, because -- if a pragma Compile_Time_Warning occurs in dead code, it -- gets counted in Compile_Time_Pragma_Warnings but not in -- Warnings_Detected. begin Total_Errors_Detected := Int'Max (Total, 0); - Warnings_Detected := - Warning_Info_Messages + Compile_Time_Pragma_Warnings; + Warnings_Detected := Compile_Time_Pragma_Warnings; end; end if; end Output_Messages; @@ -3630,10 +3642,6 @@ package body Errout is Warnings_Detected := Warnings_Detected - 1; end if; - if Errors.Table (E).Info then - Warning_Info_Messages := Warning_Info_Messages - 1; - end if; - -- When warning about a runtime exception has been escalated -- into error, the starting message has increased the total -- errors counter, so here we decrease this counter. diff --git a/gcc/ada/erroutc.adb b/gcc/ada/erroutc.adb index f404018c44d..aa9aac4774f 100644 --- a/gcc/ada/erroutc.adb +++ b/gcc/ada/erroutc.adb @@ -59,6 +59,11 @@ package body Erroutc is -- from generic instantiations by using pragma Warnings around generic -- instances, as needed in GNATprove. + function Has_Switch_Tag (Id : Error_Msg_Id) return Boolean; + function Has_Switch_Tag (E_Msg : Error_Msg_Object) return Boolean; + -- Returns True if the E_Msg is Warning, Style or Info and has a non-empty + -- Warn_Char. + --------------- -- Add_Class -- --------------- @@ -144,12 +149,7 @@ package body Erroutc is if Errors.Table (D).Info then - if Errors.Table (D).Warn then - Warning_Info_Messages := Warning_Info_Messages - 1; - Warnings_Detected := Warnings_Detected - 1; - else - Report_Info_Messages := Report_Info_Messages - 1; - end if; + Info_Messages := Info_Messages - 1; elsif Errors.Table (D).Warn or else Errors.Table (D).Style then Warnings_Detected := Warnings_Detected - 1; @@ -246,8 +246,7 @@ package body Erroutc is ------------------------ function Compilation_Errors return Boolean is - Warnings_Count : constant Int - := Warnings_Detected - Warning_Info_Messages; + Warnings_Count : constant Int := Warnings_Detected; begin if Total_Errors_Detected /= 0 then return True; @@ -330,6 +329,7 @@ package body Erroutc is w (" Line = ", Int (E.Line)); w (" Col = ", Int (E.Col)); + w (" Info = ", E.Info); w (" Warn = ", E.Warn); w (" Warn_Err = ", E.Warn_Err); w (" Warn_Runtime_Raise = ", E.Warn_Runtime_Raise); @@ -366,13 +366,11 @@ package body Erroutc is ------------------------ function Get_Warning_Option (Id : Error_Msg_Id) return String is - Warn : constant Boolean := Errors.Table (Id).Warn; Style : constant Boolean := Errors.Table (Id).Style; Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr; begin - if (Warn or Style) - and then Warn_Chr /= " " + if Has_Switch_Tag (Errors.Table (Id)) and then Warn_Chr (1) /= '?' then if Warn_Chr = "$ " then @@ -394,13 +392,11 @@ package body Erroutc is --------------------- function Get_Warning_Tag (Id : Error_Msg_Id) return String is - Warn : constant Boolean := Errors.Table (Id).Warn; - Style : constant Boolean := Errors.Table (Id).Style; Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr; Option : constant String := Get_Warning_Option (Id); begin - if Warn or Style then + if Has_Switch_Tag (Id) then if Warn_Chr = "? " then return "[enabled by default]"; elsif Warn_Chr = "* " then @@ -413,6 +409,23 @@ package body Erroutc is return ""; end Get_Warning_Tag; + -------------------- + -- Has_Switch_Tag -- + -------------------- + + function Has_Switch_Tag (Id : Error_Msg_Id) return Boolean + is (Has_Switch_Tag (Errors.Table (Id))); + + function Has_Switch_Tag (E_Msg : Error_Msg_Object) return Boolean + is + Warn : constant Boolean := E_Msg.Warn; + Style : constant Boolean := E_Msg.Style; + Info : constant Boolean := E_Msg.Info; + Warn_Chr : constant String (1 .. 2) := E_Msg.Warn_Chr; + begin + return (Warn or Style or Info) and then Warn_Chr /= " "; + end Has_Switch_Tag; + ------------- -- Matches -- ------------- @@ -918,6 +931,7 @@ package body Erroutc is Is_Unconditional_Msg := False; Is_Warning_Msg := False; Is_Runtime_Raise := False; + Warning_Msg_Char := " "; -- Check style message @@ -962,7 +976,14 @@ package body Erroutc is elsif Msg (J) = '?' or else Msg (J) = '<' then if Msg (J) = '?' or else Error_Msg_Warn then - Is_Warning_Msg := not Is_Style_Msg; + + -- Consider Info and Style messages as unique message types. + -- Those messages can have warning insertion characters within + -- them. However they should only be switch specific insertion + -- characters and not the generic ? or ?? warning insertion + -- characters. + + Is_Warning_Msg := not (Is_Style_Msg or else Is_Info_Msg); J := J + 1; Warning_Msg_Char := Parse_Message_Class; diff --git a/gcc/ada/errutil.adb b/gcc/ada/errutil.adb index 4f5aa216461..6747fe59d24 100644 --- a/gcc/ada/errutil.adb +++ b/gcc/ada/errutil.adb @@ -199,6 +199,11 @@ package body Errutil is return; end if; + -- Warning, Style and Info attributes are mutually exclusive + + pragma Assert (Boolean'Pos (Is_Warning_Msg) + Boolean'Pos (Is_Info_Msg) + + Boolean'Pos (Is_Style_Msg) <= 1); + -- Otherwise build error message object for new message Errors.Append @@ -308,15 +313,7 @@ package body Errutil is -- Bump appropriate statistics counts if Errors.Table (Cur_Msg).Info then - - -- Could be (usually is) both "info" and "warning" - - if Errors.Table (Cur_Msg).Warn then - Warning_Info_Messages := Warning_Info_Messages + 1; - Warnings_Detected := Warnings_Detected + 1; - else - Report_Info_Messages := Report_Info_Messages + 1; - end if; + Info_Messages := Info_Messages + 1; elsif Errors.Table (Cur_Msg).Warn or else Errors.Table (Cur_Msg).Style @@ -553,19 +550,19 @@ package body Errutil is Write_Str (" errors"); end if; - if Warnings_Detected - Warning_Info_Messages /= 0 then + if Warnings_Detected /= 0 then Write_Str (", "); - Write_Int (Warnings_Detected - Warning_Info_Messages); + Write_Int (Warnings_Detected); Write_Str (" warning"); - if Warnings_Detected - Warning_Info_Messages /= 1 then + if Warnings_Detected /= 1 then Write_Char ('s'); end if; if Warning_Mode = Treat_As_Error then Write_Str (" (treated as error"); - if Warnings_Detected - Warning_Info_Messages /= 1 then + if Warnings_Detected /= 1 then Write_Char ('s'); end if; @@ -595,9 +592,8 @@ package body Errutil is -- must not be treated as errors when -gnatwe is in effect. if Warning_Mode = Treat_As_Error then - Total_Errors_Detected := - Total_Errors_Detected + Warnings_Detected - Warning_Info_Messages; - Warnings_Detected := Warning_Info_Messages; + Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected; + Warnings_Detected := 0; end if; -- Prevent displaying the same messages again in the future @@ -617,8 +613,7 @@ package body Errutil is Serious_Errors_Detected := 0; Total_Errors_Detected := 0; Warnings_Detected := 0; - Warning_Info_Messages := 0; - Report_Info_Messages := 0; + Info_Messages := 0; Cur_Msg := No_Error_Msg; -- Initialize warnings table, if all warnings are suppressed, supply