https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103120

            Bug ID: 103120
           Summary: [12 Regression] test miscompiled with -O2 on darwin
                    since r12-4790
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ibuclaw at gdcproject dot org
  Target Milestone: ---

Starting from r12-4790, one of the D library tests started failing on darwin.

Distilled it down to following C code.  Passes when compiled with -O1 and -O3,
but fails with -O2.
---
#define radix 10
__INT32_TYPE__ numDigits(__UINT64_TYPE__ value)
{
     __INT32_TYPE__ n = 1;
     while (value > __UINT32_MAX__)
     {
        n += 4;
        value /= radix * radix * radix * radix;
     }
     __UINT32_TYPE__ v = (__UINT32_TYPE__)value;
     while (1)
     {
         if (v < radix)
             return n;
         if (v < radix * radix)
             return n + 1;
         if (v < radix * radix * radix)
             return n + 2;
         if (v < radix * radix * radix * radix)
             return n + 3;
         n += 4;
         v /= radix * radix * radix * radix;
     }
}

int main()
{
    if (numDigits(__UINT64_MAX__) != 20)
        __builtin_abort();
}

Reply via email to