aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorAkira Hatanaka <ahatanaka@apple.com>2018-03-28 21:13:14 +0000
committerAkira Hatanaka <ahatanaka@apple.com>2018-03-28 21:13:14 +0000
commitc4bfd75d786a2a77c779cee6976534f37202ac21 (patch)
tree7d3c598ba8143ab5196aed15a7573593c53dabe5 /lib/AST/ASTContext.cpp
parent1ec33d54dfc07388c7bc7d637723ceeaa74869ee (diff)
[ObjC++] Make parameter passing and function return compatible with ObjC
ObjC and ObjC++ pass non-trivial structs in a way that is incompatible with each other. For example: typedef struct { id f0; __weak id f1; } S; // this code is compiled in c++. extern "C" { void foo(S s); } void caller() { // the caller passes the parameter indirectly and destructs it. foo(S()); } // this function is compiled in c. // 'a' is passed directly and is destructed in the callee. void foo(S a) { } This patch fixes the incompatibility by passing and returning structs with __strong or weak fields using the C ABI in C++ mode. __strong and __weak fields in a struct do not cause the struct to be destructed in the caller and __strong fields do not cause the struct to be passed indirectly. Also, this patch fixes the microsoft ABI bug mentioned here: https://reviews.llvm.org/D41039?id=128767#inline-364710 rdar://problem/38887866 Differential Revision: https://reviews.llvm.org/D44908 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328731 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r--lib/AST/ASTContext.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 77c06f21df..ea96a07763 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2643,9 +2643,11 @@ void ASTContext::adjustExceptionSpec(
}
bool ASTContext::isParamDestroyedInCallee(QualType T) const {
- return getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee() ||
- T.hasTrivialABIOverride() ||
- T.isDestructedType() == QualType::DK_nontrivial_c_struct;
+ if (getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+ return true;
+ if (const auto *RT = T->getBaseElementTypeUnsafe()->getAs<RecordType>())
+ return RT->getDecl()->isParamDestroyedInCallee();
+ return false;
}
/// getComplexType - Return the uniqued reference to the type for a complex