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