[PATCH] D81315: [Draft] [Prototype] warning for default constructed unique pointer dereferences
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 8 03:46:43 PDT 2020
NoQ added inline comments.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:72-76
+ // STL smart pointer methods which resets to null
+ const llvm::StringSet<> ResetMethods = {"reset", "release", "swap"};
+
+ // STL smart pointer methods which resets to null via null argument
+ const llvm::StringSet<> NullResetMethods = {"reset", "swap"};
----------------
Please consider `CallDescription` and `CallDescriptionMap`!
================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:81
+// to track the mem region and curresponding states
+REGISTER_MAP_WITH_PROGRAMSTATE(TrackedRegionMap, const MemRegion *, RegionState)
+// to track the Symbols which will get inner raw pointer via unique_ptr.get()
----------------
I ultimately believe this map should go away. The only thing we really need is the map from smart pointer region to the symbol for its current raw pointer. As long as we have such data we can discover the nullness of that symbol (which *is* the nullness of the smart pointer as well) from Range Constraints.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:213-214
+
+ if (!BT)
+ BT.reset(new BugType(this, "unique_ptr", "Dont call unique_ptr"));
+ auto R = std::make_unique<PathSensitiveBugReport>(
----------------
These days we don't bother with lazy initialization, the usual syntax is:
```lang=c++
class YourChecker {
// ...
BugType BT { this, "unique_ptr", "Dont call unique_ptr" };
// ...
};
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81315/new/
https://reviews.llvm.org/D81315
More information about the cfe-commits
mailing list