]> granicus.if.org Git - clang/commit
[analyzer] Assume that the allocated value is non-null before construction.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 24 Jan 2018 20:32:26 +0000 (20:32 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 24 Jan 2018 20:32:26 +0000 (20:32 +0000)
commit0ecda274ef03a5908e5ea9d7dedbe1c564486de6
tree4d2a067bd11e2639ebb7f1063e233621bd66aa2b
parent4e56966f84ebf321114a0269f8f3efd1027bda6a
[analyzer] Assume that the allocated value is non-null before construction.

I.e. not after. In the c++-allocator-inlining=true mode, we need to make the
assumption that the conservatively evaluated operator new() has returned a
non-null value. Previously we did this on CXXNewExpr, but now we have to do that
before calling the constructor, because some clever constructors are sometimes
assuming that their "this" is null and doing weird stuff. We would also crash
upon evaluating CXXNewExpr when the allocator was inlined and returned null and
had a throw specification; this is UB even for custom allocators, but we still
need not to crash.

Added more FIXME tests to ensure that eventually we fix calling the constructor
for null return values.

Differential Revision: https://reviews.llvm.org/D42192

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323370 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
test/Analysis/new-ctor-conservative.cpp
test/Analysis/new-ctor-null-throw.cpp [new file with mode: 0644]
test/Analysis/new-ctor-null.cpp