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