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