1 | // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -verify %s |
2 | // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -analyzer-config c++-allocator-inlining=true -verify %s |
3 | // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=plist %s -o %t.plist |
4 | // RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/NewDelete-path-notes.cpp.plist - |
5 | |
6 | void test() { |
7 | int *p = new int; |
8 | // expected-note@-1 {{Memory is allocated}} |
9 | if (p) |
10 | // expected-note@-1 {{Taking true branch}} |
11 | delete p; |
12 | // expected-note@-1 {{Memory is released}} |
13 | |
14 | delete p; // expected-warning {{Attempt to free released memory}} |
15 | // expected-note@-1 {{Attempt to free released memory}} |
16 | } |
17 | |
18 | struct Odd { |
19 | void kill() { |
20 | delete this; // expected-note {{Memory is released}} |
21 | } |
22 | }; |
23 | |
24 | void test(Odd *odd) { |
25 | odd->kill(); // expected-note{{Calling 'Odd::kill'}} |
26 | // expected-note@-1 {{Returning; memory was released}} |
27 | delete odd; // expected-warning {{Attempt to free released memory}} |
28 | // expected-note@-1 {{Attempt to free released memory}} |
29 | } |
30 | |
31 | |