<div dir="ltr">The tests only failed with module enabled. FWIW, I think the change in ASTImporter (<a href="https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk">https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk</a>) needs additional changes to make imports work for RecordDecl. </div><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 12, 2018 at 3:56 PM Eric Liu <<a href="mailto:ioeric@google.com">ioeric@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Akira,<div><br></div><div>It seems that this commit also changes behavior for compiling C++ code as we are seeing test failures caused by this change in our internal tests.</div><div><br></div><div>I'm still trying to reduce a reproducer for the failure. In the meantime, could you please double check if this affects C++?</div><div><br></div><div>Thanks,</div><div>Eric</div></div><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr">On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ahatanak<br>
Date: Fri Mar  9 22:36:08 2018<br>
New Revision: 327206<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=327206&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=327206&view=rev</a><br>
Log:<br>
[ObjC] Allow declaring __weak pointer fields in C structs in ARC.<br>
<br>
This patch uses the infrastructure added in r326307 for enabling<br>
non-trivial fields to be declared in C structs to allow __weak fields in<br>
C structs in ARC.<br>
<br>
rdar://problem/33599681<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D44095" rel="noreferrer" target="_blank">https://reviews.llvm.org/D44095</a><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m<br>
Modified:<br>
    cfe/trunk/include/clang/AST/Decl.h<br>
    cfe/trunk/include/clang/AST/DeclCXX.h<br>
    cfe/trunk/include/clang/AST/Type.h<br>
    cfe/trunk/lib/AST/ASTImporter.cpp<br>
    cfe/trunk/lib/AST/Decl.cpp<br>
    cfe/trunk/lib/AST/DeclCXX.cpp<br>
    cfe/trunk/lib/AST/Type.cpp<br>
    cfe/trunk/lib/CodeGen/CGBlocks.cpp<br>
    cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp<br>
    cfe/trunk/lib/CodeGen/CGObjC.cpp<br>
    cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
    cfe/trunk/lib/CodeGen/TargetInfo.cpp<br>
    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>
    cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp<br>
    cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m<br>
<br>
Modified: cfe/trunk/include/clang/AST/Decl.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Decl.h (original)<br>
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018<br>
@@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {<br>
   bool NonTrivialToPrimitiveCopy : 1;<br>
   bool NonTrivialToPrimitiveDestroy : 1;<br>
<br>
+  /// True if this class can be passed in a non-address-preserving fashion<br>
+  /// (such as in registers).<br>
+  /// This does not imply anything about how the ABI in use will actually<br>
+  /// pass an object of this class.<br>
+  bool CanPassInRegisters : 1;<br>
+<br>
 protected:<br>
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,<br>
              SourceLocation StartLoc, SourceLocation IdLoc,<br>
@@ -3636,6 +3642,18 @@ public:<br>
     NonTrivialToPrimitiveDestroy = true;<br>
   }<br>
<br>
+  /// Determine whether this class can be passed in registers. In C++ mode,<br>
+  /// it must have at least one trivial, non-deleted copy or move constructor.<br>
+  /// FIXME: This should be set as part of completeDefinition.<br>
+  bool canPassInRegisters() const {<br>
+    return CanPassInRegisters;<br>
+  }<br>
+<br>
+  /// Set that we can pass this RecordDecl in registers.<br>
+  void setCanPassInRegisters(bool CanPass) {<br>
+    CanPassInRegisters = CanPass;<br>
+  }<br>
+<br>
   /// \brief Determines whether this declaration represents the<br>
   /// injected class name.<br>
   ///<br>
<br>
Modified: cfe/trunk/include/clang/AST/DeclCXX.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)<br>
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018<br>
@@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl<br>
     /// constructor.<br>
     unsigned HasDefaultedDefaultConstructor : 1;<br>
<br>
-    /// \brief True if this class can be passed in a non-address-preserving<br>
-    /// fashion (such as in registers) according to the C++ language rules.<br>
-    /// This does not imply anything about how the ABI in use will actually<br>
-    /// pass an object of this class.<br>
-    unsigned CanPassInRegisters : 1;<br>
-<br>
     /// \brief True if a defaulted default constructor for this class would<br>
     /// be constexpr.<br>
     unsigned DefaultedDefaultConstructorIsConstexpr : 1;<br>
@@ -1474,18 +1468,6 @@ public:<br>
     return data().HasIrrelevantDestructor;<br>
   }<br>
<br>
-  /// \brief Determine whether this class has at least one trivial, non-deleted<br>
-  /// copy or move constructor.<br>
-  bool canPassInRegisters() const {<br>
-    return data().CanPassInRegisters;<br>
-  }<br>
-<br>
-  /// \brief Set that we can pass this RecordDecl in registers.<br>
-  // FIXME: This should be set as part of completeDefinition.<br>
-  void setCanPassInRegisters(bool CanPass) {<br>
-    data().CanPassInRegisters = CanPass;<br>
-  }<br>
-<br>
   /// Determine whether the triviality for the purpose of calls for this class<br>
   /// is overridden to be trivial because this class or the type of one of its<br>
   /// subobjects has attribute "trivial_abi".<br>
