Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Dodge a compiler bug affecting timetz_zone/timetz_izone.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Oct 2023 17:40:15 +0000 (13:40 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 20 Oct 2023 17:40:15 +0000 (13:40 -0400)
This avoids a compiler bug occurring in AIX's xlc, even in pretty
late-model revisions.  Buildfarm testing has now confirmed that
only 64-bit xlc is affected.  Although we are contemplating
dropping support for xlc in v17, it's still supported in the
back branches, so we need this fix.

Back-patch of code changes from HEAD commit 19fa97731.
(The test cases were already back-patched, in 4a427b82c et al.)

Discussion: https://postgr.es/m/CA+hUKGK=DOC+hE-62FKfZy=Ybt5uLkrg3zCZD-jFykM-iPn8yw@mail.gmail.com

src/backend/utils/adt/date.c

index e798c1a78ee7a7ab627b3ffc0b1ef56ac8563fa5..baa069125e857724c937819f0dc1952788905848 100644 (file)
@@ -2861,10 +2861,11 @@ timetz_zone(PG_FUNCTION_ARGS)
    result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
 
    result->time = t->time + (t->zone - tz) * USECS_PER_SEC;
+   /* C99 modulo has the wrong sign convention for negative input */
    while (result->time < INT64CONST(0))
        result->time += USECS_PER_DAY;
-   while (result->time >= USECS_PER_DAY)
-       result->time -= USECS_PER_DAY;
+   if (result->time >= USECS_PER_DAY)
+       result->time %= USECS_PER_DAY;
 
    result->zone = tz;
 
@@ -2894,10 +2895,11 @@ timetz_izone(PG_FUNCTION_ARGS)
    result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
 
    result->time = time->time + (time->zone - tz) * USECS_PER_SEC;
+   /* C99 modulo has the wrong sign convention for negative input */
    while (result->time < INT64CONST(0))
        result->time += USECS_PER_DAY;
-   while (result->time >= USECS_PER_DAY)
-       result->time -= USECS_PER_DAY;
+   if (result->time >= USECS_PER_DAY)
+       result->time %= USECS_PER_DAY;
 
    result->zone = tz;