[PATCH] D98726: [analyzer] Remove unnecessary TODO
Deep Majumder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 16 10:55:54 PDT 2021
RedDocMD created this revision.
RedDocMD added reviewers: NoQ, vsavchenko, steakhal.
Herald added subscribers: ASDenysPetrov, martong, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
RedDocMD requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This I think should not be a TODO, since MallocChecker indeed does track
released pointers. I have added a test for that.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98726
Files:
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
clang/test/Analysis/smart-ptr-text-output.cpp
Index: clang/test/Analysis/smart-ptr-text-output.cpp
===================================================================
--- clang/test/Analysis/smart-ptr-text-output.cpp
+++ clang/test/Analysis/smart-ptr-text-output.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_analyze_cc1\
-// RUN: -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN: -analyzer-checker=core,cplusplus.Move,cplusplus.NewDelete,alpha.cplusplus.SmartPtr\
// RUN: -analyzer-config cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
// RUN: -analyzer-output=text -std=c++11 %s -verify=expected
@@ -43,6 +43,14 @@
// expected-note at -1{{Dereference of null smart pointer 'P'}}
}
+void derefOfReleasedPtr(A *oldptr) {
+ std::unique_ptr<A> P(oldptr);
+ A* aptr = P.release();
+ delete aptr; // expected-note {{Memory is released}}
+ aptr->foo(); // expected-warning {{Use of memory after it is freed [cplusplus.NewDelete]}}
+ // expected-note at -1{{Use of memory after it is freed}}
+}
+
void derefAfterReset() {
std::unique_ptr<A> P(new A()); // expected-note {{Smart pointer 'P' is constructed}}
P.reset(); // expected-note {{Smart pointer 'P' reset using a null value}}
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -13,6 +13,7 @@
#include "Move.h"
#include "SmartPtr.h"
+#include "AllocationState.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclarationName.h"
@@ -391,8 +392,6 @@
checkAndPrettyPrintRegion(OS, ThisRegion);
OS << " is released and set to null";
}));
- // TODO: Add support to enable MallocChecker to start tracking the raw
- // pointer.
}
void SmartPtrModeling::handleSwap(const CallEvent &Call,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98726.331044.patch
Type: text/x-patch
Size: 1859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210316/58bbd210/attachment.bin>
More information about the cfe-commits
mailing list