[PATCH] D47671: [analyzer] Implement copy elision.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 1 19:30:01 PDT 2018


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

This patch builds on top of https://reviews.llvm.org/D47616 to elide pre-C++17 elidable constructors during analysis. They are present in the AST and in the CFG but they'll be skipped during analysis, as planned in http://lists.llvm.org/pipermail/cfe-dev/2018-March/057318.html

It also elides destructors that correspond to elided constructors, and for that i had to add another program state trait, because the universal state trait i added previously had no room for this flag.

The main idea is straightforward. Construction context for the elidable constructor can already be retrieved from construction context of the inner "temporary" constructor. Therefore upon constructing the "temporary", we can use the target region of the elided constructor (which isn't necessarily a temporary region). Then we flag the elidable constructor's `CXXConstructExpr` in the program state and track what target region was already computed for it. Upon encountering the elidable construct-expression during analysis, we don't perform construction, but only assign the value to the expression.

Temporary materialization becomes funny because temporary can now be materialized into a non-temporary region. But the algorithm has not changed much.

Massive changes in the tests indicate that copy elision is in fact working as intended. I also extended tests to track whether there were conservatively evaluated calls (those `glob` tests in `cxx17-mandatory-elision.cpp`). They indicate the problem with C++17 CFG that still contains destructors for C++17-mandatory-ly elided constructors. I could easily mark them as "elided", but it'd be better to never add them to the CFG in the first place.

I'm not sure we need an `-analyzer-config` flag for disabling this feature, though i wouldn't mind adding one.


Repository:
  rC Clang

https://reviews.llvm.org/D47671

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/cxx17-mandatory-elision.cpp
  test/Analysis/gtest.cpp
  test/Analysis/inlining/temp-dtors-path-notes.cpp
  test/Analysis/lifetime-extension.cpp
  test/Analysis/temporaries.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47671.149598.patch
Type: text/x-patch
Size: 39614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180602/dec43ad9/attachment-0001.bin>


More information about the cfe-commits mailing list