<br>
Modified: cfe/trunk/include/clang/AST/Type.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Type.h (original)<br>
+++ cfe/trunk/include/clang/AST/Type.h Fri Mar  9 22:36:08 2018<br>
@@ -1097,6 +1097,10 @@ public:<br>
     /// with the ARC __strong qualifier.<br>
     PDIK_ARCStrong,<br>
<br>
+    /// The type is an Objective-C retainable pointer type that is qualified<br>
+    /// with the ARC __weak qualifier.<br>
+    PDIK_ARCWeak,<br>
+<br>
     /// The type is a struct containing a field whose type is not PCK_Trivial.<br>
     PDIK_Struct<br>
   };<br>
@@ -1124,6 +1128,10 @@ public:<br>
     /// with the ARC __strong qualifier.<br>
     PCK_ARCStrong,<br>
<br>
+    /// The type is an Objective-C retainable pointer type that is qualified<br>
+    /// with the ARC __weak qualifier.<br>
+    PCK_ARCWeak,<br>
+<br>
     /// The type is a struct containing a field whose type is neither<br>
     /// PCK_Trivial nor PCK_VolatileTrivial.<br>
     /// Note that a C++ struct type does not necessarily match this; C++ copying<br>
@@ -1146,6 +1154,8 @@ public:<br>
   /// source object is placed in an uninitialized state.<br>
   PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const;<br>
<br>
+  bool canPassInRegisters() const;<br>
+<br>
   enum DestructionKind {<br>
     DK_none,<br>
     DK_cxx_destructor,<br>
<br>
Modified: cfe/trunk/lib/AST/ASTImporter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)<br>
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Mar  9 22:36:08 2018<br>
@@ -1105,7 +1105,6 @@ bool ASTNodeImporter::ImportDefinition(R<br>
       = FromData.HasConstexprNonCopyMoveConstructor;<br>
     ToData.HasDefaultedDefaultConstructor<br>
       = FromData.HasDefaultedDefaultConstructor;<br>
-    ToData.CanPassInRegisters = FromData.CanPassInRegisters;<br>
     ToData.DefaultedDefaultConstructorIsConstexpr<br>
       = FromData.DefaultedDefaultConstructorIsConstexpr;<br>
     ToData.HasConstexprDefaultConstructor<br>
<br>
Modified: cfe/trunk/lib/AST/Decl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Decl.cpp (original)<br>
+++ cfe/trunk/lib/AST/Decl.cpp Fri Mar  9 22:36:08 2018<br>
@@ -3931,7 +3931,8 @@ RecordDecl::RecordDecl(Kind DK, TagKind<br>
       HasObjectMember(false), HasVolatileMember(false),<br>
       LoadedFieldsFromExternalStorage(false),<br>
       NonTrivialToPrimitiveDefaultInitialize(false),<br>
-      NonTrivialToPrimitiveCopy(false), NonTrivialToPrimitiveDestroy(false) {<br>
+      NonTrivialToPrimitiveCopy(false), NonTrivialToPrimitiveDestroy(false),<br>
+      CanPassInRegisters(true) {<br>
   assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/AST/DeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Mar  9 22:36:08 2018<br>
@@ -93,7 +93,6 @@ CXXRecordDecl::DefinitionData::Definitio<br>
       DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true),<br>
       HasConstexprNonCopyMoveConstructor(false),<br>
       HasDefaultedDefaultConstructor(false),<br>
-      CanPassInRegisters(true),<br>
       DefaultedDefaultConstructorIsConstexpr(true),<br>
       HasConstexprDefaultConstructor(false),<br>
       HasNonLiteralTypeFieldsOrBases(false), ComputedVisibleConversions(false),<br>
<br>
Modified: cfe/trunk/lib/AST/Type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Type.cpp (original)<br>
+++ cfe/trunk/lib/AST/Type.cpp Fri Mar  9 22:36:08 2018<br>
@@ -2214,11 +2214,14 @@ QualType::isNonTrivialToPrimitiveDefault<br>
     if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize())<br>
       return PDIK_Struct;<br>
<br>
-  Qualifiers::ObjCLifetime Lifetime = getQualifiers().getObjCLifetime();<br>
-  if (Lifetime == Qualifiers::OCL_Strong)<br>
+  switch (getQualifiers().getObjCLifetime()) {<br>
+  case Qualifiers::OCL_Strong:<br>
     return PDIK_ARCStrong;<br>
-<br>
-  return PDIK_Trivial;<br>
+  case Qualifiers::OCL_Weak:<br>
+    return PDIK_ARCWeak;<br>
+  default:<br>
+    return PDIK_Trivial;<br>
+  }<br>
 }<br>
<br>
 QualType::PrimitiveCopyKind QualType::isNonTrivialToPrimitiveCopy() const {<br>
@@ -2228,10 +2231,14 @@ QualType::PrimitiveCopyKind QualType::is<br>
       return PCK_Struct;<br>
<br>
   Qualifiers Qs = getQualifiers();<br>
-  if (Qs.getObjCLifetime() == Qualifiers::OCL_Strong)<br>
+  switch (Qs.getObjCLifetime()) {<br>
+  case Qualifiers::OCL_Strong:<br>
     return PCK_ARCStrong;<br>
-<br>
-  return Qs.hasVolatile() ? PCK_VolatileTrivial : PCK_Trivial;<br>
+  case Qualifiers::OCL_Weak:<br>
+    return PCK_ARCWeak;<br>
+  default:<br>
+    return Qs.hasVolatile() ? PCK_VolatileTrivial : PCK_Trivial;<br>
+  }<br>
 }<br>
<br>
 QualType::PrimitiveCopyKind<br>
@@ -2239,6 +2246,17 @@ QualType::isNonTrivialToPrimitiveDestruc<br>
   return isNonTrivialToPrimitiveCopy();<br>
 }<br>
