[PATCH] D42876: [analyzer] Support returning objects by value.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 18:28:08 PST 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.
NoQ added dependencies: D42875: [analyzer] Add construction context for ReturnStmt., D42779: [analyzer] NFC: Make sure we don't ever inline the constructor for which the temporary destructor is noreturn and missing..
NoQ added a dependency: D42721: [analyzer] NFC: Use construction contexts for finding the target region for the construction..

Now that we've added the necessary information into the CFG in https://reviews.llvm.org/D42875, we can use it to support returning objects by value.

Unfortunately, we still do not support the constructions into temporaries which are later copied via copy-constructors, which is common in statements like `return Class()`. But we can still support objects constructed in a different manner, say `return getObject()` or `return { 1, 2 }`. Also, we've always supported `return Obj;` when `Obj` has a trivial copy constructor, but now we support it even when the constructor is non-trivial.

This patch adds a facility to prevent the new approach from being activated when temporary destructors are disabled, because we have a mechanism for suppressing hilarious false positives that wouldn't work in this case - see https://reviews.llvm.org/D42779. Namely, i'm adding a new `EvalCallOption` that will indicate that we're constructing a temporary object.


Repository:
  rC Clang

https://reviews.llvm.org/D42876

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/temporaries.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42876.132718.patch
Type: text/x-patch
Size: 9732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180203/2c48bc5a/attachment-0001.bin>


More information about the cfe-commits mailing list