(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
strlenopt-92.c
       1  /* PR tree-optimization/92765 - wrong code for strcmp of a union member
       2     { dg-do run }
       3     { dg-options "-O2 -Wall" } */
       4  
       5  #include "strlenopt.h"
       6  
       7  __attribute__((noipa)) int
       8  copy (char *x, int y)
       9  {
      10    if (y == 0)
      11      strcpy (x, "abcd");
      12    return y;
      13  }
      14  
      15  __attribute__((noipa)) char *
      16  alloc_2_copy_compare (int x)
      17  {
      18    char *p;
      19    if (x)
      20      p = malloc (4);
      21    else
      22      p = calloc (16, 1);
      23  
      24    char *q = p + 2;
      25    if (copy (q, x))
      26      return p;
      27  
      28    if (strcmp (q, "abcd") != 0)
      29      abort ();
      30  
      31    return p;
      32  }
      33  
      34  char a5[5], a6[6], a7[7];
      35  
      36  __attribute__((noipa)) char *
      37  decl_3_copy_compare (int x)
      38  {
      39    char *p = x < 0 ? a5 : 0 < x ? a6 : a7;
      40    char *q = p + 1;
      41    if (copy (q, x))
      42      return p;
      43  
      44    if (strcmp (q, "abcd") != 0)
      45      abort ();
      46  
      47    return p;
      48  }
      49  
      50  int main ()
      51  {
      52    free (alloc_2_copy_compare (0));
      53    free (alloc_2_copy_compare (1));
      54  
      55    decl_3_copy_compare (-1);
      56    decl_3_copy_compare (0);
      57    decl_3_copy_compare (1);
      58  }