summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2018-04-27 04:21:51 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2018-04-27 04:21:51 +0000
commite712374496147f61ff701ee46bdd9932366521c6 (patch)
treead3b905195500be4f8400e38a45b6977533793aa /clang/lib/CodeGen/CGCall.cpp
parentfa7fd13cf8b33f879c2f3b80dc7e91ac0cace0bd (diff)
downloadbcm5719-llvm-e712374496147f61ff701ee46bdd9932366521c6.tar.gz
bcm5719-llvm-e712374496147f61ff701ee46bdd9932366521c6.zip
[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. rdar://problem/39194693 Differential Revision: https://reviews.llvm.org/D45382 llvm-svn: 331016
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 392c7b1ded5..d4374ff6e09 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3063,6 +3063,22 @@ void CodeGenFunction::EmitDelegateCallArg(CallArgList &args,
} else {
args.add(convertTempToRValue(local, type, loc), type);
}
+
+ // Deactivate the cleanup for the callee-destructed param that was pushed.
+ if (hasAggregateEvaluationKind(type) &&
+ getContext().isParamDestroyedInCallee(type)) {
+ EHScopeStack::stable_iterator cleanup =
+ CalleeDestructedParamCleanups.lookup(cast<ParmVarDecl>(param));
+ if (cleanup.isValid()) {
+ // This unreachable is a temporary marker which will be removed later.
+ llvm::Instruction *isActive = Builder.CreateUnreachable();
+ args.addArgCleanupDeactivation(cleanup, isActive);
+ } else
+ // A param cleanup should have been pushed unless we are code-generating
+ // a thunk.
+ assert(CurFuncIsThunk &&
+ "cleanup for callee-destructed param not recorded");
+ }
}
static bool isProvablyNull(llvm::Value *addr) {
OpenPOWER on IntegriCloud