blob: 4d158b54fa1ba5f964653ef8252807aa07a1f77d (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/* { dg-skip-if "requires hosted libstdc++ for stdlib size_t" { ! hostedlib } } */
#include <stdlib.h>
#include "analyzer-decls.h"
static void __attribute__((noinline))
__analyzer_callee_1 (size_t inner_sz)
{
void *p = __builtin_alloca (inner_sz);
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(outer_sz_\[^\n\r\]*\\)'" } */
}
void
test_1 (int flag, size_t outer_sz)
{
if (flag)
__analyzer_callee_1 (outer_sz);
/* Verify that we merge state; in particular, the dynamic size of "p"
in the called frame should have been purged. */
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
}
void
test_2 (int flag, size_t sz)
{
if (flag)
{
void *p = malloc (sz);
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */
free (p);
/* The dynamic size of "p" should have been purged. */
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */
}
/* Verify that we merge state. */
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
}
/* Verify that we purge state on the NULL branch when a malloc result is
tested against NULL. */
void
test_3 (size_t sz)
{
void *p = malloc (sz);
if (p)
{
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */
}
else
{
/* The dynamic size of "p" should have been purged
due to "p" being equal to NULL. */
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */
}
free (p);
/* The dynamic size of "p" should have been purged. */
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */
/* Verify that we merge state. */
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
}
/* Verify that we purge dynamic extent of a pointer when it leaks. */
static void __attribute__((noinline))
__analyzer_callee_4 (size_t inner_sz)
{
void *p = malloc (inner_sz);
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(outer_sz_\[^\n\r\]*\\)'" } */
} /* { dg-warning "leak of 'p'" } */
void
test_4 (int flag, size_t outer_sz)
{
if (flag)
__analyzer_callee_4 (outer_sz);
/* Verify that we merge state. */
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
}
|