[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 13:16:45 PDT 2018


ahatanak created this revision.
ahatanak added reviewers: rjmccall, doug.gregor, rsmith.

r326307 and r327870 made changes that enable __strong and __weak fields to be declared in C structs. This patch changes the ObjC++ ABI so that structs with __strong or __weak pointers can be passed to or returned from functions compiled in C mode.

ObjC and ObjC++ are currently incompatible because of the differences in the way structs are passed and destructed.

For example:

  typedef struct {
    id f0;
    __weak id f1;
  } S;
  
  // this code is compiled in c++.
  extern ā€œCā€ {
    void foo(S s);
  }
  
  void caller(S a) {
    foo(a); // clang currently passes 'a' indirectly and the caller destructs 'a'.
  }
  
  // this function is compiled in c.
  void foo(S a) {  // 'a' is passed directly and is destructed in the callee.
  }

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 make 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


Repository:
  rC Clang

https://reviews.llvm.org/D44908

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  test/CodeGenObjCXX/arc-special-member-functions.mm
  test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  test/CodeGenObjCXX/property-dot-copy-elision.mm
  test/CodeGenObjCXX/trivial_abi.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44908.139836.patch
Type: text/x-patch
Size: 20281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180326/303dece6/attachment-0001.bin>


More information about the cfe-commits mailing list