]> granicus.if.org Git - clang/commit
[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)
commit4a835575fd075b8d9f350183bd40c80cb1a64c64
tree5cd8df21d0c5f0a894337971439755031bc77cbe
parentca20a3aa6343b87121938f08207f8789ba76f1b7
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322774 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
lib/StaticAnalyzer/Core/ExprEngine.cpp
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
test/Analysis/inline.cpp
test/Analysis/new-ctor-conservative.cpp [new file with mode: 0644]
test/Analysis/new-ctor-inlined.cpp [new file with mode: 0644]
test/Analysis/new-ctor-recursive.cpp [new file with mode: 0644]
test/Analysis/new-ctor-symbolic.cpp [new file with mode: 0644]