From patchwork Mon Sep 12 08:19:16 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: 1136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1779362wrt; Mon, 12 Sep 2022 01:21:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR5C33uWg7Dw5jyQe8CnXXiXn8adJladE+/DEe/MxY/4RqVZGAMQ0+9utEze4GrPRRLh7Sxp X-Received: by 2002:a17:907:97c6:b0:771:edd:d86d with SMTP id js6-20020a17090797c600b007710eddd86dmr16226940ejc.618.1662970893786; Mon, 12 Sep 2022 01:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662970893; cv=none; d=google.com; s=arc-20160816; b=Qfy4VxmxXDRnA0mo0FN0XuOpDKFbemmcgxG+WAoHZvk2KBVlKtxpBK5T34cm/dCBiC vuwMRFf3Ku0hWGnVZeYPfDgeLEd6TJ7z2ppDYYrYn/VLOu6jffjF+dG9oKq6eOQk4iHd penxf4+9zJR6Z20bd/pLquf9noPpw1VHjg91tsihafOGq1KJ0yPN/SuTNf6/ondvjs4E cfRTRutBOTUHhEyXBqHTXEGTYm8UJZth3+1yTdrU95nriJ4qNTvad3ZSzOR5A18OhaqV Z8kaB+N7l5cThWuC+yppZvKhsWaiaFw88Za/VvLGpbd+7NvgR1t4AMV4phNGSsFLTkax xEfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=sRRNynWbQpiCB6efwv5KwTU9Apk5r+VU5q7QKaJ24d4=; b=AOuuceOMv1WMaOYdlMKeYkZEEz6x13+dxAaLP6RxJTj96ySTnxwug067nDiCG93k1X s17yJfcJKOlKuN/M0+kM3p2/Zba5nDAoyfEX8BNNgsJZqabc8UHxdjFO7k67cNVzfn4q sSTrEKdrKc+ZQhVPeaaAvGiC4QXOCVVwlCmjH+Na74w17FJIkiSyZHCp7hnZVVMzoxdf tSrY8sbtE9PCv+ig/9XyTHiwPKy9cWF2W0hpjcp+fQL20ZBKiFyF7VSSRjmQgcAKNhnt 7ueQuTe8VfwdpWm4K3QI7m7CEkQ9U9xjOw5wzBvayO9k3v86ielSQPosBXxEC+kqwTJX VlMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vD6DnUun; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f20-20020a056402195400b0045196fd6a9dsi2836029edz.477.2022.09.12.01.21.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:21:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vD6DnUun; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B881385084F for ; Mon, 12 Sep 2022 08:20:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B881385084F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662970824; bh=sRRNynWbQpiCB6efwv5KwTU9Apk5r+VU5q7QKaJ24d4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vD6DnUunXHV1IzTSHChi0z9lF26BhhbAJMTVMBNp1XMsKAnLcibv0I2iQpg4ptBy6 43JjkFoP7t4Bc2BLnayrgrAz2xLta49Taqk1NZc+e4bZNOHkzp7FZHFs7LjUaSdv5A TW/q8zVUUw0ZM64laTv7ETy6eARX+diLID56Rw6E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 488F43857017 for ; Mon, 12 Sep 2022 08:19:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 488F43857017 Received: by mail-wr1-x436.google.com with SMTP id d2so14085136wrn.1 for ; Mon, 12 Sep 2022 01:19:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=sRRNynWbQpiCB6efwv5KwTU9Apk5r+VU5q7QKaJ24d4=; b=6vjQOsnde2p3ywKOAblJJF5j4ef5VcL+aXLgPVd5EY5iyLAA3YXzf1i1HwtXAS6tfD KEpSQCKCZbdM42dtiZr9afShK01SK1te0cGW1xJM117zhIcUMxXPxIp9MERvCKYhJaX/ d+E2K2Y47JdBvSByeS6SFeouXvr2TKmqBU3hvm0I+uudj/bqLVW4oy9yIid2IJN5YOje MAFEMuLVa9FVYoI2Fki0jnU7CIDX6VjfiAXKc1QXlkDhJtgnuEAoBQEvZ0Fk5PRLR7wr v8Sy/7+kXURi88iY1VDi5IwpdndnCJqej/QS5/6fUZtC7WcATZTVuxhN/5g4aNyrkBZ0 BTuQ== X-Gm-Message-State: ACgBeo1EoBPIBHfMZZ/wFH95MLO92BM0IzhCdLhjdFgFCgAdsdYUZICW jxQ8KuaTkFacaj4nPt9KnaC7x9fwaHIjEw== X-Received: by 2002:adf:fc91:0:b0:228:afa5:2432 with SMTP id g17-20020adffc91000000b00228afa52432mr14244432wrr.255.1662970758133; Mon, 12 Sep 2022 01:19:18 -0700 (PDT) Received: from poulhies-Precision-5550 (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id t6-20020a5d5346000000b00228e071baadsm7798262wrv.36.2022.09.12.01.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:19:17 -0700 (PDT) Date: Mon, 12 Sep 2022 10:19:16 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix bugs in check-related warnings. Message-ID: <20220912081916.GA1512813@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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.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: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Bob Duff Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743751367767135192?= X-GMAIL-MSGID: =?utf-8?q?1743751367767135192?= Make sure warnings about wrong-length aggregates don't get suppressed. Such a warning (in a with-ed unit) can be the only explanation for an error about No_Elaboration_Code violations. Avoid passing a bogus "#" to Error_Msg. We really should never construct message templates by concatenating strings that can come from input data, but there are too many cases of that to clean up. The message template parameters should really be of a type other than String, to avoid these kinds of bugs, but again, that's too much work to clean up now. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * checks.adb (Selected_Length_Checks): In the message for an aggregate that has too few or too many elements, add "!!" to make sure the warning gets printed in with'ed units. Note that we have to put "!!" before the "??", because Compile_Time_Constraint_Error detects warnings by comparing the last character of the message with '?' (which is bit dubious, but we're not changing that here). (Length_Mismatch_Info_Message): Use Unat for some things that can't be negative. Specify Decimal instead of Auto in calls to UI_Image. * sem_util.adb (Compile_Time_Constraint_Error): Minor. * uintp.adb (Image_Uint): It's always better to initialize objects on their declaration. diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -9951,8 +9951,8 @@ package body Checks is -- Typ'Length /= Exp'Length function Length_Mismatch_Info_Message - (Left_Element_Count : Uint; - Right_Element_Count : Uint) return String; + (Left_Element_Count : Unat; + Right_Element_Count : Unat) return String; -- Returns a message indicating how many elements were expected -- (Left_Element_Count) and how many were found (Right_Element_Count). @@ -10150,14 +10150,14 @@ package body Checks is ---------------------------------- function Length_Mismatch_Info_Message - (Left_Element_Count : Uint; - Right_Element_Count : Uint) return String + (Left_Element_Count : Unat; + Right_Element_Count : Unat) return String is - function Plural_Vs_Singular_Ending (Count : Uint) return String; + function Plural_Vs_Singular_Ending (Count : Unat) return String; -- Returns an empty string if Count is 1; otherwise returns "s" - function Plural_Vs_Singular_Ending (Count : Uint) return String is + function Plural_Vs_Singular_Ending (Count : Unat) return String is begin if Count = 1 then return ""; @@ -10167,12 +10167,19 @@ package body Checks is end Plural_Vs_Singular_Ending; begin - return "expected " & UI_Image (Left_Element_Count) + return "expected " + & UI_Image (Left_Element_Count, Format => Decimal) & " element" & Plural_Vs_Singular_Ending (Left_Element_Count) - & "; found " & UI_Image (Right_Element_Count) + & "; found " + & UI_Image (Right_Element_Count, Format => Decimal) & " element" & Plural_Vs_Singular_Ending (Right_Element_Count); + -- "Format => Decimal" above is needed because otherwise UI_Image + -- can sometimes return a hexadecimal number 16#...#, but "#" means + -- something special to Errout. A previous version used the default + -- Auto, which was essentially the same bug as documented here: + -- https://xkcd.com/327/ . end Length_Mismatch_Info_Message; ----------------- @@ -10371,14 +10378,14 @@ package body Checks is if L_Length > R_Length then Add_Check (Compile_Time_Constraint_Error - (Wnode, "too few elements for}??", T_Typ, + (Wnode, "too few elements for}!!??", T_Typ, Extra_Msg => Length_Mismatch_Info_Message (L_Length, R_Length))); elsif L_Length < R_Length then Add_Check (Compile_Time_Constraint_Error - (Wnode, "too many elements for}??", T_Typ, + (Wnode, "too many elements for}!!??", T_Typ, Extra_Msg => Length_Mismatch_Info_Message (L_Length, R_Length))); end if; diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6691,8 +6691,6 @@ package body Sem_Util is Wmsg : Boolean; Eloc : Source_Ptr; - -- Start of processing for Compile_Time_Constraint_Error - begin -- If this is a warning, convert it into an error if we are in code -- subject to SPARK_Mode being set On, unless Warn is True to force a diff --git a/gcc/ada/uintp.adb b/gcc/ada/uintp.adb --- a/gcc/ada/uintp.adb +++ b/gcc/ada/uintp.adb @@ -300,11 +300,9 @@ package body Uintp is function Better_In_Hex return Boolean is T16 : constant Valid_Uint := Uint_2**Int'(16); - A : Valid_Uint; + A : Valid_Uint := UI_Abs (Input); begin - A := UI_Abs (Input); - -- Small values up to 2**16 can always be in decimal if A < T16 then