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

            Bug ID: 129250
           Summary: wrong code at -O2: __builtin_toupper(224) is assumed
                    not to return 192 in an ISO-8859-1 locale
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyuwoncho18 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

#include <locale.h>
#include <stdio.h>

volatile int v;

int main(void)
{
  if (!setlocale(LC_CTYPE, "en_US.ISO-8859-1"))
    return 2;
  int x = 224 + (v != 0);
  puts(__builtin_toupper(x) == 192 ? "mapped" : "not mapped");
}

godbolt: https://godbolt.org/z/6vvbxr5Th

With godbolt's en_US.ISO-8859-1 locale, the program prints "mapped" at -O0 but
"not mapped" at -O2. In that locale, byte 224 is lower-case à and toupper
returns 192 (upper-case À), so "mapped" is correct.
  • [Bug tree-optimization/129250] N... kyuwoncho18 at gmail dot com via Gcc-bugs

Reply via email to