This is an archive of the discontinued LLVM Phabricator instance.

[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr
ClosedPublic

Authored by timshen on May 20 2016, 3:35 PM.

Details

Summary

These ExprWithCleanups are added for holding a RunCleanupsScope not
for destructor calls; rather, they are for lifetime marks. This requires
ExprWithCleanups to keep a bit to indicate whether it have cleanups with
side effects (e.g. dtor calls).

Diff Detail

Repository
rL LLVM

Event Timeline

timshen updated this revision to Diff 58013.May 20 2016, 3:35 PM
timshen retitled this revision from to [Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.
timshen updated this object.
timshen added a reviewer: rsmith.
timshen added a subscriber: cfe-commits.
rsmith added inline comments.May 20 2016, 5:05 PM
include/clang/AST/ExprCXX.h
2871–2872 ↗(On Diff #58013)

You may as well put this in the bitfield storage on Stmt.

include/clang/Sema/CleanupInfo.h
31 ↗(On Diff #58013)

Should this be |=?

include/clang/Sema/Sema.h
444 ↗(On Diff #58013)

ExprNeedsCleanups -> ExprWithCleanups

lib/AST/Expr.cpp
2906–2907 ↗(On Diff #58013)

You should only return true if IncludePossibleEffects -- cleanupsHaveSideEffects means there might be a side-effect, not that there definitely is one. (This is a pre-existing bug.)

lib/Sema/SemaExpr.cpp
4579 ↗(On Diff #58013)

This should inherit the side-effects flag from the ExprWithCleanups in the default argument.

lib/Sema/SemaInit.cpp
6190–6191 ↗(On Diff #58013)

Please also sink the calls to mark the destructor referenced and check its access into here too. We should keep the checks for a usable destructor and the triggering of an ExprWithCleanups for the destructor together.

rsmith added inline comments.May 20 2016, 5:12 PM
lib/Sema/SemaExprCXX.cpp
5636–5639 ↗(On Diff #58013)

Please pass these flags into ::Create rather than using a setter. Generally, we aim for the AST to be immutable once created.

lib/Sema/SemaInit.cpp
6191 ↗(On Diff #58013)

I think this may set ExprNeedsCleanups even when unnecessary, if the MTE is lifetime-extended (I think you only actually want an ExprWithCleanups if the storage duration is SD_Automatic). We can't really deal with that here, because we don't know the storage duration of the MTE yet, but please add a FIXME here to not set ExprNeedsCleanups if the temporary is lifetime-extended.

timshen updated this revision to Diff 58676.May 26 2016, 1:03 PM

Update to reflect the comments.

timshen marked 7 inline comments as done.May 26 2016, 1:09 PM
timshen added inline comments.
lib/Sema/SemaInit.cpp
6190–6191 ↗(On Diff #58676)

Please also sink the calls to mark the destructor referenced and check its access into here too. We should keep the checks for a usable destructor and the triggering of an ExprWithCleanups for the destructor together.

As discussed, MaybeBindToTemporary more or less overlaps with this in the access checking perspective. Added a TODO for a potential merge of MaterializeTemporaryExpr and BindToCXXTemporary in the future.

I think this may set ExprNeedsCleanups even when unnecessary, if the MTE is lifetime-extended (I think you only actually want an ExprWithCleanups if the storage duration is SD_Automatic). We can't really deal with that here, because we don't know the storage duration of the MTE yet, but please add a FIXME here to not set ExprNeedsCleanups if the temporary is lifetime-extended.

Due to the use of pushCleanupAfterFullExpr in CodeGen::EmitMaterializeTemporaryExpr, there has to have a RunCleanupsScope at FullExpr level to delay and forward the cleanups to its upper level. So even for lifetime-extended variables, the cleanup scope is necessary.

rsmith added inline comments.May 26 2016, 1:36 PM
lib/Sema/SemaInit.cpp
6197 ↗(On Diff #58676)

Why is this C++-only? We presumably would want to clean up after materialized temporaries in other languages if they ever get created.

6461 ↗(On Diff #58676)

Accidentally-deleted?

timshen updated this revision to Diff 58694.May 26 2016, 1:57 PM
timshen marked 2 inline comments as done.

Removed C++ constrain and added back the missing comment line.

timshen marked an inline comment as done.Jun 9 2016, 9:53 AM

Ping? :)

rsmith accepted this revision.Jun 9 2016, 12:51 PM
rsmith edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 9 2016, 12:51 PM
This revision was automatically updated to reflect the committed changes.
timshen reopened this revision.Jun 10 2016, 1:56 PM

Clang-tidy is broken by this change. Dependency is added to track the fix.

This revision is now accepted and ready to land.Jun 10 2016, 1:56 PM

D21243 is committed. Let's do this again.

Committed as r273312.

timshen closed this revision.Jun 21 2016, 1:39 PM