https://gcc.gnu.org/g:1c5502a3a49a2c697bda4401696978e440e35209
commit r17-1195-g1c5502a3a49a2c697bda4401696978e440e35209 Author: Piotr Trojanek <[email protected]> Date: Wed Apr 8 12:29:37 2026 +0200 ada: Simplify interfacing with localtime wrappers Interface from Ada to C for calling localtime was over-complicated, including access types, aliased variables and suppressed CodePeer messages. None of this is necessary if we just rely on the Ada RM and what it guarantees when interfacing for parameters of elementary types depending on their IN/OUT mode. gcc/ada/ChangeLog: * libgnat/a-calend.adb (localtime_tzoff): Simplify interface. * sysdep.c (__gnat_localtime_tzoff): Remove duplicated specs; pass "in" parameters via copy and "out" parameters via pointers. Diff: --- gcc/ada/libgnat/a-calend.adb | 23 +++++++---------------- gcc/ada/sysdep.c | 27 +++++++++++---------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/gcc/ada/libgnat/a-calend.adb b/gcc/ada/libgnat/a-calend.adb index d2f84f084aa5..ecb84d9ff38f 100644 --- a/gcc/ada/libgnat/a-calend.adb +++ b/gcc/ada/libgnat/a-calend.adb @@ -692,15 +692,10 @@ is Nanos_In_56_Years : constant := (14 * 366 + 42 * 365) * Nanos_In_Day; - type int_Pointer is access all Interfaces.C.int; - type long_Pointer is access all Interfaces.C.long; - - type OS_Time_Pointer is access all System.OS_Lib.OS_Time; - procedure localtime_tzoff - (timer : OS_Time_Pointer; - is_historic : int_Pointer; - off : long_Pointer); + (timer : System.OS_Lib.OS_Time; + is_historic : Interfaces.C.int; + off : out Interfaces.C.long); pragma Import (C, localtime_tzoff, "__gnat_localtime_tzoff"); -- This routine is a interfacing wrapper around the library function -- __gnat_localtime_tzoff. Parameter 'timer' represents a Unix-based @@ -713,9 +708,9 @@ is Adj_Cent : Integer; Date_N : Time_Rep; - Flag : aliased Interfaces.C.int; - Offset : aliased Interfaces.C.long; - Secs_T : aliased System.OS_Lib.OS_Time; + Flag : Interfaces.C.int; + Offset : Interfaces.C.long; + Secs_T : System.OS_Lib.OS_Time; -- Start of processing for UTC_Time_Offset @@ -759,11 +754,7 @@ is Flag := (if Is_Historic then 1 else 0); - localtime_tzoff - (Secs_T'Unchecked_Access, - Flag'Unchecked_Access, - Offset'Unchecked_Access); - pragma Annotate (CodePeer, Modified, Offset); + localtime_tzoff (Secs_T, Flag, Offset); return Long_Integer (Offset); end UTC_Time_Offset; diff --git a/gcc/ada/sysdep.c b/gcc/ada/sysdep.c index 7752693a20a6..20cc3db49175 100644 --- a/gcc/ada/sysdep.c +++ b/gcc/ada/sysdep.c @@ -654,16 +654,17 @@ long __gnat_invalid_tzoff = 259273; /* Definition of __gnat_localtime_r used by a-calend.adb */ +extern void +__gnat_localtime_tzoff (OS_Time, int, long *); + #if defined (__MINGW32__) /* Reentrant localtime for Windows. */ -extern void -__gnat_localtime_tzoff (const OS_Time *, const int *, long *); - static const unsigned long long w32_epoch_offset = 11644473600ULL; + void -__gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off) +__gnat_localtime_tzoff (OS_Time timer, int is_historic, long *off) { TIME_ZONE_INFORMATION tzi; @@ -676,7 +677,7 @@ __gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off) signifies that the date is NOT historic, see the body of Ada.Calendar.UTC_Time_Offset. */ - if (*is_historic == 0) { + if (is_historic == 0) { *off = tzi.Bias; /* The system is operating in the range covered by the StandardDate @@ -707,7 +708,7 @@ __gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off) BOOL status; /* First convert unix time_t structure to windows FILETIME format. */ - utc_time.ull_time = ((unsigned long long) *timer + w32_epoch_offset) + utc_time.ull_time = ((unsigned long long) timer + w32_epoch_offset) * 10000000ULL; /* If GetTimeZoneInformation does not return a value between 0 and 2 then @@ -752,11 +753,8 @@ __gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off) spec is required. Only use when ___THREADS_POSIX4ad4__ is defined, the Lynx convention when building against the legacy API. */ -extern void -__gnat_localtime_tzoff (const OS_Time *, const int *, long *); - void -__gnat_localtime_tzoff (const OS_Time *timer, const int *is_historic, long *off) +__gnat_localtime_tzoff (OS_Time timer, int is_historic, long *off) { *off = 0; } @@ -771,16 +769,13 @@ extern void (*Lock_Task) (void); #define Unlock_Task system__soft_links__unlock_task extern void (*Unlock_Task) (void); -extern void -__gnat_localtime_tzoff (const OS_Time *, const int *, long *); - void -__gnat_localtime_tzoff (const OS_Time *timer ATTRIBUTE_UNUSED, - const int *is_historic ATTRIBUTE_UNUSED, +__gnat_localtime_tzoff (OS_Time timer ATTRIBUTE_UNUSED, + int is_historic ATTRIBUTE_UNUSED, long *off ATTRIBUTE_UNUSED) { struct tm tp ATTRIBUTE_UNUSED; - const time_t time = (time_t) *timer; + const time_t time = (time_t) timer; /* AIX, HPUX, Sun Solaris */ #if defined (_AIX) || defined (__hpux__) || defined (__sun__)
