diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/opt70.adb | 13 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/opt70_pkg.adb | 55 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/opt70_pkg.ads | 7 |
4 files changed, 81 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 09d97e0..4a0b371 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-05-14 Eric Botcazou <ebotcazou@adacore.com> + + PR target/85756 + * gnat.dg/opt70.adb: New test. + * gnat.dg/opt70_pkg.ad[sb]: New helper. + 2018-05-14 Kyrylo Tkachov <kyrylo.tkachov@arm.com> * 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 0000000..fcf5543 --- /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 0000000..d6a9f39 --- /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 0000000..d578d0b --- /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; |