From ef6bd9cda95c5f40965c195ce0545df85652a6ed Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Mon, 14 May 2018 20:17:19 +0000 Subject: [PATCH] re PR target/85756 (wrong code at -Os on x86-64-linux-gnu in 32-bit mode) PR target/85756 * gnat.dg/opt70.adb: New test. * gnat.dg/opt70_pkg.ad[sb]: New helper. From-SVN: r260239 --- gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/gnat.dg/opt70.adb | 13 +++++++ gcc/testsuite/gnat.dg/opt70_pkg.adb | 55 +++++++++++++++++++++++++++++ gcc/testsuite/gnat.dg/opt70_pkg.ads | 7 ++++ 4 files changed, 81 insertions(+) create mode 100644 gcc/testsuite/gnat.dg/opt70.adb create mode 100644 gcc/testsuite/gnat.dg/opt70_pkg.adb create mode 100644 gcc/testsuite/gnat.dg/opt70_pkg.ads diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 09d97e0364c..4a0b371cecc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-05-14 Eric Botcazou + + PR target/85756 + * gnat.dg/opt70.adb: New test. + * gnat.dg/opt70_pkg.ad[sb]: New helper. + 2018-05-14 Kyrylo Tkachov * gcc.target/aarch64/crypto-fuse-1.c: New test. diff --git a/gcc/testsuite/gnat.dg/opt70.adb b/gcc/testsuite/gnat.dg/opt70.adb new file mode 100644 index 00000000000..fcf55432b1c --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt70.adb @@ -0,0 +1,13 @@ +-- { dg-do run } +-- { dg-options "-O2" } + +with Ada.Calendar; +with Opt70_Pkg; + +procedure Opt70 is + T : Ada.Calendar.Time := Ada.Calendar.Time_Of (2001, 10, 31); +begin + if Opt70_Pkg.Image (T, "%y") /= "01" then + raise Program_Error; + end if; +end; diff --git a/gcc/testsuite/gnat.dg/opt70_pkg.adb b/gcc/testsuite/gnat.dg/opt70_pkg.adb new file mode 100644 index 00000000000..d6a9f3943b0 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt70_pkg.adb @@ -0,0 +1,55 @@ +with Ada.Calendar; use Ada.Calendar; +with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with GNAT.Calendar; use GNAT.Calendar; + +package body Opt70_Pkg is + + type Enum is (None, Zero, Space); + + type Sec_Number is mod 2 ** 64; + + function Image (N : Sec_Number; Pad : Enum; Length : Natural) return String; + + function Image (N : Natural; Pad : Enum; Length: Natural) return String is + begin + return Image (Sec_Number (N), Pad, Length); + end; + + function Image (N : Sec_Number; Pad : Enum; Length : Natural) return String is + + function Pad_Char return String is + begin + case Pad is + when None => return ""; + when Zero => return "00"; + when Space => return " "; + end case; + end; + + NI : constant String := Sec_Number'Image (N); + NIP : constant String := Pad_Char & NI (2 .. NI'Last); + + begin + return NIP (NIP'Last - Length + 1 .. NIP'Last); + end; + + function Image (Date : Ada.Calendar.Time; S : String) return String is + Result : Unbounded_String := Null_Unbounded_String; + Year : Year_Number; + Month : Month_Number; + Day : Day_Number; + Hour : Hour_Number; + Minute : Minute_Number; + Second : Second_Number; + Sub_Second : Second_Duration; + begin + Split (Date, Year, Month, Day, Hour, Minute, Second, Sub_Second); + case S (S'First + 1) is + when 'S' => Result := Result & Image (Second, Zero, 2); + when 'y' => Result := Result & Image (Sec_Number (1), Zero, 2); + when others => null; + end case; + return To_String (Result); + end; + +end Opt70_Pkg; diff --git a/gcc/testsuite/gnat.dg/opt70_pkg.ads b/gcc/testsuite/gnat.dg/opt70_pkg.ads new file mode 100644 index 00000000000..d578d0beccb --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt70_pkg.ads @@ -0,0 +1,7 @@ +with Ada.Calendar; + +package Opt70_Pkg is + + function Image (Date : Ada.Calendar.Time; S : String) return String; + +end Opt70_Pkg; -- 2.30.2