[PATCH] D108753: [analyzer] MallocChecker: Add notes from NoOwnershipChangeVisitor only when a function "intents", but doesn't change ownership, enable by default
Kristóf Umann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 26 02:47:06 PDT 2021
Szelethus created this revision.
Szelethus added reviewers: NoQ, martong, steakhal, balazske, ASDenysPetrov, vsavchenko.
Szelethus added a project: clang.
Herald added subscribers: manas, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, whisperity, yaxunl.
Szelethus requested review of this revision.
Herald added a subscriber: cfe-commits.
D105819 <https://reviews.llvm.org/D105819> Added NoOwnershipChangeVisitor, but it is only registered when an off-by-default, hidden checker option was enabled. The reason behind this was that it grossly overestimated the set of functions that really needed a note:
std::string getTrainName(const Train *T) {
return T->name;
} // note: Retuning without changing the ownership of or deallocating memory
// Umm... I mean duh? Nor would I expect this function to do anything like that...
void foo() {
Train *T = new Train("Land Plane");
print(getTrainName(T)); // note: calling getTrainName / returning from getTrainName
} // warn: Memory leak
This patch adds a heuristic that guesses that any function that has an explicit `operator delete` call could have be responsible for deallocating the memory that ended up leaking. This is waaaay too conservative (see the TODOs in the new function), but it safer to err on the side of too little than too much, and would allow us to enable the option by default *now*, and add refinements one-by-one.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108753
Files:
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/NewDeleteLeaks.cpp
clang/test/Analysis/analyzer-config.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108753.368836.patch
Type: text/x-patch
Size: 4968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210826/1b6ffce1/attachment.bin>
More information about the cfe-commits
mailing list