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

            Bug ID: 118206
           Summary: [15 regression] libdeflate miscompiled by ifcombine
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
  Target Milestone: ---

This first manifested as R failing to build (https://bugs.gentoo.org/946876),
then I found libdeflate failed its testsuite.

Here's a reduced version of its test_trailing_bytes test.
```
#include <stdint.h>
#include <stddef.h>

static inline __attribute__((always_inline)) uint16_t
load_uint16_t_unaligned(const void *p) {
  uint16_t v;
  __builtin_memcpy(&v, p, sizeof(v));
  return v;
}

__attribute__((noipa))
int libdeflate_zlib_decompress_ex(const void *in, size_t in_nbytes) {
  const uint8_t *in_next = in;
  uint16_t hdr;

  if (in_nbytes < (2 + 4))
    return 1;

  hdr = __builtin_bswap16(load_uint16_t_unaligned(in_next));
  in_next += 2;

  if ((hdr % 31) != 0)
    return 1;

  if (((hdr >> 8) & 0xF) != 8)
    return 1;

  if ((hdr >> 12) > 7)
    return 1;

  return 0;
}

int main() {
  uint8_t data[8] = {0x78, 0x9c, 0xc5, 0x96, 0x3, 0x93, 0x5d, 0x6b};
  int ret = libdeflate_zlib_decompress_ex(data, sizeof(data)/sizeof(data[0]));
  if (ret != 0) {
    __builtin_abort();
  }
}
```

-O0 even fails, but -O0 -fdisable-tree-ifcombine works.

Reply via email to