Enabling the SmartPtrModeling to handle swap method for unique_ptr
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
clang/test/Analysis/smart-ptr.cpp | ||
---|---|---|
131 | I will fix this. |
LGTM, thanks!
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
---|---|---|
965 | Maybe it is worth to add a TODO to introduce an additional template parameter once the deleter is added above. | |
clang/test/Analysis/smart-ptr.cpp | ||
124 | This test case is very similar to the first one. Maybe you could move them closer. And you could make both pointers invalid to make them more distinct. |
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
---|---|---|
964–965 | You seem to be relying on the fact that global std::swap is implemented in terms of the member std::swap. That's an implementation detail of the standard library; i'm not sure that this is always the case. Ideally we should model the global std::swap separately. |
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
---|---|---|
964–965 | I am not sure how reliable cppreference is, but I think this overload might actually be guaranteed by the standard: https://en.cppreference.com/w/cpp/memory/unique_ptr/swap2 |
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp | ||
---|---|---|
198 | I think it would be good to add some comments in the body of the function to be more explicit about the situation you are handling. | |
224–228 | These two if's are clearly duplicates and it seems like a good candidate for a separate function. | |
clang/test/Analysis/smart-ptr.cpp | ||
124 | +1 |
- Changes from review comments
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp | ||
---|---|---|
198 | Added comments | |
224–228 | Thanks! | |
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
964–965 | I also made the assumption based on this (https://en.cppreference.com/w/cpp/memory/unique_ptr/swap2). | |
965 | Added the TODO | |
clang/test/Analysis/smart-ptr.cpp | ||
124 | Moved and made both pointers invalid in the test | |
131 | Fixed |
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
---|---|---|
964–965 | Aha, interesting. We still probably can't rely on it being always inlined though, so we'll still probably have to model it separately. |
I have already committed this changes.
https://github.com/llvm/llvm-project/commit/76c0577763505ea3db1017a9aab579c1c2f135d0
clang/test/Analysis/Inputs/system-header-simulator-cxx.h | ||
---|---|---|
964–965 | Okay. We will add the separate modeling for std::swap |
clang-format not found in user's PATH; not linting file.