<div dir="ltr">Hi, I'm working on bug 27451 (<a href="https://llvm.org/bugs/show_bug.cgi?id=27451">https://llvm.org/bugs/show_bug.cgi?id=27451</a>).<div><div><br></div><div><div>If the lifetime-extended temporary object is not trivially destructible, there will be a ExprWithCleanups generated for the VarDecl, so calling <span style="line-height:1.5">CodeGenFunction::</span><span style="line-height:1.5">pushCleanupAfterFullExpr to push a llvm.lifetime.end() call as a cleanup (as clang currently does in non-temporary cases) just works.</span></div><div><br></div></div><div><span style="line-height:1.5">However, I learned that ExprWithCleanups will not be generated by </span><span class="s1" style="line-height:1.5">Sema</span><span class="s2" style="line-height:1.5">::MaybeBindToTemp</span><span class="s1" style="line-height:1.5">orary, if the destructor is trivial, according to </span><span style="line-height:1.5"><</span><a href="https://github.com/llvm-mirror/clang/blob/4a65931dcba82b23856d654eb77d133d0a3c59f2/lib/Sema/SemaExprCXX.cpp#L5593" style="line-height:1.5">https://github.com/llvm-mirror/clang/blob/4a65931dcba82b23856d654eb77d133d0a3c59f2/lib/Sema/SemaExprCXX.cpp#L5593</a><span style="line-height:1.5">>; and pushCleanupAfterFullExpr seems not working well without a ExprWithCleanups, due to the absence of </span><span style="line-height:1.5">RunCleanupsScope <</span><a href="https://github.com/llvm-mirror/clang/blob/717e5e20622b0f4ac3c16bb643ed6a36eef29603/lib/CodeGen/CGExpr.cpp#L1002">https://github.com/llvm-mirror/clang/blob/717e5e20622b0f4ac3c16bb643ed6a36eef29603/lib/CodeGen/CGExpr.cpp#L1002</a>><span style="line-height:1.5">.</span></div>







</div><div><div><br></div><div><span style="line-height:1.5">If there is a ExprWithCleanups generated even for a trivially destructible temporary, generating llvm.lifetime.end() is easy by calling CodeGenFunction::pushCleanupAfterFullExpr.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">This requires moving L5593 to L5550 in SemaExprCXX.cpp. </span><span style="line-height:1.5">The two-lines change breaks 36 tests, most of which are checking for warnings, so I suppose I also need to fix some warning detections.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Is this - by adding more ExprWithCleanups and fix tests -</span><span style="line-height:1.5"> </span><span style="line-height:1.5">the correct way</span><span style="line-height:1.5"> to fix the temporary lifetime bug? I feel weird about the existence of ExprWithCleanups in the first place, but that's off the topic.</span></div></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Just for illustration, the attached patch fixes the bug, but doesn't fix the tests though.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Thanks!</span></div></div>