<br>
+bool QualType::canPassInRegisters() const {<br>
+  if (const auto *RT =<br>
+          getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())<br>
+    return RT->getDecl()->canPassInRegisters();<br>
+<br>
+  if (getQualifiers().getObjCLifetime() == Qualifiers::OCL_Weak)<br>
+    return false;<br>
+<br>
+  return true;<br>
+}<br>
+<br>
 bool Type::isLiteralType(const ASTContext &Ctx) const {<br>
   if (isDependentType())<br>
     return false;<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Mar  9 22:36:08 2018<br>
@@ -1525,6 +1525,9 @@ computeCopyInfoForBlockCapture(const Blo<br>
   case QualType::PCK_Struct:<br>
     return std::make_pair(BlockCaptureEntityKind::NonTrivialCStruct,<br>
                           BlockFieldFlags());<br>
+  case QualType::PCK_ARCWeak:<br>
+    // We need to register __weak direct captures with the runtime.<br>
+    return std::make_pair(BlockCaptureEntityKind::ARCWeak, Flags);<br>
   case QualType::PCK_ARCStrong:<br>
     // We need to retain the copied value for __strong direct captures.<br>
     // If it's a block pointer, we have to copy the block and assign that to<br>
@@ -1542,10 +1545,6 @@ computeCopyInfoForBlockCapture(const Blo<br>
     // Special rules for ARC captures:<br>
     Qualifiers QS = T.getQualifiers();<br>
<br>
-    // We need to register __weak direct captures with the runtime.<br>
-    if (QS.getObjCLifetime() == Qualifiers::OCL_Weak)<br>
-      return std::make_pair(BlockCaptureEntityKind::ARCWeak, Flags);<br>
-<br>
     // Non-ARC captures of retainable pointers are strong and<br>
     // therefore require a call to _Block_object_assign.<br>
     if (!QS.getObjCLifetime() && !LangOpts.ObjCAutoRefCount)<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Fri Mar  9 22:36:08 2018<br>
@@ -77,6 +77,8 @@ struct DefaultInitializedTypeVisitor {<br>
     switch (PDIK) {<br>
     case QualType::PDIK_ARCStrong:<br>
       return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);<br>
+    case QualType::PDIK_ARCWeak:<br>
+      return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);<br>
     case QualType::PDIK_Struct:<br>
       return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);<br>
     case QualType::PDIK_Trivial:<br>
@@ -108,6 +110,8 @@ struct CopiedTypeVisitor {<br>
     switch (PCK) {<br>
     case QualType::PCK_ARCStrong:<br>
       return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);<br>
+    case QualType::PCK_ARCWeak:<br>
+      return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);<br>
     case QualType::PCK_Struct:<br>
       return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);<br>
     case QualType::PCK_Trivial:<br>
@@ -141,11 +145,6 @@ template <class Derived> struct StructVi<br>
<br>
   template <class... Ts> void visitTrivial(Ts... Args) {}<br>
<br>
-  template <class... Ts> void visitARCWeak(Ts... Args) {<br>
-    // FIXME: remove this when visitARCWeak is implemented in the subclasses.<br>
-    llvm_unreachable("weak field is not expected");<br>
-  }<br>
-<br>
   template <class... Ts> void visitCXXDestructor(Ts... Args) {<br>
     llvm_unreachable("field of a C++ struct type is not expected");<br>
   }<br>
@@ -245,6 +244,13 @@ template <class Derived> struct GenFuncN<br>
     appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));<br>
   }<br>
<br>
+  void visitARCWeak(QualType FT, const FieldDecl *FD,<br>
+                    CharUnits CurStructOffset) {<br>
+    appendStr("_w");<br>
+    CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);<br>
+    appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));<br>
+  }<br>
+<br>
   void visitStruct(QualType QT, const FieldDecl *FD,<br>
                    CharUnits CurStructOffset) {<br>
     CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);<br>
@@ -615,6 +621,12 @@ struct GenDestructor : StructVisitor<Gen<br>
         *CGF, getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);<br>
   }<br>
<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 1> Addrs) {<br>
+    CGF->destroyARCWeak(<br>
+        *CGF, getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);<br>
+  }<br>
+<br>
   void callSpecialFunction(QualType FT, CharUnits Offset,<br>
                            std::array<Address, 1> Addrs) {<br>
     CGF->callCStructDestructor(<br>
@@ -636,6 +648,12 @@ struct GenDefaultInitialize<br>
         getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);<br>
   }<br>
