Page MenuHomePhabricator

[CFG] [analyzer] Add MaterializeTemporaryExpr into the construction context.
ClosedPublic

Authored by NoQ on Feb 19 2018, 11:57 AM.

Details

Summary

MaterializeTemporaryExpr captures lifetime extension information. In the analyzer it is important to have this information at construction site because we would be dealing only with rvalue expressions for quite a while, but in order to perform lifetime extension later, we need to put extra effort into keeping the lvalue around.

MaterializeTemporaryExpr is added either as a trigger statement if there's no CXXBindTemporaryExpr within it (eg. const C &c(123); or the actual (not the elidable copy) constructor in C foo() { return C(123); }), or as a parent construction context if there already is a CXXBindTemporary. In the latter case, it is included in the dump and tested accordingly. I understand that this is quite counter-intuitive at the moment (easy to construct, hard to use) and i'd make super sure that ConstructionContext is refactored later to become easy to understand and work with - separation of different "kinds" of construction contexts and fancy kind-specific helper methods are absolutely necessary. But for now i'm focused on getting it to work.

Diff Detail

Repository
rC Clang

Event Timeline

NoQ created this revision.Feb 19 2018, 11:57 AM
NoQ added a comment.Feb 19 2018, 12:46 PM

eg. const C &c(123); or the actual (not the elidable copy) constructor in C foo() { return C(123); }

Emm, sry, never mind, forget it, i was trying to say that the reason why we don't have a CXXBindTemporary is because we don't have a destructor in class C, not because we have specific syntax patterns.

This fix does not cause changes in the analyzer yet. Even though we are providing construction contexts in a bit more cases, and even if we used them in the analyzer, we wouldn't get any functional change yet, because temporary constructors that require no destructors are inlined anyway, regardless of construction context, and an exact same temporary region is accidentally created for them. So the point of this patch is not to make more construction contexts available, but to provide better construction contexts in the CXXBindTemporary case, which will be used later.

This revision is now accepted and ready to land.Feb 20 2018, 8:44 PM
Closed by commit rC326014: [CFG] Provide construction contexts for lifetime-extended temporaries. (authored by dergachev, committed by ). · Explain Why
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.