From 09e86e77c903f7be16a4924c543800428eaf9a6d Mon Sep 17 00:00:00 2001 From: Kristof Umann Date: Mon, 17 Dec 2018 12:07:57 +0000 Subject: [PATCH] Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions' llvm-svn: 349340 --- .../StaticAnalyzer/Checkers/MallocChecker.cpp | 14 +++---------- .../NewDelete-path-notes.cpp.plist | 20 +++++++++---------- ...Malloc+MismatchedDeallocator+NewDelete.cpp | 2 +- .../test/Analysis/NewDelete-checker-test.cpp | 2 +- clang/test/Analysis/NewDelete-path-notes.cpp | 8 ++++---- clang/test/Analysis/dtor.cpp | 2 +- 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index b56c55d666c3..a5b774fe248d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -137,7 +137,7 @@ class RefState { const Stmt *S; Kind K : 3; - AllocationFamily Family : 29; + AllocationFamily Family : 3; RefState(Kind k, const Stmt *s, AllocationFamily family) : S(s), K(k), Family(family) { @@ -1431,8 +1431,7 @@ ProgramStateRef MallocChecker::addExtentSize(CheckerContext &C, void MallocChecker::checkPreStmt(const CXXDeleteExpr *DE, 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 (SymbolRef Sym = C.getSVal(DE->getArgument()).getAsSymbol()) 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 -/// failed, returns true. Also, stores the corresponding return value symbol in -/// \p RetStatusSymbol. +/// failed, returns true. Also, returns the corresponding return value symbol. static bool didPreviousFreeFail(ProgramStateRef State, SymbolRef Sym, SymbolRef &RetStatusSymbol) { const SymbolRef *Ret = State->get(Sym); @@ -2291,12 +2289,6 @@ void MallocChecker::ReportDoubleFree(CheckerContext &C, SourceRange Range, if (!CheckKind.hasValue()) 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 (!BT_DoubleFree[*CheckKind]) BT_DoubleFree[*CheckKind].reset(new BugType( diff --git a/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist b/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist index 6a3a3d30c4e1..d74d9fc7c677 100644 --- a/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist +++ b/clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist @@ -194,17 +194,17 @@ depth0 extended_message - Attempt to delete released memory + Attempt to free released memory message - Attempt to delete released memory + Attempt to free released memory - descriptionAttempt to delete released memory + descriptionAttempt to free released memory categoryMemory error - typeDouble delete + typeDouble free check_namecplusplus.NewDelete - issue_hash_content_of_line_in_context593b185245106bed5175ccf2753039b2 + issue_hash_content_of_line_in_contextbd8e324d09c70b9e2be6f824a4942e5a issue_context_kindfunction issue_contexttest issue_hash_function_offset8 @@ -423,17 +423,17 @@ depth0 extended_message - Attempt to delete released memory + Attempt to free released memory message - Attempt to delete released memory + Attempt to free released memory - descriptionAttempt to delete released memory + descriptionAttempt to free released memory categoryMemory error - typeDouble delete + typeDouble free check_namecplusplus.NewDelete - issue_hash_content_of_line_in_context6484e9b006ede7362edef2187ba6eb37 + issue_hash_content_of_line_in_context8bf1a5b9fdae9d86780aa6c4cdce2605 issue_context_kindfunction issue_contexttest issue_hash_function_offset3 diff --git a/clang/test/Analysis/Malloc+MismatchedDeallocator+NewDelete.cpp b/clang/test/Analysis/Malloc+MismatchedDeallocator+NewDelete.cpp index e5176eb50fff..b5e47b3355da 100644 --- a/clang/test/Analysis/Malloc+MismatchedDeallocator+NewDelete.cpp +++ b/clang/test/Analysis/Malloc+MismatchedDeallocator+NewDelete.cpp @@ -46,7 +46,7 @@ void testMismatchedDeallocator() { void testNewDoubleFree() { int *p = new int; delete p; - delete p; // expected-warning{{Attempt to delete released memory}} + delete p; // expected-warning{{Attempt to free released memory}} } void testNewLeak() { diff --git a/clang/test/Analysis/NewDelete-checker-test.cpp b/clang/test/Analysis/NewDelete-checker-test.cpp index fcbe2c740239..620237cd6ede 100644 --- a/clang/test/Analysis/NewDelete-checker-test.cpp +++ b/clang/test/Analysis/NewDelete-checker-test.cpp @@ -182,7 +182,7 @@ void testUseThisAfterDelete() { void testDoubleDelete() { int *p = new int; delete p; - delete p; // expected-warning{{Attempt to delete released memory}} + delete p; // expected-warning{{Attempt to free released memory}} } void testExprDeleteArg() { diff --git a/clang/test/Analysis/NewDelete-path-notes.cpp b/clang/test/Analysis/NewDelete-path-notes.cpp index 94658360fbcb..d9fe1976b826 100644 --- a/clang/test/Analysis/NewDelete-path-notes.cpp +++ b/clang/test/Analysis/NewDelete-path-notes.cpp @@ -11,8 +11,8 @@ void test() { delete p; // expected-note@-1 {{Memory is released}} - delete p; // expected-warning {{Attempt to delete released memory}} - // expected-note@-1 {{Attempt to delete released memory}} + delete p; // expected-warning {{Attempt to free released memory}} + // expected-note@-1 {{Attempt to free released memory}} } struct Odd { @@ -24,7 +24,7 @@ struct Odd { void test(Odd *odd) { odd->kill(); // expected-note{{Calling 'Odd::kill'}} // expected-note@-1 {{Returning; memory was released}} - delete odd; // expected-warning {{Attempt to delete released memory}} - // expected-note@-1 {{Attempt to delete released memory}} + delete odd; // expected-warning {{Attempt to free released memory}} + // expected-note@-1 {{Attempt to free released memory}} } diff --git a/clang/test/Analysis/dtor.cpp b/clang/test/Analysis/dtor.cpp index 2ea38e95c87b..d843f03aada7 100644 --- a/clang/test/Analysis/dtor.cpp +++ b/clang/test/Analysis/dtor.cpp @@ -528,7 +528,7 @@ struct NonTrivial { return *this; } ~NonTrivial() { - delete[] p; // expected-warning {{delete released memory}} + delete[] p; // expected-warning {{free released memory}} } };