1  /* PR rtl-optimization/16968 */
       2  /* Testcase by Jakub Jelinek  <jakub@redhat.com> */
       3  /* { dg-require-effective-target freorder } */
       4  /* { dg-options "-O2 -freorder-blocks-and-partition" } */
       5  
       6  struct T
       7  {
       8    unsigned int b, c, *d;
       9    unsigned char e;
      10  };
      11  struct S
      12  {
      13    unsigned int a;
      14    struct T f;
      15  };
      16  struct U
      17  {
      18    struct S g, h;
      19  };
      20  struct V
      21  {
      22    unsigned int i;
      23    struct U j;
      24  };
      25  
      26  extern void exit (int);
      27  extern void abort (void);
      28  
      29  void *
      30  dummy1 (void *x)
      31  {
      32    return "";
      33  }
      34  
      35  void *
      36  dummy2 (void *x, void *y)
      37  {
      38    exit (0);
      39  }
      40  
      41  struct V *
      42  baz (unsigned int x)
      43  {
      44    static struct V v;
      45    __builtin_memset (&v, 0x55, sizeof (v));
      46    return &v;
      47  }
      48  
      49  int
      50  check (void *x, struct S *y)
      51  {
      52    if (y->a || y->f.b || y->f.c || y->f.d || y->f.e)
      53      abort ();
      54    return 1;
      55  }
      56  
      57  static struct V *
      58  bar (unsigned int x, void *y)
      59  {
      60    const struct T t = { 0, 0, (void *) 0, 0 };
      61    struct V *u;
      62    void *v;
      63    v = dummy1 (y);
      64    if (!v)
      65      return (void *) 0;
      66  
      67    u = baz (sizeof (struct V));
      68    u->i = x;
      69    u->j.g.a = 0;
      70    u->j.g.f = t;
      71    u->j.h.a = 0;
      72    u->j.h.f = t;
      73  
      74    if (!check (v, &u->j.g) || !check (v, &u->j.h))
      75      return (void *) 0;
      76    return u;
      77  }
      78  
      79  int
      80  foo (unsigned int *x, unsigned int y, void **z)
      81  {
      82    void *v;
      83    unsigned int i, j;
      84  
      85    *z = v = (void *) 0;
      86  
      87    for (i = 0; i < y; i++)
      88      {
      89        struct V *c;
      90  
      91        j = *x;
      92  
      93        switch (j)
      94  	{
      95  	case 1:
      96  	  c = bar (j, x);
      97  	  break;
      98  	default:
      99  	  c = 0;
     100  	  break;
     101  	}
     102        if (c)
     103  	v = dummy2 (v, c);
     104        else
     105          return 1;
     106      }
     107  
     108    *z = v;
     109    return 0;
     110  }
     111  
     112  int
     113  main (void)
     114  {
     115    unsigned int one = 1;
     116    void *p;
     117    foo (&one, 1, &p);
     118    abort ();
     119  }