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

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 17:50:27 PST 2018


NoQ planned changes to this revision.
NoQ added a comment.

Destructor for the returned temporary is still evaluated conservatively:

  class C {
  public:
    int &x, &y;
    C(int &_x, int &_y) : x(_x), y(_y) { ++x; }
    C(const C &c) : x(c.x), y(c.y) { ++x; }
    ~C() { ++y; }
  };
  
  C make(int &x, int &y) {
    return { x, y };
  }
  
  void test() {
    int x = 0, y = 0;
    {
      C c = make(x, y);
    }
    clang_analyzer_dump(x); // 2 S32b
    clang_analyzer_dump(y); // 1 S32b
  }

Also there's a weird rebound at the call site - from the callee-context-temporary to the caller-context-temporary - which is currently implemented as a trivial copy and not a full-featured constructor call. I guess there shouldn't be a copy here (because there is no constructor or assignment operator), so i suspect we should directly construct into the caller context's temporary for the call-expression.

These issues are known, i'm just pointing out that we'd need to tackle them to make at least this simple example work correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D42876





More information about the cfe-commits mailing list