From patchwork Mon Oct 16 13:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wright X-Patchwork-Id: 153406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3463490vqb; Mon, 16 Oct 2023 06:33:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOLcq+s24Y8BZxc775Pk64yOuWFoSWqkfvfcCU96gfUFi8uebbhovQYdzRkNp2C1yCopKz X-Received: by 2002:a05:620a:22f3:b0:772:63b3:1ad2 with SMTP id p19-20020a05620a22f300b0077263b31ad2mr32152212qki.29.1697463200316; Mon, 16 Oct 2023 06:33:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697463200; cv=pass; d=google.com; s=arc-20160816; b=c8AGQPx9ewe4WBm5uuez8EZfyKEXsd4VZJ0rAqMfyhVSgiiQ19nwa3c/J3gCmsMvQ/ n+npMqO11B7KiMYYDTJb25r/vjqjLz5gqDh75dXEgmcydowmEDYQUIFcl8uYyz1I9vGB VmThGvVu2p5ufLll2A7dN6/bbctMdjI7xgLAzMjm1dLEjdAQC9XWiMrNr6PRcZGAAvmN tssHWwBLr5VnkwMPJPQR0qkPFKFtiLNHccs3C8rgxGbcNVLpCwgRjJWURpvJyccM7iFG /n6rmSZtaBsERXku9w/Usr2paOJ9WolSRDXBD1bu1igDTg304Dtfjq8q5yGa77EW+FyB XKaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:date:message-id:subject :mime-version:content-transfer-encoding:from:arc-filter:dmarc-filter :delivered-to; bh=xhXyD+WHt+ae8WGk/CHHmiQlPzXuzyNjIHB0vNke95g=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=DRWSDqovflvCciPNu6CiSVFwDPvu5shbPS0Kt1fldoF+x0cecQPxqRv/V8AfvFVvhV o9GoUUve1zWg00vuAt/aq4y0B7CxqhzRH4a5uq8TVJMX9sIkPPy5NhxzOGcfQCDEXw92 SWRXew8n+2H6iOXeAwmn5NQfNl9AzWeE2oyh5iNjCp8GcIVg7e41wvZmU57oT4tR8W7w Rnz7kxLdvzg0UXTRFtr/kdyosOg0kRPK5yLmRbP+410AGfAY7slWI2BP7mEZZf1o63Np ueZpx74uexDMKKEZM5UQYMNgJ3FbTQGRmrG37SLBawqRbpW1tgMc/snNbySMzsy/U0uu ZR6w== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id tp1-20020a05620a3c8100b007759ca123b0si5051454qkn.439.2023.10.16.06.33.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 06:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CD2E3858039 for ; Mon, 16 Oct 2023 13:33:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.hosts.co.uk (smtp.hosts.co.uk [85.233.160.19]) by sourceware.org (Postfix) with ESMTPS id 56B2338582AC for ; Mon, 16 Oct 2023 13:32:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56B2338582AC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=pushface.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=pushface.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 56B2338582AC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=85.233.160.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697463176; cv=none; b=utxo6meJOsEZKJQhazGQgk8feDTk6VtX55bh1A7uv9NuXmRS0XEOYKLsDs+Qp4OaWBQfQqsGJyVqTSPyH9/DV4mNtq/5QRMBzFqZNESovZ8CqUhh3v6UAImlOxVYCI/YBwwDZNxPtbE3G2AiFMBMHGNI0xclblvcL9IXv6DNhg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697463176; c=relaxed/simple; bh=E4jXwJUNVUKDcDdB20vbi/pRzHmQQ5rD/dnQqg9jcI8=; h=From:Mime-Version:Subject:Message-Id:Date:To; b=DrszJ6pD8LXb2u/zO/wuZe39x2MWiDxE6d2sNNmSa3eZzsXTCJ7SSMqfVVDGNO2qhETJlBCSe2FfjXjsajODkoXtghJ5/jzSgtbBZ0kFq0cQXVJAnHu0Y5DGTSKh1BTkgonXkY2rGw/oZB7BzSnvf12V2hi/ecjpKJlS7DhZz3c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from host-80-43-120-208.as13285.net ([80.43.120.208] helo=smtpclient.apple) by smtp.hosts.co.uk with esmtpa (Exim) (envelope-from ) id 1qsNiH-0004BV-98 for gcc-patches@gcc.gnu.org; Mon, 16 Oct 2023 14:32:54 +0100 From: Simon Wright Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: [PATCH] Fix PR ada/111813 (Inconsistent limit in Ada.Calendar.Formatting) Message-Id: Date: Mon, 16 Oct 2023 14:32:43 +0100 To: gcc-patches@gcc.gnu.org X-Mailer: Apple Mail (2.3731.700.6) X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779919172727099882 X-GMAIL-MSGID: 1779919172727099882 The description of the second Value function (returning Duration) (ARM 9.6.1(87) doesn't place any limitation on the Elapsed_Time parameter's value, beyond "Constraint_Error is raised if the string is not formatted as described for Image, or the function cannot interpret the given string as a Duration value". It would seem reasonable that Value and Image should be consistent, in that any string produced by Image should be accepted by Value. Since Image must produce a two-digit representation of the Hours, there's an implication that its Elapsed_Time parameter should be less than 100.0 hours (the ARM merely says that in that case the result is implementation-defined). The current implementation of Value raises Constraint_Error if the Elapsed_Time parameter is greater than or equal to 24 hours. This patch removes the restriction, so that the Elapsed_Time parameter must only be less than 100.0 hours. gcc/ada/Changelog: 2023-10-15 Simon Wright PR ada/111813 * gcc/ada/libgnat/a-calfor.adb (Value (2)): Allow values of parameter Elapsed_Time greater than or equal to 24 hours, by doing the hour calculations in Natural rather than Hour_Number (0 .. 23). Calculate the result directly rather than by using Seconds_Of (whose Hour parameter is of type Hour_Number). If an exception occurs of type Constraint_Error, re-raise it rather than raising a new CE. gcc/testsuite/Changelog: 2023-10-15 Simon Wright PR ada/111813 * gcc/testsuite/gnat.dg/calendar_format_value.adb: New test. --- gcc/ada/libgnat/a-calfor.adb | 11 +++++--- .../gnat.dg/calendar_format_value.adb | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/calendar_format_value.adb diff --git a/gcc/ada/libgnat/a-calfor.adb b/gcc/ada/libgnat/a-calfor.adb index 18f4e7388df..493728b490e 100644 --- a/gcc/ada/libgnat/a-calfor.adb +++ b/gcc/ada/libgnat/a-calfor.adb @@ -777,7 +777,7 @@ package body Ada.Calendar.Formatting is function Value (Elapsed_Time : String) return Duration is D : String (1 .. 11); - Hour : Hour_Number; + Hour : Natural; Minute : Minute_Number; Second : Second_Number; Sub_Second : Second_Duration := 0.0; @@ -817,7 +817,7 @@ package body Ada.Calendar.Formatting is -- Value extraction - Hour := Hour_Number (Hour_Number'Value (D (1 .. 2))); + Hour := Natural (Natural'Value (D (1 .. 2))); Minute := Minute_Number (Minute_Number'Value (D (4 .. 5))); Second := Second_Number (Second_Number'Value (D (7 .. 8))); @@ -837,9 +837,14 @@ package body Ada.Calendar.Formatting is raise Constraint_Error; end if; - return Seconds_Of (Hour, Minute, Second, Sub_Second); + return Duration (Hour * 3600) + + Duration (Minute * 60) + + Duration (Second) + + Sub_Second; exception + -- CE is mandated, but preserve trace if CE already. + when Constraint_Error => raise; when others => raise Constraint_Error; end Value; diff --git a/gcc/testsuite/gnat.dg/calendar_format_value.adb b/gcc/testsuite/gnat.dg/calendar_format_value.adb new file mode 100644 index 00000000000..e98e496fd3b --- /dev/null +++ b/gcc/testsuite/gnat.dg/calendar_format_value.adb @@ -0,0 +1,26 @@ +-- { dg-do run } +-- { dg-options "-O2" } + +with Ada.Calendar.Formatting; + +procedure Calendar_Format_Value is + Limit : constant Duration + := 99 * 3600.0 + 59 * 60.0 + 59.0; +begin + declare + Image : constant String := Ada.Calendar.Formatting .Image (Limit); + Image_Error : exception; + begin + if Image /= "99:59:59" then + raise Image_Error with "image: " & Image; + end if; + declare + Value : constant Duration := Ada.Calendar.Formatting.Value (Image); + Value_Error : exception; + begin + if Value /= Limit then + raise Value_Error with "duration: " & Value'Image; + end if; + end; + end; +end Calendar_Format_Value;