[ObjC++] Make parameter passing and function return compatible with ObjC
authorAkira Hatanaka <ahatanaka@apple.com>
Wed, 28 Mar 2018 21:13:14 +0000 (21:13 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Wed, 28 Mar 2018 21:13:14 +0000 (21:13 +0000)
commitfcbe17c6be86c87031822c1c01d8b43b6d142695
tree701edbfeeae78c64ed7133dead94509fd4abcc04
parentaac23d78814d45039c0a8b3dbf204d5664df854c
[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

llvm-svn: 328731
27 files changed:
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Frontend/CodeGenOptions.def
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/Type.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
clang/test/CodeGenObjCXX/arc-special-member-functions.mm
clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm [moved from clang/test/CodeGenObjCXX/trivial_abi.mm with 73% similarity]
clang/test/CodeGenObjCXX/property-dot-copy-elision.mm