<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 1> Addrs) {<br>
+    CGF->EmitNullInitialization(<br>
+        getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);<br>
+  }<br>
+<br>
   template <class FieldKind, size_t... Is><br>
   void visitArray(FieldKind FK, QualType QT, const FieldDecl *FD,<br>
                   CharUnits CurStackOffset, std::array<Address, 1> Addrs) {<br>
@@ -678,6 +696,14 @@ struct GenCopyConstructor : GenBinaryFun<br>
     llvm::Value *Val = CGF->EmitARCRetain(QT, SrcVal);<br>
     CGF->EmitStoreOfScalar(Val, CGF->MakeAddrLValue(Addrs[DstIdx], QT), true);<br>
   }<br>
+<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 2> Addrs) {<br>
+    Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);<br>
+    Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);<br>
+    CGF->EmitARCCopyWeak(Addrs[DstIdx], Addrs[SrcIdx]);<br>
+  }<br>
+<br>
   void callSpecialFunction(QualType FT, CharUnits Offset,<br>
                            std::array<Address, 2> Addrs) {<br>
     CGF->callCStructCopyConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),<br>
@@ -700,6 +726,14 @@ struct GenMoveConstructor : GenBinaryFun<br>
     CGF->EmitStoreOfScalar(SrcVal, CGF->MakeAddrLValue(Addrs[DstIdx], QT),<br>
                            /* isInitialization */ true);<br>
   }<br>
+<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 2> Addrs) {<br>
+    Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);<br>
+    Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);<br>
+    CGF->EmitARCMoveWeak(Addrs[DstIdx], Addrs[SrcIdx]);<br>
+  }<br>
+<br>
   void callSpecialFunction(QualType FT, CharUnits Offset,<br>
                            std::array<Address, 2> Addrs) {<br>
     CGF->callCStructMoveConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),<br>
@@ -720,6 +754,14 @@ struct GenCopyAssignment : GenBinaryFunc<br>
     CGF->EmitARCStoreStrong(CGF->MakeAddrLValue(Addrs[DstIdx], QT), SrcVal,<br>
                             false);<br>
   }<br>
+<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 2> Addrs) {<br>
+    Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);<br>
+    Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);<br>
+    CGF->emitARCCopyAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);<br>
+  }<br>
+<br>
   void callSpecialFunction(QualType FT, CharUnits Offset,<br>
                            std::array<Address, 2> Addrs) {<br>
     CGF->callCStructCopyAssignmentOperator(<br>
@@ -747,6 +789,13 @@ struct GenMoveAssignment : GenBinaryFunc<br>
     CGF->EmitARCRelease(DstVal, ARCImpreciseLifetime);<br>
   }<br>
<br>
+  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,<br>
+                    std::array<Address, 2> Addrs) {<br>
+    Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);<br>
+    Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);<br>
+    CGF->emitARCMoveAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);<br>
+  }<br>
+<br>
   void callSpecialFunction(QualType FT, CharUnits Offset,<br>
                            std::array<Address, 2> Addrs) {<br>
     CGF->callCStructMoveAssignmentOperator(<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Mar  9 22:36:08 2018<br>
@@ -2307,6 +2307,21 @@ void CodeGenFunction::EmitARCCopyWeak(Ad<br>
                        "objc_copyWeak");<br>
 }<br>
<br>
+void CodeGenFunction::emitARCCopyAssignWeak(QualType Ty, Address DstAddr,<br>
+                                            Address SrcAddr) {<br>
+  llvm::Value *Object = EmitARCLoadWeakRetained(SrcAddr);<br>
+  Object = EmitObjCConsumeObject(Ty, Object);<br>
+  EmitARCStoreWeak(DstAddr, Object, false);<br>
+}<br>
+<br>
+void CodeGenFunction::emitARCMoveAssignWeak(QualType Ty, Address DstAddr,<br>
+                                            Address SrcAddr) {<br>
+  llvm::Value *Object = EmitARCLoadWeakRetained(SrcAddr);<br>
+  Object = EmitObjCConsumeObject(Ty, Object);<br>
+  EmitARCStoreWeak(DstAddr, Object, false);<br>
+  EmitARCDestroyWeak(SrcAddr);<br>
+}<br>
+<br>
 /// Produce the code to do a objc_autoreleasepool_push.<br>
 ///   call i8* \@objc_autoreleasePoolPush(void)<br>
 llvm::Value *CodeGenFunction::EmitObjCAutoreleasePoolPush() {<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Mar  9 22:36:08 2018<br>
@@ -3548,6 +3548,8 @@ public:<br>
   llvm::Value *EmitARCLoadWeak(Address addr);<br>
   llvm::Value *EmitARCLoadWeakRetained(Address addr);<br>
   llvm::Value *EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored);<br>
+  void emitARCCopyAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);<br>
+  void emitARCMoveAssignWeak(QualType Ty, Address DstAddr, Address SrcAddr);<br>
   void EmitARCCopyWeak(Address dst, Address src);<br>
   void EmitARCMoveWeak(Address dst, Address src);<br>
   llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value);<br>
<br>
Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Fri Mar  9 22:36:08 2018<br>
@@ -140,8 +140,11 @@ bool SwiftABIInfo::isLegalVectorTypeForS<br>
 static CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT,<br>
                                               CGCXXABI &CXXABI) {<br>
   const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());<br>
