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}}
|
[analyzer] ConditionBRVisitor: Enhance to write out more information
Summary:
Add extra messages to the bug report to inform the user why the analyzer
`Taking true/false branch`.
Reviewers: NoQ, george.karpenkov
Reviewed By: NoQ
Subscribers: gerazo, gsd, dkrupp, whisperity, baloghadamsoftware, xazax.hun,
eraman, szepet, a.sidorin, mikhail.ramalho, Szelethus,
donat.nagy, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53076
llvm-svn: 362020
2019-05-30 04:06:09 +08:00
|
|
|
if (p) // expected-note {{'p' is non-null}}
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|