[PATCH] D43056: [CFG] [analyzer] Add construction context for CXXBindTemporaryExpr.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 17:14:26 PST 2018


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

This covers temporary constructors for which a destructor is necessary. It is necessary to support `CXXTemporaryObjectExpr` here, which is a "constructor in the middle of nowhere" expression like `C()` - it's a sub-class of `CXXConstructExpr` which we didn't even notice yet because it didn't appear in construction contexts we added support for in the previous patches, but it does commonly appear in `CXXBindTemporaryExpr`s and failing to consume the construction context would trigger the construction context overwrite assertion.

Note that when the destructor is trivial, `CXXBindTemporaryExpr` is omitted, and in that case we don't provide any construction context yet. In such cases there's no trigger statement at all, for example the following code:

  struct S {};
  
  void foo() {
    S();
  }

would produce the following AST:

  `-FunctionDecl 0x7fea280366a0 <line:3:1, line:5:1> line:3:6 foo 'void ()'
    `-CompoundStmt 0x7fea28036d98 <col:12, line:5:1>
      `-CXXTemporaryObjectExpr 0x7fea28036c70 <line:4:3, col:5> 'S' 'void () noexcept' zeroing

... and that's it.

So in that case we'd have to make a special kind of construction context that merely conveys that we are sure that we are indeed constructing a simple temporary object because we were directly told to do so by the programmer. But that's another story.


Repository:
  rC Clang

https://reviews.llvm.org/D43056

Files:
  lib/Analysis/CFG.cpp
  test/Analysis/auto-obj-dtors-cfg-output.cpp
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43056.133341.patch
Type: text/x-patch
Size: 31258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180208/d0eb5fc6/attachment-0001.bin>


More information about the cfe-commits mailing list