diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 57c6f4533630..e14187013a0f 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -3616,24 +3616,24 @@ public: return NonTrivialToPrimitiveDefaultInitialize; } - void setNonTrivialToPrimitiveDefaultInitialize() { - NonTrivialToPrimitiveDefaultInitialize = true; + void setNonTrivialToPrimitiveDefaultInitialize(bool V) { + NonTrivialToPrimitiveDefaultInitialize = V; } bool isNonTrivialToPrimitiveCopy() const { return NonTrivialToPrimitiveCopy; } - void setNonTrivialToPrimitiveCopy() { - NonTrivialToPrimitiveCopy = true; + void setNonTrivialToPrimitiveCopy(bool V) { + NonTrivialToPrimitiveCopy = V; } bool isNonTrivialToPrimitiveDestroy() const { return NonTrivialToPrimitiveDestroy; } - void setNonTrivialToPrimitiveDestroy() { - NonTrivialToPrimitiveDestroy = true; + void setNonTrivialToPrimitiveDestroy(bool V) { + NonTrivialToPrimitiveDestroy = V; } /// \brief Determines whether this declaration represents the diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6e4ae6ae159b..577724bd67ce 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -15445,12 +15445,12 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, if (Record && !getLangOpts().CPlusPlus) { QualType FT = FD->getType(); if (FT.isNonTrivialToPrimitiveDefaultInitialize()) - Record->setNonTrivialToPrimitiveDefaultInitialize(); + Record->setNonTrivialToPrimitiveDefaultInitialize(true); QualType::PrimitiveCopyKind PCK = FT.isNonTrivialToPrimitiveCopy(); if (PCK != QualType::PCK_Trivial && PCK != QualType::PCK_VolatileTrivial) - Record->setNonTrivialToPrimitiveCopy(); + Record->setNonTrivialToPrimitiveCopy(true); if (FT.isDestructedType()) - Record->setNonTrivialToPrimitiveDestroy(); + Record->setNonTrivialToPrimitiveDestroy(true); } if (Record && FD->getType().isVolatileQualified()) diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 10439d36f5bb..ab99a170799d 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -739,6 +739,9 @@ ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { RD->setAnonymousStructOrUnion(Record.readInt()); RD->setHasObjectMember(Record.readInt()); RD->setHasVolatileMember(Record.readInt()); + RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); + RD->setNonTrivialToPrimitiveCopy(Record.readInt()); + RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); return Redecl; } diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index dd57029ca2e6..b3886b6555f8 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -465,6 +465,9 @@ void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { Record.push_back(D->isAnonymousStructOrUnion()); Record.push_back(D->hasObjectMember()); Record.push_back(D->hasVolatileMember()); + Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize()); + Record.push_back(D->isNonTrivialToPrimitiveCopy()); + Record.push_back(D->isNonTrivialToPrimitiveDestroy()); if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && @@ -1899,6 +1902,14 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember + + // isNonTrivialToPrimitiveDefaultInitialize + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + // isNonTrivialToPrimitiveCopy + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + // isNonTrivialToPrimitiveDestroy + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + // DC Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset diff --git a/clang/test/CodeGenObjC/strong-in-c-struct.m b/clang/test/CodeGenObjC/strong-in-c-struct.m index c48c66316d7b..11291f746787 100644 --- a/clang/test/CodeGenObjC/strong-in-c-struct.m +++ b/clang/test/CodeGenObjC/strong-in-c-struct.m @@ -1,4 +1,10 @@ -// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s + +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -emit-pch -o %t %s +// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks -fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s + +#ifndef HEADER +#define HEADER typedef void (^BlockTy)(void); @@ -63,6 +69,10 @@ typedef struct { volatile char i6; } Bitfield1; +#endif + +#ifdef USESTRUCT + StrongSmall getStrongSmall(void); StrongOuter getStrongOuter(void); void calleeStrongSmall(StrongSmall); @@ -520,3 +530,5 @@ void test_copy_constructor_Bitfield0(Bitfield0 *a) { void test_copy_constructor_Bitfield1(Bitfield1 *a) { Bitfield1 t = *a; } + +#endif /* USESTRUCT */