This is an archive of the discontinued LLVM Phabricator instance.

Fix some cases of incorrect handling of lifetime extended temporaries.
ClosedPublic

Authored by klimek on Jul 28 2014, 7:42 AM.

Details

Reviewers
jordan_rose
Summary

MaterializeTemporaryExpr already contains information about the lifetime
of the temporary; if the lifetime is not the full statement, we do not
want to emit a destructor at the end of the full statement for it.

Diff Detail

Event Timeline

klimek updated this revision to Diff 11944.Jul 28 2014, 7:42 AM
klimek retitled this revision from to Fix some cases of incorrect handling of lifetime extended temporaries..
klimek updated this object.
klimek edited the test plan for this revision. (Show Details)
klimek added a reviewer: jordan_rose.
klimek added subscribers: alexmc, Unknown Object (MLST).

Is there a test case that covers this bug?

jordan_rose edited edge metadata.Jul 28 2014, 9:16 AM

I second what Alex said, and also wonder if this affects existing destruction of lifetime-extended objects (which happens under the auto destructors path, and is also not quite correct).

Can't you write a CFG-based test case?

klimek updated this revision to Diff 11973.Jul 29 2014, 4:53 AM
klimek edited edge metadata.

Add tests and fix lifetime extensions in the face of the comma operator.

klimek updated this revision to Diff 11975.Jul 29 2014, 5:36 AM

Add tests for lifetime extension of multiple objects via initializer.

klimek updated this revision to Diff 11976.Jul 29 2014, 5:38 AM

Make test more readable.

jordan_rose accepted this revision.Jul 29 2014, 7:37 PM
jordan_rose edited edge metadata.

Can you add a test for the subobject case too, even though that doesn't work yet either?

const LifetimeExtend &ref = Aggregate{ 0, 1 }.a;
6;
// expect ~Aggregate here rather than ~LifetimeExtend

Other than that, this seems like a fine incremental improvement.

test/Analysis/cfg.cpp
421–429

I did not realize this worked. Huh. That's going to be fun.

This revision is now accepted and ready to land.Jul 29 2014, 7:37 PM
klimek closed this revision.Jul 30 2014, 1:47 AM

Submitted as r214292. Requested tests in upcoming patch (where they don't crash any more).