From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.hosts.co.uk (smtp.hosts.co.uk [85.233.160.19]) by sourceware.org (Postfix) with ESMTPS id 100F33858D28 for ; Thu, 19 Oct 2023 11:31:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 100F33858D28 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 100F33858D28 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=1697715103; cv=none; b=dLHf3X/3KCI8AEnhflGQZiZiQLv8QKHTJ0gYTVKLHBuZ4TS93dAmfaeZOqz91Uy+XWmTKjV2W9eYH1pxxSCIkkB6Hug1P7JFDFQ/tNXyPV77mX6YIFGwNY0FA/owHFUCFmw1lksKFypJzXuqMKWMwj/H20/YYVyDBPmcbapBhHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697715103; c=relaxed/simple; bh=VJ+5ZWiTQblaakImpXLgDmZ5imo4drF9R/GXpl+9WIA=; h=Mime-Version:Subject:From:Date:Message-Id:To; b=YEpWElpMKj4l9so8Jcfai1b4gRbUcEdaL6NdcQCx0LOpn+buXfkfQEdcw8Gjl0TJcO/BFRpCZlpCw8jZsVEmSIuJ1NdoM5Pr9G0KwsRJEW1v8+fnBwBgoi7ntmaSsEx0eYSvPK5WnGqFmTwDL2XmZyYitXtr35wM9rWJQShD5Rc= 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 1qtRFc-000Blg-7u; Thu, 19 Oct 2023 12:31:40 +0100 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Subject: Re: [PATCH] Fix PR ada/111813 (Inconsistent limit in Ada.Calendar.Formatting) From: Simon Wright In-Reply-To: Date: Thu, 19 Oct 2023 12:31:29 +0100 Cc: derodat@adacore.com Content-Transfer-Encoding: quoted-printable Message-Id: References: To: gcc-patches@gcc.gnu.org X-Mailer: Apple Mail (2.3774.100.2.1.4) X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RCVD_IN_DNSWL_LOW,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 List-Id: Pierre-Marie, I=E2=80=99ve CC=E2=80=99d you hoping you=E2=80=99re an = appropriate person to ping on this one. If not, who would be for this sort of change? I should have said, tested by - add test case, make -C gcc check-gnat: error reported - make -C gcc gnatlib_and_tools; make install - make -C gcc check-gnat: no error reported FSF copyright assignment RT:1016382 =E2=80=94S > On 16 Oct 2023, at 14:32, Simon Wright wrote: >=20 > The description of the second Value function (returning Duration) (ARM = 9.6.1(87)=20 > doesn't place any limitation on the Elapsed_Time parameter's value, = beyond=20 > "Constraint_Error is raised if the string is not formatted as = described for Image, or=20 > the function cannot interpret the given string as a Duration value". >=20 > It would seem reasonable that Value and Image should be consistent, in = that any=20 > 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=20 > Elapsed_Time parameter should be less than 100.0 hours (the ARM merely = says > that in that case the result is implementation-defined). >=20 > The current implementation of Value raises Constraint_Error if the = Elapsed_Time > parameter is greater than or equal to 24 hours. >=20 > This patch removes the restriction, so that the Elapsed_Time parameter = must only > be less than 100.0 hours. >=20 > gcc/ada/Changelog: >=20 > 2023-10-15 Simon Wright >=20 > PR ada/111813 >=20 > * 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). >=20 > If an exception occurs of type Constraint_Error, re-raise it > rather than raising a new CE. >=20 > gcc/testsuite/Changelog: >=20 > 2023-10-15 Simon Wright >=20 > PR ada/111813 >=20 > * gcc/testsuite/gnat.dg/calendar_format_value.adb: New test. >=20 > --- > 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 >=20 > 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 >=20 > 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 :=3D 0.0; > @@ -817,7 +817,7 @@ package body Ada.Calendar.Formatting is >=20 > -- Value extraction >=20 > - Hour :=3D Hour_Number (Hour_Number'Value (D (1 .. 2))); > + Hour :=3D Natural (Natural'Value (D (1 .. 2))); > Minute :=3D Minute_Number (Minute_Number'Value (D (4 .. 5))); > Second :=3D Second_Number (Second_Number'Value (D (7 .. 8))); >=20 > @@ -837,9 +837,14 @@ package body Ada.Calendar.Formatting is > raise Constraint_Error; > end if; >=20 > - return Seconds_Of (Hour, Minute, Second, Sub_Second); > + return Duration (Hour * 3600) > + + Duration (Minute * 60) > + + Duration (Second) > + + Sub_Second; >=20 > exception > + -- CE is mandated, but preserve trace if CE already. > + when Constraint_Error =3D> raise; > when others =3D> raise Constraint_Error; > end Value; >=20 > 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 > + :=3D 99 * 3600.0 + 59 * 60.0 + 59.0; > +begin > + declare > + Image : constant String :=3D Ada.Calendar.Formatting .Image = (Limit); > + Image_Error : exception; > + begin > + if Image /=3D "99:59:59" then > + raise Image_Error with "image: " & Image; > + end if; > + declare > + Value : constant Duration :=3D Ada.Calendar.Formatting.Value = (Image); > + Value_Error : exception; > + begin > + if Value /=3D Limit then > + raise Value_Error with "duration: " & Value'Image; > + end if; > + end; > + end; > +end Calendar_Format_Value; > --=20 > 2.39.3 (Apple Git-145) >=20