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

            Bug ID: 106142
           Summary: [13 Regression] Wrong code on pcre-8.45, minimized
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slyfox at gcc dot gnu.org
  Target Milestone: ---

Initially noticed the problem as a pcre-8.45 test failure when built with this
week's gcc. Very likely a fresh regression.

Extracted self-contained example:

// cat pcre_compile.c
/*
  Extracted from pcre-8.45 on latest weekly 13.0.0 20220626 (experimental)
(GCC):

  $ gcc-13/bin/gcc -O1 pcre_compile.c -o a && ./a

  $ gcc-13/bin/gcc -O2 pcre_compile.c -o a && ./a
  Illegal instruction

 */

static void check_escape(const char *ptr, int *errorcodeptr, int options)
__attribute__((noipa));

static void check_escape(const char *ptr, int *errorcodeptr, int options)
{
  int utf = (options & 0x2) != 0;
  unsigned int c = 0;
  /* "D800" -> 0xD800 */
  for (int i = 0; i < 4; ++i)
  {
    unsigned int cc = *(ptr++);
    c = c * 16 + cc - ((cc < 'A') ? '0' : ('A' - 10));
  }

  if (c > (utf ? 0x10ffffU : 0xffU))
    *errorcodeptr = 1;
  else if (utf && c >= 0xd800 && c <= 0xdfff)
    *errorcodeptr = 2;
}

int main (void)
{
    int errorcode = 0;
    check_escape("D800", &errorcode, 0x2);
    if (errorcode == 0) /* should be 2 */
      __builtin_trap();

    return 0;
}


$ gcc-13/bin/gcc -O1 pcre_compile.c -o a && ./a
$ gcc-13/bin/gcc -O2 pcre_compile.c -o a && ./a
Illegal instruction

$ gcc-13/bin/gcc -v |& unnix
Using built-in specs.
COLLECT_GCC=/<<NIX>>/gcc-13.0.0/bin/gcc
COLLECT_LTO_WRAPPER=/<<NIX>>/gcc-13.0.0/libexec/gcc/x86_64-unknown-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20220626 (experimental) (GCC)

Reply via email to