(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
deref-before-check-pr77425.c
       1  /* Fixed in r7-2945-g61f46d0e6dd568.
       2     Simplified from gcc/ipa-devirt.c.  */
       3  
       4  #define NULL ((void *)0)
       5  typedef struct odr_type_d {
       6    /* .... */
       7    int id;
       8    /* .... */
       9  } *odr_type;
      10  static odr_type **odr_types_ptr;
      11  #define odr_types (*odr_types_ptr) /* { dg-message "pointer 'odr_types_ptr' is dereferenced here" } */
      12  
      13  int cond, other_cond;
      14  
      15  odr_type some_logic ();
      16  
      17  odr_type
      18  get_odr_type (/* ... */)
      19  {
      20    /* .... */
      21    odr_type val = NULL;
      22    /* .... */
      23  
      24    val = some_logic ();
      25  
      26    /* .... */
      27    if (cond)
      28      {
      29        /* .... */
      30      }
      31    else if (other_cond)
      32      {
      33        odr_types[val->id] = 0; /* { dg-message "in expansion of macro 'odr_types'" } */
      34        /* .... */
      35        if (odr_types_ptr) /* { dg-warning "check of 'odr_types_ptr' for NULL after already dereferencing it" } */
      36  	{
      37  	  /* .... */
      38  	  val->id = 42;
      39  	}
      40        /* .... */
      41      }
      42    return val;
      43  }