[analyzer] operator new: Use the correct region for the constructor.
authorArtem Dergachev <artem.dergachev@gmail.com>
Wed, 17 Jan 2018 22:34:23 +0000 (22:34 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Wed, 17 Jan 2018 22:34:23 +0000 (22:34 +0000)
commit5579630275ce2fc64d0c7acd27789442728d6555
tree910401a74edd1fe0a28fb407206c470bdbfbb0fd
parenta79b0620a08d94a58fd48787e78cc83924632ad8
[analyzer] operator new: Use the correct region for the constructor.

The -analyzer-config c++-allocator-inlining experimental option allows the
analyzer to reason about C++ operator new() similarly to how it reasons about
regular functions. In this mode, operator new() is correctly called before the
construction of an object, with the help of a special CFG element.

However, the subsequent construction of the object was still not performed into
the region of memory returned by operator new(). The patch fixes it.

Passing the value from operator new() to the constructor and then to the
new-expression itself was tricky because operator new() has no call site of its
own in the AST. The new expression itself is not a good call site because it
has an incorrect type (operator new() returns 'void *', while the new expression
is a pointer to the allocated object type). Additionally, lifetime of the new
expression in the environment makes it unsuitable for passing the value.
For that reason, an additional program state trait is introduced to keep track
of the return value.

Finally this patch relaxes restrictions on the memory region class that are
required for inlining the constructor. This change affects the old mode as well
(c++-allocator-inlining=false) and seems safe because these restrictions were
an overkill compared to the actual problems observed.

Differential Revision: https://reviews.llvm.org/D40560
rdar://problem/12180598

llvm-svn: 322774
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/test/Analysis/inline.cpp
clang/test/Analysis/new-ctor-conservative.cpp [new file with mode: 0644]
clang/test/Analysis/new-ctor-inlined.cpp [new file with mode: 0644]
clang/test/Analysis/new-ctor-recursive.cpp [new file with mode: 0644]
clang/test/Analysis/new-ctor-symbolic.cpp [new file with mode: 0644]