[CodeGen] Avoid destructing a callee-destructued struct type in a
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 27 Apr 2018 06:57:00 +0000 (06:57 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 27 Apr 2018 06:57:00 +0000 (06:57 +0000)
commitccda3d297023091f6468ad195c68b250c474a45a
treee8552b0b8d4d92f599ebb46243f5b7e2b5cde863
parentb4f3637cec2f4b914528bc6b27d00b8317f7a995
[CodeGen] Avoid destructing a callee-destructued struct type in a
function if a function delegates to another function.

Fix a bug introduced in r328731, which caused a struct with ObjC __weak
fields that was passed to a function to be destructed twice, once in the
callee function and once in another function the callee function
delegates to. To prevent this, keep track of the callee-destructed
structs passed to a function and disable their cleanups at the point of
the call to the delegated function.

This reapplies r331016, which was reverted in r331019 because it caused
an assertion to fail in EmitDelegateCallArg on a windows bot. I made
changes to EmitDelegateCallArg so that it doesn't try to deactivate
cleanups for structs that have trivial destructors (cleanups for those
structs are never pushed to the cleanup stack in EmitParmDecl).

rdar://problem/39194693

Differential Revision: https://reviews.llvm.org/D45382

llvm-svn: 331020
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGCleanup.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/CodeGenCXX/lambda-to-function-pointer-conversion.cpp [new file with mode: 0644]
clang/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
clang/test/CodeGenObjCXX/arc-special-member-functions.mm
clang/test/CodeGenObjCXX/lambda-expressions.mm