(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
anon-struct-12.c
       1  /* { dg-do run } */
       2  /* { dg-options "-fplan9-extensions" } */
       3  
       4  /* When using -fplan9-extensions, we support automatic conversion of
       5     pointer types, and we support referring to a typedef name
       6     directly.  */
       7  
       8  extern void exit (int);
       9  extern void abort (void);
      10  
      11  struct A { char a; };
      12  
      13  struct B {
      14    char b;
      15    struct A;
      16    char c;
      17  };
      18  
      19  void
      20  f1 (struct A *p)
      21  {
      22    p->a = 1;
      23  }
      24  
      25  void
      26  test1 (void)
      27  {
      28    struct B b;
      29    struct A *p;
      30  
      31    b.b = 2;
      32    b.c = 3;
      33    f1 (&b);
      34    if (b.a != 1)
      35      abort ();
      36    if (b.b != 2 || b.c != 3)
      37      abort ();
      38    p = &b;
      39    if (p->a != 1)
      40      abort ();
      41  }
      42  
      43  typedef struct { char d; } D;
      44  
      45  struct E {
      46    char b;
      47    struct F { char f; };
      48    char c;
      49    union {
      50      D;
      51    };
      52    char e;
      53  };
      54  
      55  void
      56  f2 (struct F *p)
      57  {
      58    p->f = 6;
      59  }
      60  
      61  void
      62  f3 (D *p)
      63  {
      64    p->d = 4;
      65  }
      66  
      67  void
      68  f4 (D d)
      69  {
      70  }
      71  
      72  void
      73  test2 (void)
      74  {
      75    struct E e;
      76    struct F *pf;
      77    D *pd;
      78    D d;
      79  
      80    e.b = 2;
      81    e.c = 3;
      82    e.e = 5;
      83    f2 (&e);
      84    f3 (&e);
      85    if (e.d != 4)
      86      abort ();
      87    if (e.f != 6)
      88      abort ();
      89    if (e.b != 2 || e.c != 3 || e.e != 5)
      90      abort ();
      91    pf = &e;
      92    if (pf->f != 6)
      93      abort ();
      94    pd = &e;
      95    if (pd->d != 4)
      96      abort ();
      97    d = e.D;
      98    f3 (&e.D);
      99    f4 (e.D);
     100  }
     101  
     102  int
     103  main ()
     104  {
     105    test1 ();
     106    test2 ();
     107    exit (0);
     108  }