2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -verify %s
|
2018-01-18 08:50:19 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -analyzer-config c++-allocator-inlining=true -verify %s
|
2018-06-13 03:07:41 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=plist %s -o %t.plist
|
2019-01-11 02:15:44 +08:00
|
|
|
// RUN: cat %t.plist | %diff_plist %S/Inputs/expected-plists/NewDelete-path-notes.cpp.plist -
|
2013-03-25 09:35:45 +08:00
|
|
|
|
|
|
|
void test() {
|
|
|
|
int *p = new int;
|
|
|
|
// expected-note@-1 {{Memory is allocated}}
|
|
|
|
if (p)
|
2013-08-28 16:04:08 +08:00
|
|
|
// expected-note@-1 {{Taking true branch}}
|
2013-03-25 09:35:45 +08:00
|
|
|
delete p;
|
|
|
|
// expected-note@-1 {{Memory is released}}
|
|
|
|
|
2018-12-17 20:07:57 +08:00
|
|
|
delete p; // expected-warning {{Attempt to free released memory}}
|
|
|
|
// expected-note@-1 {{Attempt to free released memory}}
|
2013-03-25 09:35:45 +08:00
|
|
|
}
|
|
|
|
|
2013-04-16 08:22:55 +08:00
|
|
|
struct Odd {
|
|
|
|
void kill() {
|
|
|
|
delete this; // expected-note {{Memory is released}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(Odd *odd) {
|
|
|
|
odd->kill(); // expected-note{{Calling 'Odd::kill'}}
|
|
|
|
// expected-note@-1 {{Returning; memory was released}}
|
2018-12-17 20:07:57 +08:00
|
|
|
delete odd; // expected-warning {{Attempt to free released memory}}
|
|
|
|
// expected-note@-1 {{Attempt to free released memory}}
|
2013-04-16 08:22:55 +08:00
|
|
|
}
|
|
|
|
|