(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
edges-1.c
       1  typedef struct FILE   FILE;
       2  
       3  FILE* fopen (const char*, const char*);
       4  int   fclose (FILE*);
       5  
       6  extern int foo ();
       7  extern void bar ();
       8  
       9  /* Verify that only significant edges are reported.  */
      10  
      11  void test_1 (const char *path, int flag)
      12  {
      13    FILE *fp = fopen (path, "r");
      14  
      15    if (!fp) /* { dg-message "when 'fp' is non-NULL" } */
      16      return;
      17  
      18    /* We shouldn't report this control flow.  */
      19    while (foo ()) /* { dg-bogus "" } */
      20      bar ();
      21  
      22    if (flag) /* { dg-message "when 'flag == 0'" "branch event" } */
      23      fclose (fp); /* { dg-bogus "leak" "warning at wrong location" { xfail *-*-* } .-1 } */
      24  } /* { dg-warning "leak of FILE 'fp'" "warning" { xfail *-*-* } } */
      25  // TODO(xfail): location of leak message ought to be on closing brace
      26  
      27  void test_2 (const char *path, int flag)
      28  {
      29    FILE *fp = fopen (path, "r");
      30  
      31    /* We shouldn't report this control flow.  */
      32    if (foo ()) /* { dg-bogus "" } */
      33      bar ();
      34    else
      35      bar ();
      36  
      37    if (flag) /* { dg-message "when 'flag == 0'" } */
      38      fclose (fp); 
      39  } /* { dg-warning "leak of FILE 'fp'" } */
      40  
      41  static void __attribute__((noinline))
      42  called_by_test_3 (int flag)
      43  {
      44    if (flag)
      45      foo ();
      46  }
      47  
      48  void test_3 (const char *path, int flag)
      49  {
      50    FILE *fp = fopen (path, "r");
      51  
      52    /* We shouldn't report the call/return here.  */
      53    called_by_test_3 (flag); /* { dg-bogus "" } */
      54  
      55    if (flag) /* { dg-message "when 'flag == 0'" } */
      56      fclose (fp);
      57  } /* { dg-warning "leak of FILE 'fp'" } */