[PATCH] D48681: [CFG] [analyzer] Add construction contexts for function arguments.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 27 16:27:48 PDT 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, baloghadamsoftware.

Replace stubs we had to discriminate between temporaries and function arguments with actual construction contexts for arguments. Make them visible in the CFG. Which means that when there's an argument constructor in the CFG, it'll now be a `CFGConstructor` element (or a `CFGCXXRecordTypedCall` element if it's a temporary produced by a function call in C++17 where copy elision is mandatory) that will augment the construct-expression with the information about the constructed object  - that it's argument #N of a certain function call.

On the analyzer side, the patch interacts with the recently implemented pre-C++17 copy elision support (https://reviews.llvm.org/D47616, https://reviews.llvm.org/D47671) in an interesting manner. If on the CFG side we didn't find a construction context for the elidable constructor, we build the CFG as if the elidable constructor is not elided, and the non-elided constructor within it is a simple temporary. But the same problem may occur in the analyzer: if the elidable constructor has a construction context but the analyzer doesn't implement such context yet, the analyzer should also try to skip copy elision and still inline the non-elided temporary constructor. This was implemented by adding a "roll back" mechanism: when elision fails, roll back the changes and proceed as if it's a simple temporary. The approach is wonky, but i'm fine with that as long as it's merely a defensive mechanism that should eventually go away once all construction contexts become supported.


Repository:
  rC Clang

https://reviews.llvm.org/D48681

Files:
  include/clang/Analysis/CFG.h
  include/clang/Analysis/ConstructionContext.h
  lib/Analysis/CFG.cpp
  lib/Analysis/ConstructionContext.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/cfg-rich-constructors.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48681.153199.patch
Type: text/x-patch
Size: 19966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180627/0679b77f/attachment-0001.bin>


More information about the cfe-commits mailing list