[PATCH] D44597: [CFG] [analyzer] Add C++17-specific variable and return value construction contexts.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 16 18:36:53 PDT 2018


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

In C++17 copy elision is mandatory for variable and return value constructors (as long as it doesn't involve type conversion) which results in AST that does not contain elidable constructors in their usual places. In order to provide construction contexts in this scenario we need to cover more AST patterns.

This patch makes the CFG prepared for these scenarios by:

- Adding two new construction context classes: `CXX17ElidedCopyVariableConstructionContext` and `CXX17ElidedCopyReturnedValueConstructionContext`. These are forks of `SimpleVariableConstructionContext` and `ReturnedValueConstructionContext` which contain the additional `CXXBindTemporaryExpr` when it's found in the AST. Additionally, `ReturnedValueConstructionContext` is renamed into `SimpleReturnedValueConstructionContext`. Finally, common abstract base classes are introduced: `VariableConstructionContext` and `ReturnedValueConstructionContext`.
- Allowing `CFGCXXRecordTypedCall` element to accept `VariableConstructionContext` and `ReturnedValueConstructionContext` as its context.

`CXXBindTemporaryExpr` is assumed to be present iff the object has non-trivial destructor. If the object has trivial destructor then `CXXBindTemporaryExpr` is not there, and the AST is pretty much indistinguishable from the simple case so we re-use  `SimpleVariableConstructionContext` and `SimpleReturnedValueConstructionContext`. I'm not entirely sure that this is indeed the same case, but for the purposes of the analyzer, which is the primary user of construction contexts, this seems fine because when the object has trivial destructor it is not scary to inline the constructor. When the object requires non-trivial destruction, the new construction context is provided, and the analyzer bails out (with the hope of falling back to the pre-temporary-support behavior) for now - but more work seems to be necessary on the analyzer side to prevent it from crashing during actual analysis.


Repository:
  rC Clang

https://reviews.llvm.org/D44597

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44597.138804.patch
Type: text/x-patch
Size: 42343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180317/32c5141d/attachment-0001.bin>


More information about the cfe-commits mailing list