Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'

llvm-svn: 349340
This commit is contained in:
Kristof Umann 2018-12-17 12:07:57 +00:00
parent 357973192d
commit 09e86e77c9
6 changed files with 20 additions and 28 deletions

View File

@ -137,7 +137,7 @@ class RefState {
const Stmt *S; const Stmt *S;
Kind K : 3; Kind K : 3;
AllocationFamily Family : 29; AllocationFamily Family : 3;
RefState(Kind k, const Stmt *s, AllocationFamily family) RefState(Kind k, const Stmt *s, AllocationFamily family)
: S(s), K(k), Family(family) { : S(s), K(k), Family(family) {
@ -1431,8 +1431,7 @@ ProgramStateRef MallocChecker::addExtentSize(CheckerContext &C,
void MallocChecker::checkPreStmt(const CXXDeleteExpr *DE, void MallocChecker::checkPreStmt(const CXXDeleteExpr *DE,
CheckerContext &C) const { CheckerContext &C) const {
// This will regard deleting freed() regions as a use-after-free, rather then
// a double-free or double-delete error.
if (!ChecksEnabled[CK_NewDeleteChecker]) if (!ChecksEnabled[CK_NewDeleteChecker])
if (SymbolRef Sym = C.getSVal(DE->getArgument()).getAsSymbol()) if (SymbolRef Sym = C.getSVal(DE->getArgument()).getAsSymbol())
checkUseAfterFree(Sym, C, DE->getArgument()); checkUseAfterFree(Sym, C, DE->getArgument());
@ -1629,8 +1628,7 @@ ProgramStateRef MallocChecker::FreeMemAux(CheckerContext &C,
} }
/// Checks if the previous call to free on the given symbol failed - if free /// Checks if the previous call to free on the given symbol failed - if free
/// failed, returns true. Also, stores the corresponding return value symbol in /// failed, returns true. Also, returns the corresponding return value symbol.
/// \p RetStatusSymbol.
static bool didPreviousFreeFail(ProgramStateRef State, static bool didPreviousFreeFail(ProgramStateRef State,
SymbolRef Sym, SymbolRef &RetStatusSymbol) { SymbolRef Sym, SymbolRef &RetStatusSymbol) {
const SymbolRef *Ret = State->get<FreeReturnValue>(Sym); const SymbolRef *Ret = State->get<FreeReturnValue>(Sym);
@ -2291,12 +2289,6 @@ void MallocChecker::ReportDoubleFree(CheckerContext &C, SourceRange Range,
if (!CheckKind.hasValue()) if (!CheckKind.hasValue())
return; return;
// If this is a double delete error, print the appropiate warning message.
if (CheckKind == CK_NewDeleteChecker) {
ReportDoubleDelete(C, Sym);
return;
}
if (ExplodedNode *N = C.generateErrorNode()) { if (ExplodedNode *N = C.generateErrorNode()) {
if (!BT_DoubleFree[*CheckKind]) if (!BT_DoubleFree[*CheckKind])
BT_DoubleFree[*CheckKind].reset(new BugType( BT_DoubleFree[*CheckKind].reset(new BugType(

View File

@ -194,17 +194,17 @@
</array> </array>
<key>depth</key><integer>0</integer> <key>depth</key><integer>0</integer>
<key>extended_message</key> <key>extended_message</key>
<string>Attempt to delete released memory</string> <string>Attempt to free released memory</string>
<key>message</key> <key>message</key>
<string>Attempt to delete released memory</string> <string>Attempt to free released memory</string>
</dict> </dict>
</array> </array>
<key>description</key><string>Attempt to delete released memory</string> <key>description</key><string>Attempt to free released memory</string>
<key>category</key><string>Memory error</string> <key>category</key><string>Memory error</string>
<key>type</key><string>Double delete</string> <key>type</key><string>Double free</string>
<key>check_name</key><string>cplusplus.NewDelete</string> <key>check_name</key><string>cplusplus.NewDelete</string>
<!-- This hash is experimental and going to change! --> <!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>593b185245106bed5175ccf2753039b2</string> <key>issue_hash_content_of_line_in_context</key><string>bd8e324d09c70b9e2be6f824a4942e5a</string>
<key>issue_context_kind</key><string>function</string> <key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>test</string> <key>issue_context</key><string>test</string>
<key>issue_hash_function_offset</key><string>8</string> <key>issue_hash_function_offset</key><string>8</string>
@ -423,17 +423,17 @@
</array> </array>
<key>depth</key><integer>0</integer> <key>depth</key><integer>0</integer>
<key>extended_message</key> <key>extended_message</key>
<string>Attempt to delete released memory</string> <string>Attempt to free released memory</string>
<key>message</key> <key>message</key>
<string>Attempt to delete released memory</string> <string>Attempt to free released memory</string>
</dict> </dict>
</array> </array>
<key>description</key><string>Attempt to delete released memory</string> <key>description</key><string>Attempt to free released memory</string>
<key>category</key><string>Memory error</string> <key>category</key><string>Memory error</string>
<key>type</key><string>Double delete</string> <key>type</key><string>Double free</string>
<key>check_name</key><string>cplusplus.NewDelete</string> <key>check_name</key><string>cplusplus.NewDelete</string>
<!-- This hash is experimental and going to change! --> <!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>6484e9b006ede7362edef2187ba6eb37</string> <key>issue_hash_content_of_line_in_context</key><string>8bf1a5b9fdae9d86780aa6c4cdce2605</string>
<key>issue_context_kind</key><string>function</string> <key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>test</string> <key>issue_context</key><string>test</string>
<key>issue_hash_function_offset</key><string>3</string> <key>issue_hash_function_offset</key><string>3</string>

View File

@ -46,7 +46,7 @@ void testMismatchedDeallocator() {
void testNewDoubleFree() { void testNewDoubleFree() {
int *p = new int; int *p = new int;
delete p; delete p;
delete p; // expected-warning{{Attempt to delete released memory}} delete p; // expected-warning{{Attempt to free released memory}}
} }
void testNewLeak() { void testNewLeak() {

View File

@ -182,7 +182,7 @@ void testUseThisAfterDelete() {
void testDoubleDelete() { void testDoubleDelete() {
int *p = new int; int *p = new int;
delete p; delete p;
delete p; // expected-warning{{Attempt to delete released memory}} delete p; // expected-warning{{Attempt to free released memory}}
} }
void testExprDeleteArg() { void testExprDeleteArg() {

View File

@ -11,8 +11,8 @@ void test() {
delete p; delete p;
// expected-note@-1 {{Memory is released}} // expected-note@-1 {{Memory is released}}
delete p; // expected-warning {{Attempt to delete released memory}} delete p; // expected-warning {{Attempt to free released memory}}
// expected-note@-1 {{Attempt to delete released memory}} // expected-note@-1 {{Attempt to free released memory}}
} }
struct Odd { struct Odd {
@ -24,7 +24,7 @@ struct Odd {
void test(Odd *odd) { void test(Odd *odd) {
odd->kill(); // expected-note{{Calling 'Odd::kill'}} odd->kill(); // expected-note{{Calling 'Odd::kill'}}
// expected-note@-1 {{Returning; memory was released}} // expected-note@-1 {{Returning; memory was released}}
delete odd; // expected-warning {{Attempt to delete released memory}} delete odd; // expected-warning {{Attempt to free released memory}}
// expected-note@-1 {{Attempt to delete released memory}} // expected-note@-1 {{Attempt to free released memory}}
} }

View File

@ -528,7 +528,7 @@ struct NonTrivial {
return *this; return *this;
} }
~NonTrivial() { ~NonTrivial() {
delete[] p; // expected-warning {{delete released memory}} delete[] p; // expected-warning {{free released memory}}
} }
}; };