(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.c-torture/
execute/
pr93213.c
       1  /* PR tree-optimization/93213 - wrong code on a multibyte store with
       2     -Og -foptimize-strlen
       3     { dg-require-effective-target int128 }
       4     { dg-additional-options "-Og -foptimize-strlen" } */
       5  
       6  typedef unsigned __INT16_TYPE__ u16;
       7  typedef unsigned __INT32_TYPE__ u32;
       8  typedef unsigned __int128 u128;
       9  
      10  static inline u128
      11  foo (u16 u16_1, u32 u32_1, u128 u128_1)
      12  {
      13  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
      14    u128 u128_0 = 0;
      15    u128_1 -= __builtin_mul_overflow (u32_1, u16_1, &u32_1);
      16    __builtin_memmove (&u16_1, &u128_0, 2);
      17    __builtin_memmove (&u16_1, &u128_1, 1);
      18    return u16_1;
      19  #else
      20    return 0xff;
      21  #endif
      22  }
      23  
      24  __attribute__ ((noipa)) void
      25  bar (void)
      26  {
      27    char a[] = { 1, 2 };
      28    const char b[] = { 0, 0 };
      29    const char c[] = { 2 };
      30    __builtin_memcpy (a, b, 2);
      31    // The above is transformed into
      32    //   MEM <short unsigned int> [(char * {ref-all})&a] = 0;
      33    // which was then dropped because of the non-nul store below.
      34    __builtin_memcpy (a, c, 1);
      35  
      36    volatile char *p = a;
      37    if (p[0] != 2 || p[1] != 0)
      38      __builtin_abort ();
      39  }
      40  
      41  int
      42  main (void)
      43  {
      44    u16 x = foo (-1, -1, 0);
      45    if (x != 0xff)
      46      __builtin_abort ();
      47  
      48    bar ();
      49    return 0;
      50  }