[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 14 20:44:41 PDT 2021
NoQ added inline comments.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:207
+
+ const auto PtrVal = C.getSValBuilder().conjureSymbolVal(
+ Call.getOriginExpr(), C.getLocationContext(),
----------------
Can you do a `getConjuredHeapSymbolVal()` instead? That'd give us the right memory space as well as the extra bit of information that the new symbol doesn't alias with any previous symbols.
I get it that it doesn't accept the type but it's perfectly ok for you to teach it how to accept the type.
================
Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:339
+void makeUniqueForOverwriteReturnsNullUniquePtr() {
+ auto P = std::make_unique_for_overwrite<A>(); // expected-note {{std::unique_ptr 'P' constructed by std::make_unique_for_overwrite is null}}
+ *P; // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
----------------
Mmm wait a sec, that doesn't look like what the spec says.
https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique:
> Same as (1), except that the object is default-initialized. This overload participates in overload resolution only if T is not an array type. The function is equivalent to `unique_ptr<T>(new T)`
It zero-initializes the //pointee//, not the //pointer//.
The difference between `std::make_unique<A>()` and `std::make_unique_for_overwrite<A>()` is the difference between value-initialization (invoking the default constructor) and zero-initialization (simply filling the buffer with `0`s).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103750/new/
https://reviews.llvm.org/D103750
More information about the cfe-commits
mailing list