(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
malloc-vs-local-4.c
       1  #include <stdlib.h>
       2  
       3  void __attribute__((noinline)) callee_1 (int *ptr)
       4  {
       5    *ptr = 42; /* { dg-warning "dereference of possibly-NULL 'ptr'" } */
       6  }
       7  
       8  int test_1 (int i, int flag)
       9  {
      10    /* Double diamond CFG; either use &i, or a malloc-ed buffer.  */
      11    int *ptr = &i;
      12    if (flag)
      13      ptr = (int *)malloc (sizeof (int));
      14    callee_1 (ptr);
      15    if (flag)
      16      free (ptr);
      17    return i;
      18  }
      19  
      20  void __attribute__((noinline)) callee_2 (int *ptr)
      21  {
      22    *ptr = 42;
      23  }
      24  
      25  int test_2 (int flag)
      26  {
      27    int i;
      28  
      29    if (flag)
      30      callee_2 (&i);
      31  
      32    callee_2 (&i);
      33  
      34    if (!flag)
      35      {
      36        void *ptr = malloc (16);
      37        free (ptr);
      38        free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
      39      }
      40  }