Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/edges-1.c

raw
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 bar ();
19
20 /* We shouldn't report this control flow. */
21 while (foo ()) /* { dg-bogus "" } */
22 bar ();
23
24 if (flag) /* { dg-message "when 'flag == 0'" "branch event" } */
25 fclose (fp); /* { dg-bogus "leak" "warning at wrong location" { xfail *-*-* } .-1 } */
26 } /* { dg-warning "leak of FILE 'fp'" "warning" { xfail *-*-* } } */
27 // TODO(xfail): location of leak message ought to be on closing brace
28
29 void test_2 (const char *path, int flag)
30 {
31 FILE *fp = fopen (path, "r");
32
33 /* We shouldn't report this control flow. */
34 if (foo ()) /* { dg-bogus "" } */
35 bar ();
36 else
37 bar ();
38
39 if (flag) /* { dg-message "when 'flag == 0'" } */
40 fclose (fp);
41 } /* { dg-warning "leak of FILE 'fp'" } */
42
43 static void __attribute__((noinline))
44 called_by_test_3 (int flag)
45 {
46 if (flag)
47 foo ();
48 }
49
50 void test_3 (const char *path, int flag)
51 {
52 FILE *fp = fopen (path, "r");
53
54 /* We shouldn't report the call/return here. */
55 called_by_test_3 (flag); /* { dg-bogus "" } */
56
57 if (flag) /* { dg-message "when 'flag == 0'" } */
58 fclose (fp);
59 } /* { dg-warning "leak of FILE 'fp'" } */