Clang Project

clang_source_code/test/Analysis/inlining/eager-reclamation-path-notes.c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -analyzer-config graph-trim-interval=5 -verify %s
2// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file -analyzer-config graph-trim-interval=5 %s -o %t.plist
3// RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/eager-reclamation-path-notes.c.plist -
4
5void use(int *ptr, int val) {
6  *ptr = val; // expected-warning {{Dereference of null pointer (loaded from variable 'ptr')}}
7  // expected-note@-1 {{Dereference of null pointer (loaded from variable 'ptr')}}
8}
9
10int compute() {
11  // Do something that will take enough processing to trigger trimming.
12  // FIXME: This is actually really sensitive. If the interval timing is just
13  // wrong, the node for the actual dereference may also be collected, and all
14  // the path notes will disappear. <rdar://problem/12511814>
15  return 2 + 3 + 4 + 5 + 6;
16}
17
18void testSimple() {
19  int *p = 0;
20  // expected-note@-1 {{'p' initialized to a null pointer value}}
21  use(p, compute());
22  // expected-note@-1 {{Passing null pointer value via 1st parameter 'ptr'}}
23  // expected-note@-2 {{Calling 'use'}}
24}
25
26
27void use2(int *ptr, int val) {
28  *ptr = val; // expected-warning {{Dereference of null pointer (loaded from variable 'ptr')}}
29  // expected-note@-1 {{Dereference of null pointer (loaded from variable 'ptr')}}
30}
31
32void passThrough(int *p) {
33  use2(p, compute());
34  // expected-note@-1 {{Passing null pointer value via 1st parameter 'ptr'}}
35  // expected-note@-2 {{Calling 'use2'}}
36}
37
38void testChainedCalls() {
39  int *ptr = 0;
40  // expected-note@-1 {{'ptr' initialized to a null pointer value}}
41  passThrough(ptr);
42  // expected-note@-1 {{Passing null pointer value via 1st parameter 'p'}}
43  // expected-note@-2 {{Calling 'passThrough'}}
44}
45
46