This is an archive of the discontinued LLVM Phabricator instance.

avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls
ClosedPublic

Authored by rsmith on Aug 3 2018, 5:07 PM.

Details

Summary

When a non-extended temporary object is created in a conditional branch, the lifetime of that temporary ends outside the conditional (at the end of the full-expression). If we're inserting lifetime markers, this means we can end up generating

if (some_cond) {
  lifetime.start(&tmp);
  Tmp::Tmp(&tmp);
}
// ...
if (some_cond) {
  lifetime.end(&tmp);
}

for a full-expression containing a subexpression of the form some_cond ? Tmp().x : 0. This patch moves the lifetime start for such a temporary out of the conditional branch so that we don't need to generate an additional basic block to hold the lifetime end marker.

This is disabled if we want precise lifetime markers (for asan's stack-use-after-scope checks) or of the temporary has a non-trivial destructor (in which case we'd generate an extra basic block anyway to hold the destructor call).

Diff Detail

Repository
rC Clang

Event Timeline

rsmith created this revision.Aug 3 2018, 5:07 PM
rsmith updated this revision to Diff 159143.Aug 3 2018, 5:23 PM

Add forgotten test file.

rjmccall added inline comments.Aug 3 2018, 6:10 PM
lib/CodeGen/CGExpr.cpp
521

Why only when optimization is enabled? This seems like a nice improvement regardless.

Also, please mention why this is disabled for destructed types in the comment, not just the commit message.

rsmith updated this revision to Diff 159153.Aug 3 2018, 6:20 PM
rsmith marked an inline comment as done.
rsmith added inline comments.
lib/CodeGen/CGExpr.cpp
521

The OptimizationLevel check is dead anyway (we don't emit lifetime markers unless we're optimizing or in use-after-scope mode). Removed.

rjmccall accepted this revision.Aug 3 2018, 6:23 PM

LGTM.

This revision is now accepted and ready to land.Aug 3 2018, 6:23 PM
This revision was automatically updated to reflect the committed changes.
rsmith marked an inline comment as done.