-  if (!RD)<br>
+  if (!RD) {<br>
+    if (!RT->getDecl()->canPassInRegisters())<br>
+      return CGCXXABI::RAA_Indirect;<br>
     return CGCXXABI::RAA_Default;<br>
+  }<br>
   return CXXABI.getRecordArgABI(RD);<br>
 }<br>
<br>
@@ -153,6 +156,20 @@ static CGCXXABI::RecordArgABI getRecordA<br>
   return getRecordArgABI(RT, CXXABI);<br>
 }<br>
<br>
+static bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI,<br>
+                               const ABIInfo &Info) {<br>
+  QualType Ty = FI.getReturnType();<br>
+<br>
+  if (const auto *RT = Ty->getAs<RecordType>())<br>
+    if (!isa<CXXRecordDecl>(RT->getDecl()) &&<br>
+        !RT->getDecl()->canPassInRegisters()) {<br>
+      FI.getReturnInfo() = Info.getNaturalAlignIndirect(Ty);<br>
+      return true;<br>
+    }<br>
+<br>
+  return CXXABI.classifyReturnType(FI);<br>
+}<br>
+<br>
 /// Pass transparent unions as if they were the type of the first element. Sema<br>
 /// should ensure that all elements of the union have the same "machine type".<br>
 static QualType useFirstFieldIfTransparentUnion(QualType Ty) {<br>
@@ -1749,7 +1766,7 @@ void X86_32ABIInfo::computeInfo(CGFuncti<br>
   } else<br>
     State.FreeRegs = DefaultNumRegisterParameters;<br>
<br>
-  if (!getCXXABI().classifyReturnType(FI)) {<br>
+  if (!::classifyReturnType(getCXXABI(), FI, *this)) {<br>
     FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), State);<br>
   } else if (FI.getReturnInfo().isIndirect()) {<br>
     // The C++ ABI is not aware of register usage, so we have to check if the<br>
@@ -3545,7 +3562,7 @@ void X86_64ABIInfo::computeInfo(CGFuncti<br>
   unsigned FreeSSERegs = IsRegCall ? 16 : 8;<br>
   unsigned NeededInt, NeededSSE;<br>
<br>
-  if (!getCXXABI().classifyReturnType(FI)) {<br>
+  if (!::classifyReturnType(getCXXABI(), FI, *this)) {<br>
     if (IsRegCall && FI.getReturnType()->getTypePtr()->isRecordType() &&<br>
         !FI.getReturnType()->getTypePtr()->isUnionType()) {<br>
       FI.getReturnInfo() =<br>
@@ -4895,7 +4912,7 @@ private:<br>
   bool isIllegalVectorType(QualType Ty) const;<br>
<br>
   void computeInfo(CGFunctionInfo &FI) const override {<br>
-    if (!getCXXABI().classifyReturnType(FI))<br>
+    if (!::classifyReturnType(getCXXABI(), FI, *this))<br>
       FI.getReturnInfo() = classifyReturnType(FI.getReturnType());<br>
<br>
     for (auto &it : FI.arguments())<br>
@@ -5626,7 +5643,7 @@ void WindowsARMTargetCodeGenInfo::setTar<br>
 }<br>
<br>
 void ARMABIInfo::computeInfo(CGFunctionInfo &FI) const {<br>
-  if (!getCXXABI().classifyReturnType(FI))<br>
+  if (!::classifyReturnType(getCXXABI(), FI, *this))<br>
     FI.getReturnInfo() =<br>
         classifyReturnType(FI.getReturnType(), FI.isVariadic());<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar  9 22:36:08 2018<br>
@@ -15260,7 +15260,6 @@ void Sema::ActOnFields(Scope *S, SourceL<br>
<br>
     // Get the type for the field.<br>
     const Type *FDTy = FD->getType().getTypePtr();<br>
-    Qualifiers QS = FD->getType().getQualifiers();<br>
<br>
     if (!FD->isAnonymousStructOrUnion()) {<br>
       // Remember all fields written by the user.<br>
@@ -15401,10 +15400,7 @@ void Sema::ActOnFields(Scope *S, SourceL<br>
       QualType T = Context.getObjCObjectPointerType(FD->getType());<br>
       FD->setType(T);<br>
     } else if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&<br>
-               Record && !ObjCFieldLifetimeErrReported &&<br>
-               ((!getLangOpts().CPlusPlus &&<br>
-                 QS.getObjCLifetime() == Qualifiers::OCL_Weak) ||<br>
-                Record->isUnion())) {<br>
+               Record && !ObjCFieldLifetimeErrReported && Record->isUnion()) {<br>
       // It's an error in ARC or Weak if a field has lifetime.<br>
       // We don't want to report this in a system header, though,<br>
       // so we just make the field unavailable.<br>
@@ -15450,6 +15446,8 @@ void Sema::ActOnFields(Scope *S, SourceL<br>
         Record->setNonTrivialToPrimitiveCopy();<br>
       if (FT.isDestructedType())<br>
         Record->setNonTrivialToPrimitiveDestroy();<br>
+      if (!FT.canPassInRegisters())<br>
+        Record->setCanPassInRegisters(false);<br>
     }<br>
<br>
     if (Record && FD->getType().isVolatileQualified())<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Mar  9 22:36:08 2018<br>
@@ -739,6 +739,7 @@ ASTDeclReader::VisitRecordDeclImpl(Recor<br>
   RD->setAnonymousStructOrUnion(Record.readInt());<br>
   RD->setHasObjectMember(Record.readInt());<br>
   RD->setHasVolatileMember(Record.readInt());<br>
+  RD->setCanPassInRegisters(Record.readInt());<br>
   return Redecl;<br>
 }<br>
<br>
@@ -1584,7 +1585,6 @@ void ASTDeclReader::ReadCXXDefinitionDat<br>
   Data.HasIrrelevantDestructor = Record.readInt();<br>
   Data.HasConstexprNonCopyMoveConstructor = Record.readInt();<br>
   Data.HasDefaultedDefaultConstructor = Record.readInt();<br>
-  Data.CanPassInRegisters = Record.readInt();<br>
   Data.DefaultedDefaultConstructorIsConstexpr = Record.readInt();<br>
   Data.HasConstexprDefaultConstructor = Record.readInt();<br>
   Data.HasNonLiteralTypeFieldsOrBases = Record.readInt();<br>
@@ -1724,7 +1724,6 @@ void ASTDeclReader::MergeDefinitionData(<br>
   MATCH_FIELD(HasIrrelevantDestructor)<br>
   OR_FIELD(HasConstexprNonCopyMoveConstructor)<br>
   OR_FIELD(HasDefaultedDefaultConstructor)<br>
-  MATCH_FIELD(CanPassInRegisters)<br>
   MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr)<br>
   OR_FIELD(HasConstexprDefaultConstructor)<br>
   MATCH_FIELD(HasNonLiteralTypeFieldsOrBases)<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Mar  9 22:36:08 2018<br>
@@ -6018,7 +6018,6 @@ void ASTRecordWriter::AddCXXDefinitionDa<br>
   Record->push_back(Data.HasIrrelevantDestructor);<br>
   Record->push_back(Data.HasConstexprNonCopyMoveConstructor);<br>
   Record->push_back(Data.HasDefaultedDefaultConstructor);<br>
-  Record->push_back(Data.CanPassInRegisters);<br>
   Record->push_back(Data.DefaultedDefaultConstructorIsConstexpr);<br>
   Record->push_back(Data.HasConstexprDefaultConstructor);<br>
   Record->push_back(Data.HasNonLiteralTypeFieldsOrBases);<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Fri Mar  9 22:36:08 2018<br>
@@ -465,6 +465,7 @@ void ASTDeclWriter::VisitRecordDecl(Reco<br>
   Record.push_back(D->isAnonymousStructOrUnion());<br>
   Record.push_back(D->hasObjectMember());<br>
   Record.push_back(D->hasVolatileMember());<br>
+  Record.push_back(D->canPassInRegisters());<br>
<br>
   if (D->getDeclContext() == D->getLexicalDeclContext() &&<br>
       !D->hasAttrs() &&<br>
@@ -1899,6 +1900,7 @@ void ASTWriter::WriteDeclAbbrevs() {<br>
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion<br>
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember<br>
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember<br>
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // canPassInRegisters<br>
   // DC<br>
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LexicalOffset<br>
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // VisibleOffset<br>
<br>
Modified: cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m?rev=327206&r1=327205&r2=327206&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m?rev=327206&r1=327205&r2=327206&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m (original)<br>
+++ cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m Fri Mar  9 22:36:08 2018<br>
@@ -1,12 +1,18 @@<br>
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -fobjc-exceptions -fexceptions -fobjc-arc-exceptions -emit-llvm -o - %s | FileCheck %s<br>
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -fobjc-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s<br>
<br>
 // CHECK: %[[STRUCT_STRONG:.*]] = type { i32, i8* }<br>
+// CHECK: %[[STRUCT_WEAK:.*]] = type { i32, i8* }<br>
<br>
 typedef struct {<br>
   int i;<br>
   id f1;<br>
 } Strong;<br>
<br>
+typedef struct {<br>
+  int i;<br>
+  __weak id f1;<br>
+} Weak;<br>
+<br>
 // CHECK: define void @testStrongException()<br>
 // CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_STRONG]], align 8<br>
 // CHECK: %[[AGG_TMP1:.*]] = alloca %[[STRUCT_STRONG]], align 8<br>
@@ -31,3 +37,26 @@ void calleeStrong(Strong, Strong);<br>
 void testStrongException(void) {<br>
   calleeStrong(genStrong(), genStrong());<br>
 }<br>
+<br>
+// CHECK: define void @testWeakException()<br>
+// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_WEAK]], align 8<br>
+// CHECK: %[[AGG_TMP1:.*]] = alloca %[[STRUCT_WEAK]], align 8<br>
+// CHECK: call void @genWeak(%[[STRUCT_WEAK]]* sret %[[AGG_TMP]])<br>
+// CHECK: invoke void @genWeak(%[[STRUCT_WEAK]]* sret %[[AGG_TMP1]])<br>
+<br>
+// CHECK: call void @calleeWeak(%[[STRUCT_WEAK]]* %[[AGG_TMP]], %[[STRUCT_WEAK]]* %[[AGG_TMP1]])<br>
+// CHECK: ret void<br>
+<br>
+// CHECK: landingpad { i8*, i32 }<br>
+// CHECK: %[[V3:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_TMP]] to i8**<br>
+// CHECK: call void @__destructor_8_w8(i8** %[[V3]])<br>
+// CHECK: br label<br>
+<br>
+// CHECK: resume<br>
+<br>
+Weak genWeak(void);<br>
+void calleeWeak(Weak, Weak);<br>
+<br>
+void testWeakException(void) {<br>
+  calleeWeak(genWeak(), genWeak());<br>
+}<br>
<br>
Added: cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m?rev=327206&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m?rev=327206&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m (added)<br>
+++ cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m Fri Mar  9 22:36:08 2018<br>
@@ -0,0 +1,193 @@<br>
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - %s | FileCheck -check-prefix=ARM64 -check-prefix=COMMON %s<br>
+// RUN: %clang_cc1 -triple thumbv7-apple-ios10 -fobjc-arc -fblocks -fobjc-runtime=ios-10.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s<br>
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13 -fobjc-arc -fblocks -fobjc-runtime=macosx-10.13.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s<br>
+// RUN: %clang_cc1 -triple i386-apple-macosx10.13.0 -fobjc-arc -fblocks -fobjc-runtime=macosx-fragile-10.13.0 -emit-llvm -o - %s | FileCheck -check-prefix=COMMON %s<br>
+<br>
+typedef void (^BlockTy)(void);<br>
+<br>
+// COMMON: %[[STRUCT_WEAK:.*]] = type { i32, i8* }<br>
+<br>
+typedef struct {<br>
+  int f0;<br>
+  __weak id f1;<br>
+} Weak;<br>
+<br>
+Weak getWeak(void);<br>
+void calleeWeak(Weak);<br>
+<br>
+// ARM64: define void @test_constructor_destructor_Weak()<br>
+// ARM64: %[[T:.*]] = alloca %[[STRUCT_WEAK]], align 8<br>
+// ARM64: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[T]] to i8**<br>
+// ARM64: call void @__default_constructor_8_w8(i8** %[[V0]])<br>
+// ARM64: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[T]] to i8**<br>
+// ARM64: call void @__destructor_8_w8(i8** %[[V1]])<br>
+// ARM64: ret void<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__default_constructor_8_w8(i8** %[[DST:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8<br>
+// ARM64: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**<br>
+// ARM64: %[[V4:.*]] = bitcast i8** %[[V3]] to i8*<br>
+// ARM64: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V4]], i8 0, i64 8, i1 false)<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__destructor_8_w8(i8** %[[DST:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V2:.*]] = getelementptr inbounds i8, i8* %[[V1]], i64 8<br>
+// ARM64: %[[V3:.*]] = bitcast i8* %[[V2]] to i8**<br>
+// ARM64: call void @objc_destroyWeak(i8** %[[V3]])<br>
+<br>
+void test_constructor_destructor_Weak(void) {<br>
+  Weak t;<br>
+}<br>
+<br>
+// ARM64: define void @test_copy_constructor_Weak(%[[STRUCT_WEAK]]* %{{.*}})<br>
+// ARM64: call void @__copy_constructor_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}})<br>
+// ARM64: call void @__destructor_8_w8(i8** %{{.*}})<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__copy_constructor_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32*<br>
+// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32*<br>
+// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8<br>
+// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8<br>
+// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8<br>
+// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**<br>
+// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8*<br>
+// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8<br>
+// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8**<br>
+// ARM64: call void @objc_copyWeak(i8** %[[V7]], i8** %[[V10]])<br>
+<br>
+void test_copy_constructor_Weak(Weak *s) {<br>
+  Weak t = *s;<br>
+}<br>
+<br>
+// ARM64: define void @test_copy_assignment_Weak(%[[STRUCT_WEAK]]* %{{.*}}, %[[STRUCT_WEAK]]* %{{.*}})<br>
+// ARM64: call void @__copy_assignment_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}})<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__copy_assignment_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32*<br>
+// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32*<br>
+// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8<br>
+// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8<br>
+// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8<br>
+// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**<br>
+// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8*<br>
+// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8<br>
+// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8**<br>
+// ARM64: %[[V11:.*]] = call i8* @objc_loadWeakRetained(i8** %[[V10]])<br>
+// ARM64: %[[V12:.*]] = call i8* @objc_storeWeak(i8** %[[V7]], i8* %[[V11]])<br>
+// ARM64: call void @objc_release(i8* %[[V11]])<br>
+<br>
+void test_copy_assignment_Weak(Weak *d, Weak *s) {<br>
+  *d = *s;<br>
+}<br>
+<br>
+// ARM64: define internal void @__Block_byref_object_copy_(i8*, i8*)<br>
+// ARM64: call void @__move_constructor_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}})<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__move_constructor_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32*<br>
+// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32*<br>
+// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8<br>
+// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8<br>
+// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8<br>
+// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**<br>
+// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8*<br>
+// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8<br>
+// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8**<br>
+// ARM64: call void @objc_moveWeak(i8** %[[V7]], i8** %[[V10]])<br>
+<br>
+void test_move_constructor_Weak(void) {<br>
+  __block Weak t;<br>
+  BlockTy b = ^{ (void)t; };<br>
+}<br>
+<br>
+// ARM64: define void @test_move_assignment_Weak(%[[STRUCT_WEAK]]* %{{.*}})<br>
+// ARM64: call void @__move_assignment_8_8_t0w4_w8(i8** %{{.*}}, i8** %{{.*}})<br>
+<br>
+// ARM64: define linkonce_odr hidden void @__move_assignment_8_8_t0w4_w8(i8** %[[DST:.*]], i8** %[[SRC:.*]])<br>
+// ARM64: %[[DST_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: %[[SRC_ADDR:.*]] = alloca i8**, align 8<br>
+// ARM64: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8<br>
+// ARM64: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8<br>
+// ARM64: %[[V2:.*]] = bitcast i8** %[[V0]] to i32*<br>
+// ARM64: %[[V3:.*]] = bitcast i8** %[[V1]] to i32*<br>
+// ARM64: %[[V4:.*]] = load i32, i32* %[[V3]], align 8<br>
+// ARM64: store i32 %[[V4]], i32* %[[V2]], align 8<br>
+// ARM64: %[[V5:.*]] = bitcast i8** %[[V0]] to i8*<br>
+// ARM64: %[[V6:.*]] = getelementptr inbounds i8, i8* %[[V5]], i64 8<br>
+// ARM64: %[[V7:.*]] = bitcast i8* %[[V6]] to i8**<br>
+// ARM64: %[[V8:.*]] = bitcast i8** %[[V1]] to i8*<br>
+// ARM64: %[[V9:.*]] = getelementptr inbounds i8, i8* %[[V8]], i64 8<br>
+// ARM64: %[[V10:.*]] = bitcast i8* %[[V9]] to i8**<br>
+// ARM64: %[[V11:.*]] = call i8* @objc_loadWeakRetained(i8** %[[V10]])<br>
+// ARM64: %[[V12:.*]] = call i8* @objc_storeWeak(i8** %[[V7]], i8* %[[V11]])<br>
+// ARM64: call void @objc_destroyWeak(i8** %[[V10]])<br>
+// ARM64: call void @objc_release(i8* %[[V11]])<br>
+<br>
+void test_move_assignment_Weak(Weak *p) {<br>
+  *p = getWeak();<br>
+}<br>
+<br>
+// COMMON: define void @test_parameter_Weak(%[[STRUCT_WEAK]]* %[[A:.*]])<br>
+// COMMON: %[[V0:.*]] = bitcast %[[STRUCT_WEAK]]* %[[A]] to i8**<br>
+// COMMON: call void @__destructor_{{.*}}(i8** %[[V0]])<br>
+<br>
+void test_parameter_Weak(Weak a) {<br>
+}<br>
+<br>
+// COMMON: define void @test_argument_Weak(%[[STRUCT_WEAK]]* %[[A:.*]])<br>
+// COMMON: %[[A_ADDR:.*]] = alloca %[[STRUCT_WEAK]]*<br>
+// COMMON: %[[AGG_TMP:.*]] = alloca %[[STRUCT_WEAK]]<br>
+// COMMON: store %[[STRUCT_WEAK]]* %[[A]], %[[STRUCT_WEAK]]** %[[A_ADDR]]<br>
+// COMMON: %[[V0:.*]] = load %[[STRUCT_WEAK]]*, %[[STRUCT_WEAK]]** %[[A_ADDR]]<br>
+// COMMON: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_TMP]] to i8**<br>
+// COMMON: %[[V2:.*]] = bitcast %[[STRUCT_WEAK]]* %[[V0]] to i8**<br>
+// COMMON: call void @__copy_constructor_{{.*}}(i8** %[[V1]], i8** %[[V2]])<br>
+// COMMON: call void @calleeWeak(%[[STRUCT_WEAK]]* %[[AGG_TMP]])<br>
+// COMMON-NEXT: ret<br>
+<br>
+void test_argument_Weak(Weak *a) {<br>
+  calleeWeak(*a);<br>
+}<br>
+<br>
+// COMMON: define void @test_return_Weak(%[[STRUCT_WEAK]]* noalias sret %[[AGG_RESULT:.*]], %[[STRUCT_WEAK]]* %[[A:.*]])<br>
+// COMMON: %[[A_ADDR:.*]] = alloca %[[STRUCT_WEAK]]*<br>
+// COMMON: store %[[STRUCT_WEAK]]* %[[A]], %[[STRUCT_WEAK]]** %[[A_ADDR]]<br>
+// COMMON: %[[V0:.*]] = load %[[STRUCT_WEAK]]*, %[[STRUCT_WEAK]]** %[[A_ADDR]]<br>
+// COMMON: %[[V1:.*]] = bitcast %[[STRUCT_WEAK]]* %[[AGG_RESULT]] to i8**<br>
+// COMMON: %[[V2:.*]] = bitcast %[[STRUCT_WEAK]]* %[[V0]] to i8**<br>
+// COMMON: call void @__copy_constructor_{{.*}}(i8** %[[V1]], i8** %[[V2]])<br>
+// COMMON: ret void<br>
+<br>
+Weak test_return_Weak(Weak *a) {<br>
+  return *a;<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></blockquote></div>