1  /* { dg-do compile } */ 
       2  /* { dg-options "-O2 -fdelete-null-pointer-checks -fdump-tree-isolate-paths -fdump-tree-optimized -Wnull-dereference" } */
       3  /* { dg-skip-if "" keeps_null_pointer_checks } */
       4  
       5  struct demangle_component
       6  {
       7  
       8    int type;
       9    int zzz;
      10  
      11  };
      12  
      13  struct d_info
      14  {
      15    struct demangle_component *comps;
      16    int next_comp;
      17    int num_comps;
      18  };
      19  
      20  void foo (int);
      21  void bar (int);
      22  
      23  static struct demangle_component *
      24  d_make_empty (struct d_info *di)
      25  {
      26    struct demangle_component *p;
      27  
      28    if (di->next_comp >= di->num_comps)
      29      return ((void *)0);
      30    p = &di->comps[di->next_comp];
      31    return p;
      32  }
      33  
      34  struct demangle_component *
      35  d_type (struct d_info *di)
      36  {
      37     struct demangle_component *ret;
      38     ret = d_make_empty (di);
      39     foo (ret->type); /* { dg-warning "null pointer dereference" } */
      40     bar (ret->zzz); /* { dg-warning "null pointer dereference" } */
      41     return ret;
      42  }
      43  
      44  /* We're testing two aspects of isolation here.  First that isolation
      45     occurs, second that if we have two null dereferences in a block that
      46     that we delete everything from the first dereferece to the end of the
      47     block, regardless of which comes first in the immediate use iterator.
      48  
      49     We leave the 0->type in the IL, so expect to see ->type twice.  */
      50  /* { dg-final { scan-tree-dump-times "__builtin_trap" 1 "isolate-paths"} } */
      51  /* { dg-final { scan-tree-dump-times "->type" 2 "isolate-paths"} } */
      52  /* { dg-final { scan-tree-dump-times "->type" 1 "optimized"} } */
      53  /* { dg-final { scan-tree-dump-times "\\.type" 1 "optimized"} } */
      54  /* { dg-final { scan-tree-dump-times "->zzz" 1 "isolate-paths"} } */