From 53c618c07154f8a99762fb5222aa9c05f6c434f7 Mon Sep 17 00:00:00 2001 From: Peter Rong Date: Wed, 12 Feb 2025 11:52:49 -0800 Subject: [PATCH] [clang] run clang-format on some CGObjC files (#126644) These files are relatively old and don't confront our formatting rules. It's hard to change them without massive clang-format changes. --------- Signed-off-by: Peter Rong --- clang/include/clang/AST/Mangle.h | 58 +- clang/lib/CodeGen/CGObjCMac.cpp | 2212 +++++++++++++-------------- clang/lib/CodeGen/CGObjCRuntime.h | 129 +- clang/lib/CodeGen/CodeGenFunction.h | 407 +++-- 4 files changed, 1310 insertions(+), 1496 deletions(-) diff --git a/clang/include/clang/AST/Mangle.h b/clang/include/clang/AST/Mangle.h index d5f6c0f6cc67..6134a70c04bd 100644 --- a/clang/include/clang/AST/Mangle.h +++ b/clang/include/clang/AST/Mangle.h @@ -22,32 +22,29 @@ #include namespace llvm { - class raw_ostream; +class raw_ostream; } namespace clang { - class ASTContext; - class BlockDecl; - class CXXConstructorDecl; - class CXXDestructorDecl; - class CXXMethodDecl; - class FunctionDecl; - struct MethodVFTableLocation; - class NamedDecl; - class ObjCMethodDecl; - class StringLiteral; - struct ThisAdjustment; - struct ThunkInfo; - class VarDecl; +class ASTContext; +class BlockDecl; +class CXXConstructorDecl; +class CXXDestructorDecl; +class CXXMethodDecl; +class FunctionDecl; +struct MethodVFTableLocation; +class NamedDecl; +class ObjCMethodDecl; +class StringLiteral; +struct ThisAdjustment; +struct ThunkInfo; +class VarDecl; /// MangleContext - Context for tracking state which persists across multiple /// calls to the C++ name mangler. class MangleContext { public: - enum ManglerKind { - MK_Itanium, - MK_Microsoft - }; + enum ManglerKind { MK_Itanium, MK_Microsoft }; private: virtual void anchor(); @@ -59,10 +56,10 @@ class MangleContext { /// ASTContext. bool IsAux = false; - llvm::DenseMap GlobalBlockIds; - llvm::DenseMap LocalBlockIds; - llvm::DenseMap AnonStructIds; - llvm::DenseMap FuncAnonStructSize; + llvm::DenseMap GlobalBlockIds; + llvm::DenseMap LocalBlockIds; + llvm::DenseMap AnonStructIds; + llvm::DenseMap FuncAnonStructSize; public: ManglerKind getKind() const { return Kind; } @@ -73,7 +70,7 @@ class MangleContext { ManglerKind Kind, bool IsAux = false) : Context(Context), Diags(Diags), Kind(Kind), IsAux(IsAux) {} - virtual ~MangleContext() { } + virtual ~MangleContext() {} ASTContext &getASTContext() const { return Context; } @@ -82,10 +79,10 @@ class MangleContext { virtual void startNewFunction() { LocalBlockIds.clear(); } unsigned getBlockId(const BlockDecl *BD, bool Local) { - llvm::DenseMap &BlockIds - = Local? LocalBlockIds : GlobalBlockIds; + llvm::DenseMap &BlockIds = + Local ? LocalBlockIds : GlobalBlockIds; std::pair::iterator, bool> - Result = BlockIds.insert(std::make_pair(BD, BlockIds.size())); + Result = BlockIds.insert(std::make_pair(BD, BlockIds.size())); return Result.first->second; } @@ -125,7 +122,7 @@ class MangleContext { return false; } - virtual void needsUniqueInternalLinkageNames() { } + virtual void needsUniqueInternalLinkageNames() {} // FIXME: consider replacing raw_ostream & with something like SmallString &. void mangleName(GlobalDecl GD, raw_ostream &); @@ -143,10 +140,9 @@ class MangleContext { virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers = false) = 0; virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &) = 0; - virtual void mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream&); + virtual void mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream &); - void mangleGlobalBlock(const BlockDecl *BD, - const NamedDecl *ID, + void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID, raw_ostream &Out); void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out); @@ -314,6 +310,6 @@ class ASTNameGenerator { class Implementation; std::unique_ptr Impl; }; -} +} // namespace clang #endif diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 6c929a6431c0..16986de96bdb 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -63,7 +63,7 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getMessageSendFn() const { // Add the non-lazy-bind attribute, since objc_msgSend is likely to // be called a lot. - llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy }; + llvm::Type *params[] = {ObjectPtrTy, SelectorPtrTy}; return CGM.CreateRuntimeFunction( llvm::FunctionType::get(ObjectPtrTy, params, true), "objc_msgSend", llvm::AttributeList::get(CGM.getLLVMContext(), @@ -77,10 +77,10 @@ class ObjCCommonTypesHelper { /// by indirect reference in the first argument, and therefore the /// self and selector parameters are shifted over by one. llvm::FunctionCallee getMessageSendStretFn() const { - llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(CGM.VoidTy, - params, true), - "objc_msgSend_stret"); + llvm::Type *params[] = {ObjectPtrTy, SelectorPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(CGM.VoidTy, params, true), + "objc_msgSend_stret"); } /// [double | long double] objc_msgSend_fpret(id self, SEL op, ...) @@ -89,10 +89,10 @@ class ObjCCommonTypesHelper { /// floating-point stack; without a special entrypoint, the nil case /// would be unbalanced. llvm::FunctionCallee getMessageSendFpretFn() const { - llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(CGM.DoubleTy, - params, true), - "objc_msgSend_fpret"); + llvm::Type *params[] = {ObjectPtrTy, SelectorPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(CGM.DoubleTy, params, true), + "objc_msgSend_fpret"); } /// _Complex long double objc_msgSend_fp2ret(id self, SEL op, ...) @@ -101,14 +101,14 @@ class ObjCCommonTypesHelper { /// x87 floating point stack; without a special entrypoint, the nil case /// would be unbalanced. Only used on 64-bit X86. llvm::FunctionCallee getMessageSendFp2retFn() const { - llvm::Type *params[] = { ObjectPtrTy, SelectorPtrTy }; + llvm::Type *params[] = {ObjectPtrTy, SelectorPtrTy}; llvm::Type *longDoubleType = llvm::Type::getX86_FP80Ty(VMContext); llvm::Type *resultType = llvm::StructType::get(longDoubleType, longDoubleType); - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(resultType, - params, true), - "objc_msgSend_fp2ret"); + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(resultType, params, true), + "objc_msgSend_fp2ret"); } /// id objc_msgSendSuper(struct objc_super *super, SEL op, ...) @@ -117,10 +117,10 @@ class ObjCCommonTypesHelper { /// semantics. The class passed is the superclass of the current /// class. llvm::FunctionCallee getMessageSendSuperFn() const { - llvm::Type *params[] = { SuperPtrTy, SelectorPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSendSuper"); + llvm::Type *params[] = {SuperPtrTy, SelectorPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSendSuper"); } /// id objc_msgSendSuper2(struct objc_super *super, SEL op, ...) @@ -128,10 +128,10 @@ class ObjCCommonTypesHelper { /// A slightly different messenger used for super calls. The class /// passed is the current class. llvm::FunctionCallee getMessageSendSuperFn2() const { - llvm::Type *params[] = { SuperPtrTy, SelectorPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSendSuper2"); + llvm::Type *params[] = {SuperPtrTy, SelectorPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSendSuper2"); } /// void objc_msgSendSuper_stret(void *stretAddr, struct objc_super *super, @@ -139,10 +139,10 @@ class ObjCCommonTypesHelper { /// /// The messenger used for super calls which return an aggregate indirectly. llvm::FunctionCallee getMessageSendSuperStretFn() const { - llvm::Type *params[] = { Int8PtrTy, SuperPtrTy, SelectorPtrTy }; + llvm::Type *params[] = {Int8PtrTy, SuperPtrTy, SelectorPtrTy}; return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(CGM.VoidTy, params, true), - "objc_msgSendSuper_stret"); + llvm::FunctionType::get(CGM.VoidTy, params, true), + "objc_msgSendSuper_stret"); } /// void objc_msgSendSuper2_stret(void * stretAddr, struct objc_super *super, @@ -150,10 +150,10 @@ class ObjCCommonTypesHelper { /// /// objc_msgSendSuper_stret with the super2 semantics. llvm::FunctionCallee getMessageSendSuperStretFn2() const { - llvm::Type *params[] = { Int8PtrTy, SuperPtrTy, SelectorPtrTy }; + llvm::Type *params[] = {Int8PtrTy, SuperPtrTy, SelectorPtrTy}; return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(CGM.VoidTy, params, true), - "objc_msgSendSuper2_stret"); + llvm::FunctionType::get(CGM.VoidTy, params, true), + "objc_msgSendSuper2_stret"); } llvm::FunctionCallee getMessageSendSuperFpretFn() const { @@ -240,9 +240,8 @@ class ObjCCommonTypesHelper { CanQualType Params[] = { IdType, SelType, Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), Ctx.BoolTy}; - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(IdType, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(IdType, Params)); return CGM.CreateRuntimeFunction(FTy, "objc_getProperty"); } @@ -259,9 +258,8 @@ class ObjCCommonTypesHelper { IdType, Ctx.BoolTy, Ctx.BoolTy}; - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); return CGM.CreateRuntimeFunction(FTy, "objc_setProperty"); } @@ -277,16 +275,15 @@ class ObjCCommonTypesHelper { // void objc_setProperty_nonatomic_copy(id self, SEL _cmd, // id newValue, ptrdiff_t offset); - SmallVector Params; + SmallVector Params; CanQualType IdType = Ctx.getCanonicalParamType(Ctx.getObjCIdType()); CanQualType SelType = Ctx.getCanonicalParamType(Ctx.getObjCSelType()); Params.push_back(IdType); Params.push_back(SelType); Params.push_back(IdType); Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified()); - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); const char *name; if (atomic && copy) name = "objc_setProperty_atomic_copy"; @@ -304,15 +301,14 @@ class ObjCCommonTypesHelper { CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); // void objc_copyStruct (void *, const void *, size_t, bool, bool) - SmallVector Params; + SmallVector Params; Params.push_back(Ctx.VoidPtrTy); Params.push_back(Ctx.VoidPtrTy); Params.push_back(Ctx.getSizeType()); Params.push_back(Ctx.BoolTy); Params.push_back(Ctx.BoolTy); - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); return CGM.CreateRuntimeFunction(FTy, "objc_copyStruct"); } @@ -323,14 +319,14 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getCppAtomicObjectFunction() { CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); - /// void objc_copyCppObjectAtomic(void *dest, const void *src, void *helper); - SmallVector Params; + /// void objc_copyCppObjectAtomic(void *dest, const void *src, void + /// *helper); + SmallVector Params; Params.push_back(Ctx.VoidPtrTy); Params.push_back(Ctx.VoidPtrTy); Params.push_back(Ctx.VoidPtrTy); - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); return CGM.CreateRuntimeFunction(FTy, "objc_copyCppObjectAtomic"); } @@ -338,11 +334,10 @@ class ObjCCommonTypesHelper { CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); // void objc_enumerationMutation (id) - SmallVector Params; + SmallVector Params; Params.push_back(Ctx.getCanonicalParamType(Ctx.getObjCIdType())); - llvm::FunctionType *FTy = - Types.GetFunctionType( - Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); + llvm::FunctionType *FTy = Types.GetFunctionType( + Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); return CGM.CreateRuntimeFunction(FTy, "objc_enumerationMutation"); } @@ -350,13 +345,12 @@ class ObjCCommonTypesHelper { CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); // Class objc_lookUpClass (const char *) - SmallVector Params; + SmallVector Params; Params.push_back( - Ctx.getCanonicalType(Ctx.getPointerType(Ctx.CharTy.withConst()))); + Ctx.getCanonicalType(Ctx.getPointerType(Ctx.CharTy.withConst()))); llvm::FunctionType *FTy = Types.GetFunctionType(Types.arrangeBuiltinFunctionDeclaration( - Ctx.getCanonicalType(Ctx.getObjCClassType()), - Params)); + Ctx.getCanonicalType(Ctx.getObjCClassType()), Params)); return CGM.CreateRuntimeFunction(FTy, "objc_lookUpClass"); } @@ -364,8 +358,7 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcReadWeakFn() { // id objc_read_weak (id *) llvm::Type *args[] = {CGM.UnqualPtrTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_read_weak"); } @@ -373,8 +366,7 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcAssignWeakFn() { // id objc_assign_weak (id, id *) llvm::Type *args[] = {ObjectPtrTy, CGM.UnqualPtrTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_weak"); } @@ -382,8 +374,7 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcAssignGlobalFn() { // id objc_assign_global(id, id *) llvm::Type *args[] = {ObjectPtrTy, CGM.UnqualPtrTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_global"); } @@ -391,8 +382,7 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcAssignThreadLocalFn() { // id objc_assign_threadlocal(id src, id * dest) llvm::Type *args[] = {ObjectPtrTy, CGM.UnqualPtrTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_threadlocal"); } @@ -400,15 +390,14 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcAssignIvarFn() { // id objc_assign_ivar(id, id *, ptrdiff_t) llvm::Type *args[] = {ObjectPtrTy, CGM.UnqualPtrTy, CGM.PtrDiffTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_ivar"); } /// GcMemmoveCollectableFn -- LLVM objc_memmove_collectable function. llvm::FunctionCallee GcMemmoveCollectableFn() { // void *objc_memmove_collectable(void *dst, const void *src, size_t size) - llvm::Type *args[] = { Int8PtrTy, Int8PtrTy, LongTy }; + llvm::Type *args[] = {Int8PtrTy, Int8PtrTy, LongTy}; llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_memmove_collectable"); } @@ -417,17 +406,15 @@ class ObjCCommonTypesHelper { llvm::FunctionCallee getGcAssignStrongCastFn() { // id objc_assign_strongCast(id, id *) llvm::Type *args[] = {ObjectPtrTy, CGM.UnqualPtrTy}; - llvm::FunctionType *FTy = - llvm::FunctionType::get(ObjectPtrTy, args, false); + llvm::FunctionType *FTy = llvm::FunctionType::get(ObjectPtrTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_assign_strongCast"); } /// ExceptionThrowFn - LLVM objc_exception_throw function. llvm::FunctionCallee getExceptionThrowFn() { // void objc_exception_throw(id) - llvm::Type *args[] = { ObjectPtrTy }; - llvm::FunctionType *FTy = - llvm::FunctionType::get(CGM.VoidTy, args, false); + llvm::Type *args[] = {ObjectPtrTy}; + llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.VoidTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_exception_throw"); } @@ -441,18 +428,16 @@ class ObjCCommonTypesHelper { /// SyncEnterFn - LLVM object_sync_enter function. llvm::FunctionCallee getSyncEnterFn() { // int objc_sync_enter (id) - llvm::Type *args[] = { ObjectPtrTy }; - llvm::FunctionType *FTy = - llvm::FunctionType::get(CGM.IntTy, args, false); + llvm::Type *args[] = {ObjectPtrTy}; + llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.IntTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_sync_enter"); } /// SyncExitFn - LLVM object_sync_exit function. llvm::FunctionCallee getSyncExitFn() { // int objc_sync_exit (id) - llvm::Type *args[] = { ObjectPtrTy }; - llvm::FunctionType *FTy = - llvm::FunctionType::get(CGM.IntTy, args, false); + llvm::Type *args[] = {ObjectPtrTy}; + llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.IntTy, args, false); return CGM.CreateRuntimeFunction(FTy, "objc_sync_exit"); } @@ -553,32 +538,32 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper { llvm::FunctionCallee getExceptionTryEnterFn() { llvm::Type *params[] = {CGM.UnqualPtrTy}; return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(CGM.VoidTy, params, false), - "objc_exception_try_enter"); + llvm::FunctionType::get(CGM.VoidTy, params, false), + "objc_exception_try_enter"); } /// ExceptionTryExitFn - LLVM objc_exception_try_exit function. llvm::FunctionCallee getExceptionTryExitFn() { llvm::Type *params[] = {CGM.UnqualPtrTy}; return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(CGM.VoidTy, params, false), - "objc_exception_try_exit"); + llvm::FunctionType::get(CGM.VoidTy, params, false), + "objc_exception_try_exit"); } /// ExceptionExtractFn - LLVM objc_exception_extract function. llvm::FunctionCallee getExceptionExtractFn() { llvm::Type *params[] = {CGM.UnqualPtrTy}; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, false), - "objc_exception_extract"); + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, false), + "objc_exception_extract"); } /// ExceptionMatchFn - LLVM objc_exception_match function. llvm::FunctionCallee getExceptionMatchFn() { - llvm::Type *params[] = { ClassPtrTy, ObjectPtrTy }; + llvm::Type *params[] = {ClassPtrTy, ObjectPtrTy}; return CGM.CreateRuntimeFunction( - llvm::FunctionType::get(CGM.Int32Ty, params, false), - "objc_exception_match"); + llvm::FunctionType::get(CGM.Int32Ty, params, false), + "objc_exception_match"); } /// SetJmpFn - LLVM _setjmp function. @@ -670,44 +655,44 @@ class ObjCNonFragileABITypesHelper : public ObjCCommonTypesHelper { llvm::FunctionCallee getMessageSendFixupFn() { // id objc_msgSend_fixup(id, struct message_ref_t*, ...) - llvm::Type *params[] = { ObjectPtrTy, MessageRefPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSend_fixup"); + llvm::Type *params[] = {ObjectPtrTy, MessageRefPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSend_fixup"); } llvm::FunctionCallee getMessageSendFpretFixupFn() { // id objc_msgSend_fpret_fixup(id, struct message_ref_t*, ...) - llvm::Type *params[] = { ObjectPtrTy, MessageRefPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSend_fpret_fixup"); + llvm::Type *params[] = {ObjectPtrTy, MessageRefPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSend_fpret_fixup"); } llvm::FunctionCallee getMessageSendStretFixupFn() { // id objc_msgSend_stret_fixup(id, struct message_ref_t*, ...) - llvm::Type *params[] = { ObjectPtrTy, MessageRefPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSend_stret_fixup"); + llvm::Type *params[] = {ObjectPtrTy, MessageRefPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSend_stret_fixup"); } llvm::FunctionCallee getMessageSendSuper2FixupFn() { // id objc_msgSendSuper2_fixup (struct objc_super *, // struct _super_message_ref_t*, ...) - llvm::Type *params[] = { SuperPtrTy, SuperMessageRefPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSendSuper2_fixup"); + llvm::Type *params[] = {SuperPtrTy, SuperMessageRefPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSendSuper2_fixup"); } llvm::FunctionCallee getMessageSendSuper2StretFixupFn() { // id objc_msgSendSuper2_stret_fixup(struct objc_super *, // struct _super_message_ref_t*, ...) - llvm::Type *params[] = { SuperPtrTy, SuperMessageRefPtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - params, true), - "objc_msgSendSuper2_stret_fixup"); + llvm::Type *params[] = {SuperPtrTy, SuperMessageRefPtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(ObjectPtrTy, params, true), + "objc_msgSendSuper2_stret_fixup"); } llvm::FunctionCallee getObjCEndCatchFn() { @@ -716,10 +701,9 @@ class ObjCNonFragileABITypesHelper : public ObjCCommonTypesHelper { } llvm::FunctionCallee getObjCBeginCatchFn() { - llvm::Type *params[] = { Int8PtrTy }; - return CGM.CreateRuntimeFunction(llvm::FunctionType::get(Int8PtrTy, - params, false), - "objc_begin_catch"); + llvm::Type *params[] = {Int8PtrTy}; + return CGM.CreateRuntimeFunction( + llvm::FunctionType::get(Int8PtrTy, params, false), "objc_begin_catch"); } /// Class objc_loadClassref (void *) @@ -733,21 +717,23 @@ class ObjCNonFragileABITypesHelper : public ObjCCommonTypesHelper { // // Also it is safe to make it readnone, since we never load or store the // classref except by calling this function. - llvm::Type *params[] = { Int8PtrPtrTy }; + llvm::Type *params[] = {Int8PtrPtrTy}; llvm::LLVMContext &C = CGM.getLLVMContext(); - llvm::AttributeSet AS = llvm::AttributeSet::get(C, { - llvm::Attribute::get(C, llvm::Attribute::NonLazyBind), - llvm::Attribute::getWithMemoryEffects(C, llvm::MemoryEffects::none()), - llvm::Attribute::get(C, llvm::Attribute::NoUnwind), - }); + llvm::AttributeSet AS = llvm::AttributeSet::get( + C, { + llvm::Attribute::get(C, llvm::Attribute::NonLazyBind), + llvm::Attribute::getWithMemoryEffects( + C, llvm::MemoryEffects::none()), + llvm::Attribute::get(C, llvm::Attribute::NoUnwind), + }); llvm::FunctionCallee F = CGM.CreateRuntimeFunction( llvm::FunctionType::get(ClassnfABIPtrTy, params, false), "objc_loadClassref", llvm::AttributeList::get(CGM.getLLVMContext(), llvm::AttributeList::FunctionIndex, AS)); if (!CGM.getTriple().isOSBinFormatCOFF()) - cast(F.getCallee())->setLinkage( - llvm::Function::ExternalWeakLinkage); + cast(F.getCallee()) + ->setLinkage(llvm::Function::ExternalWeakLinkage); return F; } @@ -772,9 +758,10 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { unsigned skip; unsigned scan; SKIP_SCAN(unsigned _skip = 0, unsigned _scan = 0) - : skip(_skip), scan(_scan) {} + : skip(_skip), scan(_scan) {} }; + // clang-format off /// opcode for captured block variables layout 'instructions'. /// In the following descriptions, 'I' is the value of the immediate field. /// (field following the opcode). @@ -821,11 +808,12 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { /// /// This is included so that older tools can at least continue /// processing the layout past such things. - //BLOCK_LAYOUT_OWNERSHIP_UNKNOWN = 7..10, + // BLOCK_LAYOUT_OWNERSHIP_UNKNOWN = 7..10, /// All other opcodes are reserved. Halt interpretation and /// treat everything else as opaque. }; + // clang-format on class RUN_SKIP { public: @@ -835,7 +823,7 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { RUN_SKIP(enum BLOCK_LAYOUT_OPCODE Opcode = BLOCK_LAYOUT_OPERATOR, CharUnits BytePos = CharUnits::Zero(), CharUnits Size = CharUnits::Zero()) - : opcode(Opcode), block_var_bytepos(BytePos), block_var_size(Size) {} + : opcode(Opcode), block_var_bytepos(BytePos), block_var_size(Size) {} // Allow sorting based on byte pos. bool operator<(const RUN_SKIP &b) const { @@ -853,70 +841,71 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { /// LazySymbols - Symbols to generate a lazy reference for. See /// DefinedSymbols and FinishModule(). - llvm::SetVector LazySymbols; + llvm::SetVector LazySymbols; /// DefinedSymbols - External symbols which are defined by this /// module. The symbols in this list and LazySymbols are used to add /// special linker symbols which ensure that Objective-C modules are /// linked properly. - llvm::SetVector DefinedSymbols; + llvm::SetVector DefinedSymbols; /// ClassNames - uniqued class names. - llvm::StringMap ClassNames; + llvm::StringMap ClassNames; /// MethodVarNames - uniqued method variable names. - llvm::DenseMap MethodVarNames; + llvm::DenseMap MethodVarNames; /// DefinedCategoryNames - list of category names in form Class_Category. llvm::SmallSetVector DefinedCategoryNames; /// MethodVarTypes - uniqued method type signatures. We have to use /// a StringMap here because have no other unique reference. - llvm::StringMap MethodVarTypes; + llvm::StringMap MethodVarTypes; /// MethodDefinitions - map of methods which have been defined in /// this translation unit. - llvm::DenseMap MethodDefinitions; + llvm::DenseMap MethodDefinitions; /// DirectMethodDefinitions - map of direct methods which have been defined in /// this translation unit. - llvm::DenseMap DirectMethodDefinitions; + llvm::DenseMap + DirectMethodDefinitions; /// PropertyNames - uniqued method variable names. - llvm::DenseMap PropertyNames; + llvm::DenseMap PropertyNames; /// ClassReferences - uniqued class references. - llvm::DenseMap ClassReferences; + llvm::DenseMap ClassReferences; /// SelectorReferences - uniqued selector references. - llvm::DenseMap SelectorReferences; + llvm::DenseMap SelectorReferences; /// Protocols - Protocols for which an objc_protocol structure has /// been emitted. Forward declarations are handled by creating an /// empty structure whose initializer is filled in when/if defined. - llvm::DenseMap Protocols; + llvm::DenseMap Protocols; /// DefinedProtocols - Protocols which have actually been /// defined. We should not need this, see FIXME in GenerateProtocol. - llvm::DenseSet DefinedProtocols; + llvm::DenseSet DefinedProtocols; /// DefinedClasses - List of defined classes. - SmallVector DefinedClasses; + SmallVector DefinedClasses; /// ImplementedClasses - List of @implemented classes. - SmallVector ImplementedClasses; + SmallVector ImplementedClasses; /// DefinedNonLazyClasses - List of defined "non-lazy" classes. - SmallVector DefinedNonLazyClasses; + SmallVector DefinedNonLazyClasses; /// DefinedCategories - List of defined categories. - SmallVector DefinedCategories; + SmallVector DefinedCategories; /// DefinedStubCategories - List of defined categories on class stubs. - SmallVector DefinedStubCategories; + SmallVector DefinedStubCategories; /// DefinedNonLazyCategories - List of defined "non-lazy" categories. - SmallVector DefinedNonLazyCategories; + SmallVector DefinedNonLazyCategories; /// Cached reference to the class for constant strings. This value has type /// int * but is actually an Obj-C class pointer. @@ -963,10 +952,8 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { /// building a weak layout. Does not guarantee that the layout will /// actually have any entries, because the ivar might be under-aligned. llvm::Constant *BuildIvarLayout(const ObjCImplementationDecl *OI, - CharUnits beginOffset, - CharUnits endOffset, - bool forStrongLayout, - bool hasMRCWeakIvars); + CharUnits beginOffset, CharUnits endOffset, + bool forStrongLayout, bool hasMRCWeakIvars); llvm::Constant *BuildStrongIvarLayout(const ObjCImplementationDecl *OI, CharUnits beginOffset, @@ -981,22 +968,19 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { return BuildIvarLayout(OI, beginOffset, endOffset, false, hasMRCWeakIvars); } - Qualifiers::ObjCLifetime getBlockCaptureLifetime(QualType QT, bool ByrefLayout); + Qualifiers::ObjCLifetime getBlockCaptureLifetime(QualType QT, + bool ByrefLayout); - void UpdateRunSkipBlockVars(bool IsByref, - Qualifiers::ObjCLifetime LifeTime, - CharUnits FieldOffset, - CharUnits FieldSize); + void UpdateRunSkipBlockVars(bool IsByref, Qualifiers::ObjCLifetime LifeTime, + CharUnits FieldOffset, CharUnits FieldSize); - void BuildRCBlockVarRecordLayout(const RecordType *RT, - CharUnits BytePos, bool &HasUnion, - bool ByrefLayout=false); + void BuildRCBlockVarRecordLayout(const RecordType *RT, CharUnits BytePos, + bool &HasUnion, bool ByrefLayout = false); void BuildRCRecordLayout(const llvm::StructLayout *RecLayout, const RecordDecl *RD, - ArrayRef RecFields, - CharUnits BytePos, bool &HasUnion, - bool ByrefLayout); + ArrayRef RecFields, + CharUnits BytePos, bool &HasUnion, bool ByrefLayout); uint64_t InlineLayoutInstruction(SmallVectorImpl &Layout); @@ -1009,17 +993,16 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { /// EmitPropertyList - Emit the given property list. The return /// value has type PropertyListPtrTy. - llvm::Constant *EmitPropertyList(Twine Name, - const Decl *Container, + llvm::Constant *EmitPropertyList(Twine Name, const Decl *Container, const ObjCContainerDecl *OCD, const ObjCCommonTypesHelper &ObjCTypes, bool IsClassProperty); /// EmitProtocolMethodTypes - Generate the array of extended method type /// strings. The return value has type Int8PtrPtrTy. - llvm::Constant *EmitProtocolMethodTypes(Twine Name, - ArrayRef MethodTypes, - const ObjCCommonTypesHelper &ObjCTypes); + llvm::Constant * + EmitProtocolMethodTypes(Twine Name, ArrayRef MethodTypes, + const ObjCCommonTypesHelper &ObjCTypes); /// GetProtocolRef - Return a reference to the internal protocol /// description, creating an empty one if it has not been @@ -1053,8 +1036,7 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { ConstantStructBuilder &Init, StringRef Section, CharUnits Align, bool AddToUsed); - llvm::GlobalVariable *CreateMetadataVar(Twine Name, - llvm::Constant *Init, + llvm::GlobalVariable *CreateMetadataVar(Twine Name, llvm::Constant *Init, StringRef Section, CharUnits Align, bool AddToUsed); @@ -1065,12 +1047,9 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { protected: CodeGen::RValue EmitMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Arg0, - QualType Arg0Ty, - bool IsSuper, + ReturnValueSlot Return, QualType ResultType, + Selector Sel, llvm::Value *Arg0, + QualType Arg0Ty, bool IsSuper, const CallArgList &CallArgs, const ObjCMethodDecl *OMD, const ObjCInterfaceDecl *ClassReceiver, @@ -1084,15 +1063,14 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGObjCRuntime(cgm), VMContext(cgm.getLLVMContext()) {} - bool isNonFragileABI() const { - return ObjCABI == 2; - } + bool isNonFragileABI() const { return ObjCABI == 2; } ConstantAddress GenerateConstantString(const StringLiteral *SL) override; ConstantAddress GenerateConstantNSString(const StringLiteral *SL); - llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD, - const ObjCContainerDecl *CD=nullptr) override; + llvm::Function * + GenerateMethod(const ObjCMethodDecl *OMD, + const ObjCContainerDecl *CD = nullptr) override; llvm::Function *GenerateDirectMethod(const ObjCMethodDecl *OMD, const ObjCContainerDecl *CD); @@ -1107,7 +1085,7 @@ class CGObjCCommonMac : public CodeGen::CGObjCRuntime { /// object for the given declaration, emitting it if needed. These /// forward references will be filled in with empty bodies if no /// definition is seen. The return value has type ProtocolPtrTy. - virtual llvm::Constant *GetOrEmitProtocolRef(const ObjCProtocolDecl *PD)=0; + virtual llvm::Constant *GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) = 0; virtual llvm::Constant *getNSConstantStringClassRef() = 0; @@ -1148,9 +1126,7 @@ class ProtocolMethodLists { OptionalInstanceMethods, OptionalClassMethods }; - enum { - NumProtocolMethodLists = 4 - }; + enum { NumProtocolMethodLists = 4 }; static MethodListType getMethodListKind(Kind kind) { switch (kind) { @@ -1172,8 +1148,8 @@ class ProtocolMethodLists { ProtocolMethodLists result; for (auto *MD : PD->methods()) { - size_t index = (2 * size_t(MD->isOptional())) - + (size_t(MD->isClassMethod())); + size_t index = + (2 * size_t(MD->isOptional())) + (size_t(MD->isClassMethod())); result.Methods[index].push_back(MD); } @@ -1181,14 +1157,14 @@ class ProtocolMethodLists { } template - SmallVector emitExtendedTypesArray(Self *self) const { + SmallVector emitExtendedTypesArray(Self *self) const { // In both ABIs, the method types list is parallel with the // concatenation of the methods arrays in the following order: // instance methods // class methods // optional instance methods // optional class methods - SmallVector result; + SmallVector result; // Methods is already in the correct order for both ABIs. for (auto &list : Methods) { @@ -1233,16 +1209,13 @@ class CGObjCMac : public CGObjCCommonMac { /// has type ClassExtensionPtrTy. llvm::Constant *EmitClassExtension(const ObjCImplementationDecl *ID, CharUnits instanceSize, - bool hasMRCWeakIvars, - bool isMetaclass); + bool hasMRCWeakIvars, bool isMetaclass); /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy, /// for the given class. - llvm::Value *EmitClassRef(CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID); + llvm::Value *EmitClassRef(CodeGenFunction &CGF, const ObjCInterfaceDecl *ID); - llvm::Value *EmitClassRefFromId(CodeGenFunction &CGF, - IdentifierInfo *II); + llvm::Value *EmitClassRefFromId(CodeGenFunction &CGF, IdentifierInfo *II); llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) override; @@ -1254,8 +1227,7 @@ class CGObjCMac : public CGObjCCommonMac { /// (i.e. metaclass ivars) is emitted, otherwise the list of /// interface ivars will be emitted. The return value has type /// IvarListPtrTy. - llvm::Constant *EmitIvarList(const ObjCImplementationDecl *ID, - bool ForClass); + llvm::Constant *EmitIvarList(const ObjCImplementationDecl *ID, bool ForClass); /// EmitMetaClass - Emit a forward reference to the class structure /// for the metaclass of the given interface. The return value has @@ -1294,9 +1266,8 @@ class CGObjCMac : public CGObjCCommonMac { /// structure used to store optional instance and class methods, and /// protocol properties. The return value has type /// ProtocolExtensionPtrTy. - llvm::Constant * - EmitProtocolExtension(const ObjCProtocolDecl *PD, - const ProtocolMethodLists &methodLists); + llvm::Constant *EmitProtocolExtension(const ObjCProtocolDecl *PD, + const ProtocolMethodLists &methodLists); /// EmitProtocolList - Generate the list of referenced /// protocols. The return value has type ProtocolListPtrTy. @@ -1318,19 +1289,17 @@ class CGObjCMac : public CGObjCCommonMac { CodeGen::RValue GenerateMessageSend(CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, - QualType ResultType, - Selector Sel, llvm::Value *Receiver, + QualType ResultType, Selector Sel, + llvm::Value *Receiver, const CallArgList &CallArgs, const ObjCInterfaceDecl *Class, const ObjCMethodDecl *Method) override; - CodeGen::RValue - GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, QualType ResultType, - Selector Sel, const ObjCInterfaceDecl *Class, - bool isCategoryImpl, llvm::Value *Receiver, - bool IsClassMessage, const CallArgList &CallArgs, - const ObjCMethodDecl *Method) override; + CodeGen::RValue GenerateMessageSendSuper( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, + QualType ResultType, Selector Sel, const ObjCInterfaceDecl *Class, + bool isCategoryImpl, llvm::Value *Receiver, bool IsClassMessage, + const CallArgList &CallArgs, const ObjCMethodDecl *Method) override; llvm::Value *GetClass(CodeGenFunction &CGF, const ObjCInterfaceDecl *ID) override; @@ -1370,22 +1339,19 @@ class CGObjCMac : public CGObjCCommonMac { const ObjCAtSynchronizedStmt &S) override; void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const Stmt &S); void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtThrowStmt &S, - bool ClearInsertionPoint=true) override; - llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, - Address AddrWeakObj) override; - void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dst) override; - void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest, - bool threadlocal = false) override; - void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest, - llvm::Value *ivarOffset) override; - void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest) override; - void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, - Address dest, Address src, - llvm::Value *size) override; + bool ClearInsertionPoint = true) override; + llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, + Address AddrWeakObj) override; + void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dst) override; + void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest, bool threadlocal = false) override; + void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest, llvm::Value *ivarOffset) override; + void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest) override; + void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address dest, + Address src, llvm::Value *size) override; LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, @@ -1399,24 +1365,24 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { private: friend ProtocolMethodLists; ObjCNonFragileABITypesHelper ObjCTypes; - llvm::GlobalVariable* ObjCEmptyCacheVar; - llvm::Constant* ObjCEmptyVtableVar; + llvm::GlobalVariable *ObjCEmptyCacheVar; + llvm::Constant *ObjCEmptyVtableVar; /// SuperClassReferences - uniqued super class references. - llvm::DenseMap SuperClassReferences; + llvm::DenseMap SuperClassReferences; /// MetaClassReferences - uniqued meta class references. - llvm::DenseMap MetaClassReferences; + llvm::DenseMap MetaClassReferences; /// EHTypeReferences - uniqued class ehtype references. - llvm::DenseMap EHTypeReferences; + llvm::DenseMap EHTypeReferences; /// VTableDispatchMethods - List of methods for which we generate /// vtable-based message dispatch. llvm::DenseSet VTableDispatchMethods; /// DefinedMetaClasses - List of defined meta-classes. - std::vector DefinedMetaClasses; + std::vector DefinedMetaClasses; /// isVTableDispatchedSelector - Returns true if SEL is a /// vtable-based selector. @@ -1431,20 +1397,17 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { void AddModuleClassList(ArrayRef Container, StringRef SymbolName, StringRef SectionName); - llvm::GlobalVariable * BuildClassRoTInitializer(unsigned flags, - unsigned InstanceStart, - unsigned InstanceSize, - const ObjCImplementationDecl *ID); - llvm::GlobalVariable *BuildClassObject(const ObjCInterfaceDecl *CI, - bool isMetaclass, - llvm::Constant *IsAGV, - llvm::Constant *SuperClassGV, - llvm::Constant *ClassRoGV, - bool HiddenVisibility); + llvm::GlobalVariable * + BuildClassRoTInitializer(unsigned flags, unsigned InstanceStart, + unsigned InstanceSize, + const ObjCImplementationDecl *ID); + llvm::GlobalVariable * + BuildClassObject(const ObjCInterfaceDecl *CI, bool isMetaclass, + llvm::Constant *IsAGV, llvm::Constant *SuperClassGV, + llvm::Constant *ClassRoGV, bool HiddenVisibility); void emitMethodConstant(ConstantArrayBuilder &builder, - const ObjCMethodDecl *MD, - bool forProtocol); + const ObjCMethodDecl *MD, bool forProtocol); /// Emit the method list for the given implementation. The return value /// has type MethodListnfABITy. @@ -1479,23 +1442,17 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { ObjCProtocolDecl::protocol_iterator begin, ObjCProtocolDecl::protocol_iterator end); - CodeGen::RValue EmitVTableMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Receiver, - QualType Arg0Ty, - bool IsSuper, - const CallArgList &CallArgs, - const ObjCMethodDecl *Method); + CodeGen::RValue EmitVTableMessageSend( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, + QualType ResultType, Selector Sel, llvm::Value *Receiver, QualType Arg0Ty, + bool IsSuper, const CallArgList &CallArgs, const ObjCMethodDecl *Method); /// GetClassGlobal - Return the global variable for the Objective-C /// class of the given name. llvm::Constant *GetClassGlobal(StringRef Name, ForDefinition_t IsForDefinition, bool Weak = false, bool DLLImport = false); - llvm::Constant *GetClassGlobal(const ObjCInterfaceDecl *ID, - bool isMetaclass, + llvm::Constant *GetClassGlobal(const ObjCInterfaceDecl *ID, bool isMetaclass, ForDefinition_t isForDefinition); llvm::Constant *GetClassGlobalForClassRef(const ObjCInterfaceDecl *ID); @@ -1506,11 +1463,9 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { /// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy, /// for the given class reference. - llvm::Value *EmitClassRef(CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID); + llvm::Value *EmitClassRef(CodeGenFunction &CGF, const ObjCInterfaceDecl *ID); - llvm::Value *EmitClassRefFromId(CodeGenFunction &CGF, - IdentifierInfo *II, + llvm::Value *EmitClassRefFromId(CodeGenFunction &CGF, IdentifierInfo *II, const ObjCInterfaceDecl *ID); llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) override; @@ -1528,9 +1483,8 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { /// ObjCIvarOffsetVariable - Returns the ivar offset variable for /// the given ivar. /// - llvm::GlobalVariable * ObjCIvarOffsetVariable( - const ObjCInterfaceDecl *ID, - const ObjCIvarDecl *Ivar); + llvm::GlobalVariable *ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID, + const ObjCIvarDecl *Ivar); /// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy, /// for the given selector. @@ -1547,16 +1501,15 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { StringRef getClassSymbolPrefix() const { return "OBJC_CLASS_$_"; } void GetClassSizeInfo(const ObjCImplementationDecl *OID, - uint32_t &InstanceStart, - uint32_t &InstanceSize); + uint32_t &InstanceStart, uint32_t &InstanceSize); // Shamelessly stolen from Analysis/CFRefCount.cpp - Selector GetNullarySelector(const char* name) const { + Selector GetNullarySelector(const char *name) const { const IdentifierInfo *II = &CGM.getContext().Idents.get(name); return CGM.getContext().Selectors.getSelector(0, &II); } - Selector GetUnarySelector(const char* name) const { + Selector GetUnarySelector(const char *name) const { const IdentifierInfo *II = &CGM.getContext().Idents.get(name); return CGM.getContext().Selectors.getSelector(1, &II); } @@ -1582,7 +1535,7 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { // and that the method may be inlined, this optimization actually // can't be performed. if (const ObjCMethodDecl *MD = - dyn_cast_or_null(CGF.CurFuncDecl)) + dyn_cast_or_null(CGF.CurFuncDecl)) if (MD->isInstanceMethod() && !MD->isDirectMethod()) if (const ObjCInterfaceDecl *ID = MD->getClassInterface()) return IV->getContainingInterface()->isSuperClassOf(ID); @@ -1621,27 +1574,28 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { const ObjCInterfaceDecl *Class, const ObjCMethodDecl *Method) override; - CodeGen::RValue - GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, QualType ResultType, - Selector Sel, const ObjCInterfaceDecl *Class, - bool isCategoryImpl, llvm::Value *Receiver, - bool IsClassMessage, const CallArgList &CallArgs, - const ObjCMethodDecl *Method) override; + CodeGen::RValue GenerateMessageSendSuper( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, + QualType ResultType, Selector Sel, const ObjCInterfaceDecl *Class, + bool isCategoryImpl, llvm::Value *Receiver, bool IsClassMessage, + const CallArgList &CallArgs, const ObjCMethodDecl *Method) override; llvm::Value *GetClass(CodeGenFunction &CGF, const ObjCInterfaceDecl *ID) override; - llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel) override - { return EmitSelector(CGF, Sel); } - Address GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel) override - { return EmitSelectorAddr(Sel); } + llvm::Value *GetSelector(CodeGenFunction &CGF, Selector Sel) override { + return EmitSelector(CGF, Sel); + } + Address GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel) override { + return EmitSelectorAddr(Sel); + } /// The NeXT/Apple runtimes do not support typed selectors; just emit an /// untyped one. llvm::Value *GetSelector(CodeGenFunction &CGF, - const ObjCMethodDecl *Method) override - { return EmitSelector(CGF, Method->getSelector()); } + const ObjCMethodDecl *Method) override { + return EmitSelector(CGF, Method->getSelector()); + } void GenerateCategory(const ObjCCategoryImplDecl *CMD) override; @@ -1691,22 +1645,19 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac { void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S) override; void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtThrowStmt &S, - bool ClearInsertionPoint=true) override; - llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, - Address AddrWeakObj) override; - void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address edst) override; - void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest, - bool threadlocal = false) override; - void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest, - llvm::Value *ivarOffset) override; - void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dest) override; - void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, - Address dest, Address src, - llvm::Value *size) override; + bool ClearInsertionPoint = true) override; + llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, + Address AddrWeakObj) override; + void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address edst) override; + void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest, bool threadlocal = false) override; + void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest, llvm::Value *ivarOffset) override; + void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, + Address dest) override; + void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address dest, + Address src, llvm::Value *size) override; LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers) override; @@ -1740,14 +1691,12 @@ struct NullReturnState { /// Complete the null-return operation. It is valid to call this /// regardless of whether 'init' has been called. - RValue complete(CodeGenFunction &CGF, - ReturnValueSlot returnSlot, - RValue result, - QualType resultType, - const CallArgList &CallArgs, - const ObjCMethodDecl *Method) { + RValue complete(CodeGenFunction &CGF, ReturnValueSlot returnSlot, + RValue result, QualType resultType, + const CallArgList &CallArgs, const ObjCMethodDecl *Method) { // If we never had to do a null-check, just use the raw result. - if (!NullBB) return result; + if (!NullBB) + return result; // The continuation block. This will be left null if we don't have an // IP, which can happen if the method we're calling is marked noreturn. @@ -1774,7 +1723,8 @@ struct NullReturnState { // If we've got a void return, just jump to the continuation block. if (result.isScalar() && resultType->isVoidType()) { // No jumps required if the message-send was noreturn. - if (contBB) CGF.EmitBlock(contBB); + if (contBB) + CGF.EmitBlock(contBB); return result; } @@ -1785,7 +1735,8 @@ struct NullReturnState { CGF.EmitFromMemory(CGF.CGM.EmitNullConstant(resultType), resultType); // If no join is necessary, just flow out. - if (!contBB) return RValue::get(null); + if (!contBB) + return RValue::get(null); // Otherwise, build a phi. CGF.EmitBlock(contBB); @@ -1803,7 +1754,8 @@ struct NullReturnState { assert(result.isAggregate() && "null init of non-aggregate result?"); if (!returnSlot.isUnused()) CGF.EmitNullInitialization(result.getAggregateAddress(), resultType); - if (contBB) CGF.EmitBlock(contBB); + if (contBB) + CGF.EmitBlock(contBB); return result; } @@ -1835,9 +1787,8 @@ static llvm::Constant *getConstantGEP(llvm::LLVMContext &VMContext, llvm::GlobalVariable *C, unsigned idx0, unsigned idx1) { llvm::Value *Idxs[] = { - llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx0), - llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx1) - }; + llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx0), + llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx1)}; return llvm::ConstantExpr::getGetElementPtr(C->getValueType(), C, Idxs); } @@ -1863,7 +1814,7 @@ getLinkageTypeForObjCMetadata(CodeGenModule &CGM, StringRef Section) { /// A helper function to create an internal or private global variable. static llvm::GlobalVariable * finishAndCreateGlobal(ConstantInitBuilder::StructBuilder &Builder, - const llvm::Twine &Name, CodeGenModule &CGM) { + const llvm::Twine &Name, CodeGenModule &CGM) { std::string SectionName; if (CGM.getTriple().isOSBinFormatMachO()) SectionName = "__DATA, __objc_const"; @@ -1876,8 +1827,8 @@ finishAndCreateGlobal(ConstantInitBuilder::StructBuilder &Builder, /* *** CGObjCMac Public Interface *** */ -CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGObjCCommonMac(cgm), - ObjCTypes(cgm) { +CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) + : CGObjCCommonMac(cgm), ObjCTypes(cgm) { ObjCABI = 1; EmitImageInfo(); } @@ -1896,24 +1847,22 @@ llvm::Value *CGObjCMac::GetSelector(CodeGenFunction &CGF, Selector Sel) { Address CGObjCMac::GetAddrOfSelector(CodeGenFunction &CGF, Selector Sel) { return EmitSelectorAddr(Sel); } -llvm::Value *CGObjCMac::GetSelector(CodeGenFunction &CGF, const ObjCMethodDecl - *Method) { +llvm::Value *CGObjCMac::GetSelector(CodeGenFunction &CGF, + const ObjCMethodDecl *Method) { return EmitSelector(CGF, Method->getSelector()); } llvm::Constant *CGObjCMac::GetEHType(QualType T) { - if (T->isObjCIdType() || - T->isObjCQualifiedIdType()) { + if (T->isObjCIdType() || T->isObjCQualifiedIdType()) { return CGM.GetAddrOfRTTIDescriptor( - CGM.getContext().getObjCIdRedefinitionType(), /*ForEH=*/true); + CGM.getContext().getObjCIdRedefinitionType(), /*ForEH=*/true); } - if (T->isObjCClassType() || - T->isObjCQualifiedClassType()) { + if (T->isObjCClassType() || T->isObjCQualifiedClassType()) { return CGM.GetAddrOfRTTIDescriptor( - CGM.getContext().getObjCClassRedefinitionType(), /*ForEH=*/true); + CGM.getContext().getObjCClassRedefinitionType(), /*ForEH=*/true); } if (T->isObjCObjectPointerType()) - return CGM.GetAddrOfRTTIDescriptor(T, /*ForEH=*/true); + return CGM.GetAddrOfRTTIDescriptor(T, /*ForEH=*/true); llvm_unreachable("asking for catch type for ObjC type in fragile runtime"); } @@ -1940,8 +1889,8 @@ llvm::Constant *CGObjCMac::GetEHType(QualType T) { ConstantAddress CGObjCCommonMac::GenerateConstantString(const StringLiteral *SL) { return (!CGM.getLangOpts().NoConstantCFStrings - ? CGM.GetAddrOfConstantCFString(SL) - : GenerateConstantNSString(SL)); + ? CGM.GetAddrOfConstantCFString(SL) + : GenerateConstantNSString(SL)); } static llvm::StringMapEntry & @@ -1957,9 +1906,8 @@ llvm::Constant *CGObjCMac::getNSConstantStringClassRef() { return cast(V); auto &StringClass = CGM.getLangOpts().ObjCConstantStringClass; - std::string str = - StringClass.empty() ? "_NSConstantStringClassReference" - : "_" + StringClass + "ClassReference"; + std::string str = StringClass.empty() ? "_NSConstantStringClassReference" + : "_" + StringClass + "ClassReference"; llvm::Type *PTy = llvm::ArrayType::get(CGM.IntTy, 0); auto GV = CGM.CreateRuntimeVariable(PTy, str); @@ -1972,9 +1920,8 @@ llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() { return cast(V); auto &StringClass = CGM.getLangOpts().ObjCConstantStringClass; - std::string str = - StringClass.empty() ? "OBJC_CLASS_$_NSConstantString" - : "OBJC_CLASS_$_" + StringClass; + std::string str = StringClass.empty() ? "OBJC_CLASS_$_NSConstantString" + : "OBJC_CLASS_$_" + StringClass; llvm::Constant *GV = GetClassGlobal(str, NotForDefinition); ConstantStringClassRef = GV; return GV; @@ -1984,11 +1931,11 @@ ConstantAddress CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) { unsigned StringLength = 0; llvm::StringMapEntry &Entry = - GetConstantStringEntry(NSConstantStringMap, Literal, StringLength); + GetConstantStringEntry(NSConstantStringMap, Literal, StringLength); if (auto *C = Entry.second) - return ConstantAddress( - C, C->getValueType(), CharUnits::fromQuantity(C->getAlignment())); + return ConstantAddress(C, C->getValueType(), + CharUnits::fromQuantity(C->getAlignment())); // If we don't already have it, get _NSConstantStringClassReference. llvm::Constant *Class = getNSConstantStringClassRef(); @@ -2008,7 +1955,7 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) { // String pointer. llvm::Constant *C = - llvm::ConstantDataArray::getString(VMContext, Entry.first()); + llvm::ConstantDataArray::getString(VMContext, Entry.first()); llvm::GlobalValue::LinkageTypes Linkage = llvm::GlobalValue::PrivateLinkage; bool isConstant = !CGM.getLangOpts().WritableStrings; @@ -2041,30 +1988,22 @@ CGObjCCommonMac::GenerateConstantNSString(const StringLiteral *Literal) { return ConstantAddress(GV, GV->getValueType(), Alignment); } -enum { - kCFTaggedObjectID_Integer = (1 << 1) + 1 -}; +enum { kCFTaggedObjectID_Integer = (1 << 1) + 1 }; /// Generates a message send where the super is the receiver. This is /// a message send to self with special delivery semantics indicating /// which class's method should be called. -CodeGen::RValue -CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - const ObjCInterfaceDecl *Class, - bool isCategoryImpl, - llvm::Value *Receiver, - bool IsClassMessage, - const CodeGen::CallArgList &CallArgs, - const ObjCMethodDecl *Method) { +CodeGen::RValue CGObjCMac::GenerateMessageSendSuper( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, const ObjCInterfaceDecl *Class, bool isCategoryImpl, + llvm::Value *Receiver, bool IsClassMessage, + const CodeGen::CallArgList &CallArgs, const ObjCMethodDecl *Method) { // Create and init a super structure; this is a (receiver, class) // pair we will pass to objc_msgSendSuper. RawAddress ObjCSuper = CGF.CreateTempAlloca( ObjCTypes.SuperTy, CGF.getPointerAlign(), "objc_super"); llvm::Value *ReceiverAsObject = - CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy); + CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy); CGF.Builder.CreateStore(ReceiverAsObject, CGF.Builder.CreateStructGEP(ObjCSuper, 0)); @@ -2102,7 +2041,7 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, // FIXME: We shouldn't need to do this cast, rectify the ASTContext and // ObjCTypes types. llvm::Type *ClassTy = - CGM.getTypes().ConvertType(CGF.getContext().getObjCClassType()); + CGM.getTypes().ConvertType(CGF.getContext().getObjCClassType()); Target = CGF.Builder.CreateBitCast(Target, ClassTy); CGF.Builder.CreateStore(Target, CGF.Builder.CreateStructGEP(ObjCSuper, 1)); return EmitMessageSend(CGF, Return, ResultType, Sel, ObjCSuper.getPointer(), @@ -2111,31 +2050,21 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, } /// Generate code for a message send expression. -CodeGen::RValue CGObjCMac::GenerateMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Receiver, - const CallArgList &CallArgs, - const ObjCInterfaceDecl *Class, - const ObjCMethodDecl *Method) { +CodeGen::RValue CGObjCMac::GenerateMessageSend( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, llvm::Value *Receiver, const CallArgList &CallArgs, + const ObjCInterfaceDecl *Class, const ObjCMethodDecl *Method) { return EmitMessageSend(CGF, Return, ResultType, Sel, Receiver, CGF.getContext().getObjCIdType(), false, CallArgs, Method, Class, ObjCTypes); } -CodeGen::RValue -CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Arg0, - QualType Arg0Ty, - bool IsSuper, - const CallArgList &CallArgs, - const ObjCMethodDecl *Method, - const ObjCInterfaceDecl *ClassReceiver, - const ObjCCommonTypesHelper &ObjCTypes) { +CodeGen::RValue CGObjCCommonMac::EmitMessageSend( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, llvm::Value *Arg0, QualType Arg0Ty, bool IsSuper, + const CallArgList &CallArgs, const ObjCMethodDecl *Method, + const ObjCInterfaceDecl *ClassReceiver, + const ObjCCommonTypesHelper &ObjCTypes) { CodeGenTypes &Types = CGM.getTypes(); auto selTy = CGF.getContext().getObjCSelType(); llvm::Value *SelValue = llvm::UndefValue::get(Types.ConvertType(selTy)); @@ -2157,7 +2086,7 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, "Result type mismatch!"); bool ReceiverCanBeNull = - canMessageReceiverBeNull(CGF, Method, IsSuper, ClassReceiver, Arg0); + canMessageReceiverBeNull(CGF, Method, IsSuper, ClassReceiver, Arg0); bool RequiresNullCheck = false; bool RequiresSelValue = true; @@ -2170,22 +2099,23 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, // so just don't bother with setting the `_cmd` argument. RequiresSelValue = false; } else if (CGM.ReturnSlotInterferesWithArgs(MSI.CallInfo)) { - if (ReceiverCanBeNull) RequiresNullCheck = true; - Fn = (ObjCABI == 2) ? ObjCTypes.getSendStretFn2(IsSuper) - : ObjCTypes.getSendStretFn(IsSuper); + if (ReceiverCanBeNull) + RequiresNullCheck = true; + Fn = (ObjCABI == 2) ? ObjCTypes.getSendStretFn2(IsSuper) + : ObjCTypes.getSendStretFn(IsSuper); } else if (CGM.ReturnTypeUsesFPRet(ResultType)) { Fn = (ObjCABI == 2) ? ObjCTypes.getSendFpretFn2(IsSuper) - : ObjCTypes.getSendFpretFn(IsSuper); + : ObjCTypes.getSendFpretFn(IsSuper); } else if (CGM.ReturnTypeUsesFP2Ret(ResultType)) { Fn = (ObjCABI == 2) ? ObjCTypes.getSendFp2RetFn2(IsSuper) - : ObjCTypes.getSendFp2retFn(IsSuper); + : ObjCTypes.getSendFp2retFn(IsSuper); } else { // arm64 uses objc_msgSend for stret methods and yet null receiver check // must be made for it. if (ReceiverCanBeNull && CGM.ReturnTypeUsesSRet(MSI.CallInfo)) RequiresNullCheck = true; Fn = (ObjCABI == 2) ? ObjCTypes.getSendFn2(IsSuper) - : ObjCTypes.getSendFn(IsSuper); + : ObjCTypes.getSendFn(IsSuper); } // Cast function to proper signature @@ -2214,8 +2144,8 @@ CGObjCCommonMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF, llvm::CallBase *CallSite; CGCallee Callee = CGCallee::forDirect(BitcastFn); - RValue rvalue = CGF.EmitCall(MSI.CallInfo, Callee, Return, ActualArgs, - &CallSite); + RValue rvalue = + CGF.EmitCall(MSI.CallInfo, Callee, Return, ActualArgs, &CallSite); // Mark the call as noreturn if the method is marked noreturn and the // receiver cannot be null. @@ -2240,13 +2170,19 @@ static Qualifiers::GC GetGCAttrTypeForType(ASTContext &Ctx, QualType FQT, if (auto ownership = FQT.getObjCLifetime()) { // Ownership does not apply recursively to C pointer types. - if (pointee) return Qualifiers::GCNone; + if (pointee) + return Qualifiers::GCNone; switch (ownership) { - case Qualifiers::OCL_Weak: return Qualifiers::Weak; - case Qualifiers::OCL_Strong: return Qualifiers::Strong; - case Qualifiers::OCL_ExplicitNone: return Qualifiers::GCNone; - case Qualifiers::OCL_Autoreleasing: llvm_unreachable("autoreleasing ivar?"); - case Qualifiers::OCL_None: llvm_unreachable("known nonzero"); + case Qualifiers::OCL_Weak: + return Qualifiers::Weak; + case Qualifiers::OCL_Strong: + return Qualifiers::Strong; + case Qualifiers::OCL_ExplicitNone: + return Qualifiers::GCNone; + case Qualifiers::OCL_Autoreleasing: + llvm_unreachable("autoreleasing ivar?"); + case Qualifiers::OCL_None: + llvm_unreachable("known nonzero"); } llvm_unreachable("bad objc ownership"); } @@ -2265,76 +2201,73 @@ static Qualifiers::GC GetGCAttrTypeForType(ASTContext &Ctx, QualType FQT, } namespace { - struct IvarInfo { - CharUnits Offset; - uint64_t SizeInWords; - IvarInfo(CharUnits offset, uint64_t sizeInWords) +struct IvarInfo { + CharUnits Offset; + uint64_t SizeInWords; + IvarInfo(CharUnits offset, uint64_t sizeInWords) : Offset(offset), SizeInWords(sizeInWords) {} - // Allow sorting based on byte pos. - bool operator<(const IvarInfo &other) const { - return Offset < other.Offset; - } - }; + // Allow sorting based on byte pos. + bool operator<(const IvarInfo &other) const { return Offset < other.Offset; } +}; - /// A helper class for building GC layout strings. - class IvarLayoutBuilder { - CodeGenModule &CGM; +/// A helper class for building GC layout strings. +class IvarLayoutBuilder { + CodeGenModule &CGM; - /// The start of the layout. Offsets will be relative to this value, - /// and entries less than this value will be silently discarded. - CharUnits InstanceBegin; + /// The start of the layout. Offsets will be relative to this value, + /// and entries less than this value will be silently discarded. + CharUnits InstanceBegin; - /// The end of the layout. Offsets will never exceed this value. - CharUnits InstanceEnd; + /// The end of the layout. Offsets will never exceed this value. + CharUnits InstanceEnd; - /// Whether we're generating the strong layout or the weak layout. - bool ForStrongLayout; + /// Whether we're generating the strong layout or the weak layout. + bool ForStrongLayout; - /// Whether the offsets in IvarsInfo might be out-of-order. - bool IsDisordered = false; + /// Whether the offsets in IvarsInfo might be out-of-order. + bool IsDisordered = false; - llvm::SmallVector IvarsInfo; + llvm::SmallVector IvarsInfo; - public: - IvarLayoutBuilder(CodeGenModule &CGM, CharUnits instanceBegin, - CharUnits instanceEnd, bool forStrongLayout) +public: + IvarLayoutBuilder(CodeGenModule &CGM, CharUnits instanceBegin, + CharUnits instanceEnd, bool forStrongLayout) : CGM(CGM), InstanceBegin(instanceBegin), InstanceEnd(instanceEnd), - ForStrongLayout(forStrongLayout) { - } + ForStrongLayout(forStrongLayout) {} - void visitRecord(const RecordType *RT, CharUnits offset); + void visitRecord(const RecordType *RT, CharUnits offset); - template - void visitAggregate(Iterator begin, Iterator end, - CharUnits aggrOffset, - const GetOffsetFn &getOffset); + template + void visitAggregate(Iterator begin, Iterator end, CharUnits aggrOffset, + const GetOffsetFn &getOffset); - void visitField(const FieldDecl *field, CharUnits offset); + void visitField(const FieldDecl *field, CharUnits offset); - /// Add the layout of a block implementation. - void visitBlock(const CGBlockInfo &blockInfo); + /// Add the layout of a block implementation. + void visitBlock(const CGBlockInfo &blockInfo); - /// Is there any information for an interesting bitmap? - bool hasBitmapData() const { return !IvarsInfo.empty(); } + /// Is there any information for an interesting bitmap? + bool hasBitmapData() const { return !IvarsInfo.empty(); } - llvm::Constant *buildBitmap(CGObjCCommonMac &CGObjC, - llvm::SmallVectorImpl &buffer); + llvm::Constant *buildBitmap(CGObjCCommonMac &CGObjC, + llvm::SmallVectorImpl &buffer); - static void dump(ArrayRef buffer) { - const unsigned char *s = buffer.data(); - for (unsigned i = 0, e = buffer.size(); i < e; i++) - if (!(s[i] & 0xf0)) - printf("0x0%x%s", s[i], s[i] != 0 ? ", " : ""); - else - printf("0x%x%s", s[i], s[i] != 0 ? ", " : ""); - printf("\n"); - } - }; + static void dump(ArrayRef buffer) { + const unsigned char *s = buffer.data(); + for (unsigned i = 0, e = buffer.size(); i < e; i++) + if (!(s[i] & 0xf0)) + printf("0x0%x%s", s[i], s[i] != 0 ? ", " : ""); + else + printf("0x%x%s", s[i], s[i] != 0 ? ", " : ""); + printf("\n"); + } +}; } // end anonymous namespace -llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM, - const CGBlockInfo &blockInfo) { +llvm::Constant * +CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM, + const CGBlockInfo &blockInfo) { llvm::Constant *nullPtr = llvm::Constant::getNullValue(CGM.Int8PtrTy); if (CGM.getLangOpts().getGC() == LangOptions::NonGC) @@ -2378,7 +2311,8 @@ void IvarLayoutBuilder::visitBlock(const CGBlockInfo &blockInfo) { const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); // Ignore constant captures. - if (capture.isConstant()) continue; + if (capture.isConstant()) + continue; CharUnits fieldOffset = capture.getOffset(); @@ -2413,8 +2347,8 @@ void IvarLayoutBuilder::visitBlock(const CGBlockInfo &blockInfo) { /// getBlockCaptureLifetime - This routine returns life time of the captured /// block variable for the purpose of block layout meta-data generation. FQT is /// the type of the variable captured in the block. -Qualifiers::ObjCLifetime CGObjCCommonMac::getBlockCaptureLifetime(QualType FQT, - bool ByrefLayout) { +Qualifiers::ObjCLifetime +CGObjCCommonMac::getBlockCaptureLifetime(QualType FQT, bool ByrefLayout) { // If it has an ownership qualifier, we're done. if (auto lifetime = FQT.getObjCLifetime()) return lifetime; @@ -2436,26 +2370,25 @@ void CGObjCCommonMac::UpdateRunSkipBlockVars(bool IsByref, CharUnits FieldSize) { // __block variables are passed by their descriptor address. if (IsByref) - RunSkipBlockVars.push_back(RUN_SKIP(BLOCK_LAYOUT_BYREF, FieldOffset, - FieldSize)); + RunSkipBlockVars.push_back( + RUN_SKIP(BLOCK_LAYOUT_BYREF, FieldOffset, FieldSize)); else if (LifeTime == Qualifiers::OCL_Strong) - RunSkipBlockVars.push_back(RUN_SKIP(BLOCK_LAYOUT_STRONG, FieldOffset, - FieldSize)); + RunSkipBlockVars.push_back( + RUN_SKIP(BLOCK_LAYOUT_STRONG, FieldOffset, FieldSize)); else if (LifeTime == Qualifiers::OCL_Weak) - RunSkipBlockVars.push_back(RUN_SKIP(BLOCK_LAYOUT_WEAK, FieldOffset, - FieldSize)); + RunSkipBlockVars.push_back( + RUN_SKIP(BLOCK_LAYOUT_WEAK, FieldOffset, FieldSize)); else if (LifeTime == Qualifiers::OCL_ExplicitNone) - RunSkipBlockVars.push_back(RUN_SKIP(BLOCK_LAYOUT_UNRETAINED, FieldOffset, - FieldSize)); + RunSkipBlockVars.push_back( + RUN_SKIP(BLOCK_LAYOUT_UNRETAINED, FieldOffset, FieldSize)); else - RunSkipBlockVars.push_back(RUN_SKIP(BLOCK_LAYOUT_NON_OBJECT_BYTES, - FieldOffset, - FieldSize)); + RunSkipBlockVars.push_back( + RUN_SKIP(BLOCK_LAYOUT_NON_OBJECT_BYTES, FieldOffset, FieldSize)); } void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout, const RecordDecl *RD, - ArrayRef RecFields, + ArrayRef RecFields, CharUnits BytePos, bool &HasUnion, bool ByrefLayout) { bool IsUnion = (RD && RD->isUnion()); @@ -2475,7 +2408,7 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout, // although this dependency is hidden. const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); CharUnits FieldOffset = - CGM.getContext().toCharUnitsFromBits(RL.getFieldOffset(i)); + CGM.getContext().toCharUnitsFromBits(RL.getFieldOffset(i)); // Skip over unnamed or bitfields if (!Field->getIdentifier() || Field->isBitField()) { @@ -2513,13 +2446,14 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout, // Replicate layout information for each array element. Note that // one element is already done. uint64_t ElIx = 1; - for (int FirstIndex = RunSkipBlockVars.size() - 1 ;ElIx < ElCount; ElIx++) { + for (int FirstIndex = RunSkipBlockVars.size() - 1; ElIx < ElCount; + ElIx++) { CharUnits Size = CGM.getContext().getTypeSizeInChars(RT); - for (int i = OldIndex+1; i <= FirstIndex; ++i) + for (int i = OldIndex + 1; i <= FirstIndex; ++i) RunSkipBlockVars.push_back( - RUN_SKIP(RunSkipBlockVars[i].opcode, - RunSkipBlockVars[i].block_var_bytepos + Size*ElIx, - RunSkipBlockVars[i].block_var_size)); + RUN_SKIP(RunSkipBlockVars[i].opcode, + RunSkipBlockVars[i].block_var_bytepos + Size * ElIx, + RunSkipBlockVars[i].block_var_size)); } continue; } @@ -2533,10 +2467,8 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout, MaxFieldOffset = FieldOffset; } } else { - UpdateRunSkipBlockVars(false, - getBlockCaptureLifetime(FQT, ByrefLayout), - BytePos + FieldOffset, - FieldSize); + UpdateRunSkipBlockVars(false, getBlockCaptureLifetime(FQT, ByrefLayout), + BytePos + FieldOffset, FieldSize); } } @@ -2545,32 +2477,32 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout, // Last field was a bitfield. Must update the info. uint64_t BitFieldSize = LastFieldBitfieldOrUnnamed->getBitWidthValue(); unsigned UnsSize = (BitFieldSize / ByteSizeInBits) + - ((BitFieldSize % ByteSizeInBits) != 0); + ((BitFieldSize % ByteSizeInBits) != 0); CharUnits Size = CharUnits::fromQuantity(UnsSize); Size += LastBitfieldOrUnnamedOffset; - UpdateRunSkipBlockVars(false, - getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), - ByrefLayout), - BytePos + LastBitfieldOrUnnamedOffset, - Size); + UpdateRunSkipBlockVars( + false, + getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), + ByrefLayout), + BytePos + LastBitfieldOrUnnamedOffset, Size); } else { - assert(!LastFieldBitfieldOrUnnamed->getIdentifier() &&"Expected unnamed"); + assert(!LastFieldBitfieldOrUnnamed->getIdentifier() && + "Expected unnamed"); // Last field was unnamed. Must update skip info. - CharUnits FieldSize - = CGM.getContext().getTypeSizeInChars(LastFieldBitfieldOrUnnamed->getType()); - UpdateRunSkipBlockVars(false, - getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), - ByrefLayout), - BytePos + LastBitfieldOrUnnamedOffset, - FieldSize); + CharUnits FieldSize = CGM.getContext().getTypeSizeInChars( + LastFieldBitfieldOrUnnamed->getType()); + UpdateRunSkipBlockVars( + false, + getBlockCaptureLifetime(LastFieldBitfieldOrUnnamed->getType(), + ByrefLayout), + BytePos + LastBitfieldOrUnnamedOffset, FieldSize); } } if (MaxField) - UpdateRunSkipBlockVars(false, - getBlockCaptureLifetime(MaxField->getType(), ByrefLayout), - BytePos + MaxFieldOffset, - MaxUnionSize); + UpdateRunSkipBlockVars( + false, getBlockCaptureLifetime(MaxField->getType(), ByrefLayout), + BytePos + MaxFieldOffset, MaxUnionSize); } void CGObjCCommonMac::BuildRCBlockVarRecordLayout(const RecordType *RT, @@ -2578,105 +2510,104 @@ void CGObjCCommonMac::BuildRCBlockVarRecordLayout(const RecordType *RT, bool &HasUnion, bool ByrefLayout) { const RecordDecl *RD = RT->getDecl(); - SmallVector Fields(RD->fields()); + SmallVector Fields(RD->fields()); llvm::Type *Ty = CGM.getTypes().ConvertType(QualType(RT, 0)); const llvm::StructLayout *RecLayout = - CGM.getDataLayout().getStructLayout(cast(Ty)); + CGM.getDataLayout().getStructLayout(cast(Ty)); BuildRCRecordLayout(RecLayout, RD, Fields, BytePos, HasUnion, ByrefLayout); } /// InlineLayoutInstruction - This routine produce an inline instruction for the /// block variable layout if it can. If not, it returns 0. Rules are as follow: -/// If ((uintptr_t) layout) < (1 << 12), the layout is inline. In the 64bit world, -/// an inline layout of value 0x0000000000000xyz is interpreted as follows: -/// x captured object pointers of BLOCK_LAYOUT_STRONG. Followed by -/// y captured object of BLOCK_LAYOUT_BYREF. Followed by -/// z captured object of BLOCK_LAYOUT_WEAK. If any of the above is missing, zero -/// replaces it. For example, 0x00000x00 means x BLOCK_LAYOUT_STRONG and no -/// BLOCK_LAYOUT_BYREF and no BLOCK_LAYOUT_WEAK objects are captured. +/// If ((uintptr_t) layout) < (1 << 12), the layout is inline. In the 64bit +/// world, an inline layout of value 0x0000000000000xyz is interpreted as +/// follows: x captured object pointers of BLOCK_LAYOUT_STRONG. Followed by y +/// captured object of BLOCK_LAYOUT_BYREF. Followed by z captured object of +/// BLOCK_LAYOUT_WEAK. If any of the above is missing, zero replaces it. For +/// example, 0x00000x00 means x BLOCK_LAYOUT_STRONG and no BLOCK_LAYOUT_BYREF +/// and no BLOCK_LAYOUT_WEAK objects are captured. uint64_t CGObjCCommonMac::InlineLayoutInstruction( - SmallVectorImpl &Layout) { + SmallVectorImpl &Layout) { uint64_t Result = 0; if (Layout.size() <= 3) { unsigned size = Layout.size(); - unsigned strong_word_count = 0, byref_word_count=0, weak_word_count=0; + unsigned strong_word_count = 0, byref_word_count = 0, weak_word_count = 0; unsigned char inst; - enum BLOCK_LAYOUT_OPCODE opcode ; + enum BLOCK_LAYOUT_OPCODE opcode; switch (size) { - case 3: - inst = Layout[0]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_STRONG) - strong_word_count = (inst & 0xF)+1; - else - return 0; + case 3: + inst = Layout[0]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_STRONG) + strong_word_count = (inst & 0xF) + 1; + else + return 0; + inst = Layout[1]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_BYREF) + byref_word_count = (inst & 0xF) + 1; + else + return 0; + inst = Layout[2]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_WEAK) + weak_word_count = (inst & 0xF) + 1; + else + return 0; + break; + + case 2: + inst = Layout[0]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_STRONG) { + strong_word_count = (inst & 0xF) + 1; inst = Layout[1]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); if (opcode == BLOCK_LAYOUT_BYREF) - byref_word_count = (inst & 0xF)+1; + byref_word_count = (inst & 0xF) + 1; + else if (opcode == BLOCK_LAYOUT_WEAK) + weak_word_count = (inst & 0xF) + 1; else return 0; - inst = Layout[2]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); + } else if (opcode == BLOCK_LAYOUT_BYREF) { + byref_word_count = (inst & 0xF) + 1; + inst = Layout[1]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); if (opcode == BLOCK_LAYOUT_WEAK) - weak_word_count = (inst & 0xF)+1; - else - return 0; - break; - - case 2: - inst = Layout[0]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_STRONG) { - strong_word_count = (inst & 0xF)+1; - inst = Layout[1]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_BYREF) - byref_word_count = (inst & 0xF)+1; - else if (opcode == BLOCK_LAYOUT_WEAK) - weak_word_count = (inst & 0xF)+1; - else - return 0; - } - else if (opcode == BLOCK_LAYOUT_BYREF) { - byref_word_count = (inst & 0xF)+1; - inst = Layout[1]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_WEAK) - weak_word_count = (inst & 0xF)+1; - else - return 0; - } - else - return 0; - break; - - case 1: - inst = Layout[0]; - opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_STRONG) - strong_word_count = (inst & 0xF)+1; - else if (opcode == BLOCK_LAYOUT_BYREF) - byref_word_count = (inst & 0xF)+1; - else if (opcode == BLOCK_LAYOUT_WEAK) - weak_word_count = (inst & 0xF)+1; + weak_word_count = (inst & 0xF) + 1; else return 0; - break; + } else + return 0; + break; - default: + case 1: + inst = Layout[0]; + opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_STRONG) + strong_word_count = (inst & 0xF) + 1; + else if (opcode == BLOCK_LAYOUT_BYREF) + byref_word_count = (inst & 0xF) + 1; + else if (opcode == BLOCK_LAYOUT_WEAK) + weak_word_count = (inst & 0xF) + 1; + else return 0; + break; + + default: + return 0; } // Cannot inline when any of the word counts is 15. Because this is one less // than the actual work count (so 15 means 16 actual word counts), // and we can only display 0 thru 15 word counts. - if (strong_word_count == 16 || byref_word_count == 16 || weak_word_count == 16) + if (strong_word_count == 16 || byref_word_count == 16 || + weak_word_count == 16) return 0; - unsigned count = - (strong_word_count != 0) + (byref_word_count != 0) + (weak_word_count != 0); + unsigned count = (strong_word_count != 0) + (byref_word_count != 0) + + (weak_word_count != 0); if (size == count) { if (strong_word_count) @@ -2698,7 +2629,7 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) { return nullPtr; unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(LangAS::Default); unsigned ByteSizeInBits = CGM.getTarget().getCharWidth(); - unsigned WordSizeInBytes = WordSizeInBits/ByteSizeInBits; + unsigned WordSizeInBytes = WordSizeInBits / ByteSizeInBits; // Sort on byte position; captures might not be allocated in order, // and unions can do funny things. @@ -2710,21 +2641,20 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) { enum BLOCK_LAYOUT_OPCODE opcode = RunSkipBlockVars[i].opcode; CharUnits start_byte_pos = RunSkipBlockVars[i].block_var_bytepos; CharUnits end_byte_pos = start_byte_pos; - unsigned j = i+1; + unsigned j = i + 1; while (j < size) { if (opcode == RunSkipBlockVars[j].opcode) { end_byte_pos = RunSkipBlockVars[j++].block_var_bytepos; i++; - } - else + } else break; } CharUnits size_in_bytes = - end_byte_pos - start_byte_pos + RunSkipBlockVars[j-1].block_var_size; + end_byte_pos - start_byte_pos + RunSkipBlockVars[j - 1].block_var_size; if (j < size) { - CharUnits gap = - RunSkipBlockVars[j].block_var_bytepos - - RunSkipBlockVars[j-1].block_var_bytepos - RunSkipBlockVars[j-1].block_var_size; + CharUnits gap = RunSkipBlockVars[j].block_var_bytepos - + RunSkipBlockVars[j - 1].block_var_bytepos - + RunSkipBlockVars[j - 1].block_var_size; size_in_bytes += gap; } CharUnits residue_in_bytes = CharUnits::Zero(); @@ -2745,20 +2675,21 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) { if (size_in_words > 0) { // Note that value in imm. is one less that the actual // value. So, we subtract 1 away! - unsigned char inst = (opcode << 4) | (size_in_words-1); + unsigned char inst = (opcode << 4) | (size_in_words - 1); Layout.push_back(inst); } if (residue_in_bytes > CharUnits::Zero()) { - unsigned char inst = - (BLOCK_LAYOUT_NON_OBJECT_BYTES << 4) | (residue_in_bytes.getQuantity()-1); + unsigned char inst = (BLOCK_LAYOUT_NON_OBJECT_BYTES << 4) | + (residue_in_bytes.getQuantity() - 1); Layout.push_back(inst); } } while (!Layout.empty()) { unsigned char inst = Layout.back(); - enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); - if (opcode == BLOCK_LAYOUT_NON_OBJECT_BYTES || opcode == BLOCK_LAYOUT_NON_OBJECT_WORDS) + enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); + if (opcode == BLOCK_LAYOUT_NON_OBJECT_BYTES || + opcode == BLOCK_LAYOUT_NON_OBJECT_WORDS) Layout.pop_back(); else break; @@ -2774,11 +2705,11 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) { printf("\n Inline block variable layout: "); printf("0x0%" PRIx64 "", Result); if (auto numStrong = (Result & 0xF00) >> 8) - printf(", BL_STRONG:%d", (int) numStrong); + printf(", BL_STRONG:%d", (int)numStrong); if (auto numByref = (Result & 0x0F0) >> 4) - printf(", BL_BYREF:%d", (int) numByref); + printf(", BL_BYREF:%d", (int)numByref); if (auto numWeak = (Result & 0x00F) >> 0) - printf(", BL_WEAK:%d", (int) numWeak); + printf(", BL_WEAK:%d", (int)numWeak); printf(", BL_OPERATOR:0\n"); } return llvm::ConstantInt::get(CGM.IntPtrTy, Result); @@ -2797,36 +2728,36 @@ llvm::Constant *CGObjCCommonMac::getBitmapBlockLayout(bool ComputeByrefLayout) { printf("\n Block variable layout: "); for (unsigned i = 0, e = BitMap.size(); i != e; i++) { unsigned char inst = BitMap[i]; - enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE) (inst >> 4); + enum BLOCK_LAYOUT_OPCODE opcode = (enum BLOCK_LAYOUT_OPCODE)(inst >> 4); unsigned delta = 1; switch (opcode) { - case BLOCK_LAYOUT_OPERATOR: - printf("BL_OPERATOR:"); - delta = 0; - break; - case BLOCK_LAYOUT_NON_OBJECT_BYTES: - printf("BL_NON_OBJECT_BYTES:"); - break; - case BLOCK_LAYOUT_NON_OBJECT_WORDS: - printf("BL_NON_OBJECT_WORD:"); - break; - case BLOCK_LAYOUT_STRONG: - printf("BL_STRONG:"); - break; - case BLOCK_LAYOUT_BYREF: - printf("BL_BYREF:"); - break; - case BLOCK_LAYOUT_WEAK: - printf("BL_WEAK:"); - break; - case BLOCK_LAYOUT_UNRETAINED: - printf("BL_UNRETAINED:"); - break; + case BLOCK_LAYOUT_OPERATOR: + printf("BL_OPERATOR:"); + delta = 0; + break; + case BLOCK_LAYOUT_NON_OBJECT_BYTES: + printf("BL_NON_OBJECT_BYTES:"); + break; + case BLOCK_LAYOUT_NON_OBJECT_WORDS: + printf("BL_NON_OBJECT_WORD:"); + break; + case BLOCK_LAYOUT_STRONG: + printf("BL_STRONG:"); + break; + case BLOCK_LAYOUT_BYREF: + printf("BL_BYREF:"); + break; + case BLOCK_LAYOUT_WEAK: + printf("BL_WEAK:"); + break; + case BLOCK_LAYOUT_UNRETAINED: + printf("BL_UNRETAINED:"); + break; } // Actual value of word count is one more that what is in the imm. // field of the instruction printf("%d", (inst & 0xf) + delta); - if (i < e-1) + if (i < e - 1) printf(", "); else printf("\n"); @@ -2884,13 +2815,13 @@ void CGObjCCommonMac::fillRunSkipBlockVars(CodeGenModule &CGM, unsigned WordSizeInBits = CGM.getTarget().getPointerWidth(LangAS::Default); unsigned ByteSizeInBits = CGM.getTarget().getCharWidth(); - unsigned WordSizeInBytes = WordSizeInBits/ByteSizeInBits; + unsigned WordSizeInBytes = WordSizeInBits / ByteSizeInBits; const BlockDecl *blockDecl = blockInfo.getBlockDecl(); // Calculate the basic layout of the block structure. const llvm::StructLayout *layout = - CGM.getDataLayout().getStructLayout(blockInfo.StructureType); + CGM.getDataLayout().getStructLayout(blockInfo.StructureType); // Ignore the optional 'this' capture: C++ objects are not assumed // to be GC'ed. @@ -2906,10 +2837,11 @@ void CGObjCCommonMac::fillRunSkipBlockVars(CodeGenModule &CGM, const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); // Ignore constant captures. - if (capture.isConstant()) continue; + if (capture.isConstant()) + continue; CharUnits fieldOffset = - CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex())); + CharUnits::fromQuantity(layout->getElementOffset(capture.getIndex())); assert(!type->isArrayType() && "array variable should not be caught"); if (!CI.isByRef()) @@ -2948,7 +2880,8 @@ llvm::Constant *CGObjCCommonMac::BuildByrefLayout(CodeGen::CodeGenModule &CGM, RunSkipBlockVars.clear(); bool hasUnion = false; if (const RecordType *record = T->getAs()) { - BuildRCBlockVarRecordLayout(record, fieldOffset, hasUnion, true /*ByrefLayout */); + BuildRCBlockVarRecordLayout(record, fieldOffset, hasUnion, + true /*ByrefLayout */); llvm::Constant *Result = getBitmapBlockLayout(true); if (isa(Result)) Result = llvm::ConstantExpr::getIntToPtr(Result, CGM.Int8PtrTy); @@ -2986,10 +2919,10 @@ llvm::Constant *CGObjCCommonMac::GetProtocolRef(const ObjCProtocolDecl *PD) { return GetOrEmitProtocolRef(PD); } -llvm::Value *CGObjCCommonMac::EmitClassRefViaRuntime( - CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID, - ObjCCommonTypesHelper &ObjCTypes) { +llvm::Value * +CGObjCCommonMac::EmitClassRefViaRuntime(CodeGenFunction &CGF, + const ObjCInterfaceDecl *ID, + ObjCCommonTypesHelper &ObjCTypes) { llvm::FunctionCallee lookUpClassFn = ObjCTypes.getLookUpClassFn(); llvm::Value *className = CGF.CGM @@ -2997,10 +2930,8 @@ llvm::Value *CGObjCCommonMac::EmitClassRefViaRuntime( ID->getObjCRuntimeNameAsString())) .getPointer(); ASTContext &ctx = CGF.CGM.getContext(); - className = - CGF.Builder.CreateBitCast(className, - CGF.ConvertType( - ctx.getPointerType(ctx.CharTy.withConst()))); + className = CGF.Builder.CreateBitCast( + className, CGF.ConvertType(ctx.getPointerType(ctx.CharTy.withConst()))); llvm::CallInst *call = CGF.Builder.CreateCall(lookUpClassFn, className); call->setDoesNotThrow(); return call; @@ -3042,20 +2973,19 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) { values.add(GetClassName(PD->getObjCRuntimeNameAsString())); values.add(EmitProtocolList("OBJC_PROTOCOL_REFS_" + PD->getName(), PD->protocol_begin(), PD->protocol_end())); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::RequiredInstanceMethods)); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::RequiredClassMethods)); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::RequiredInstanceMethods)); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::RequiredClassMethods)); if (Entry) { // Already created, update the initializer. assert(Entry->hasPrivateLinkage()); values.finishAndSetAsInitializer(Entry); } else { - Entry = values.finishAndCreateGlobal("OBJC_PROTOCOL_" + PD->getName(), - CGM.getPointerAlign(), - /*constant*/ false, - llvm::GlobalValue::PrivateLinkage); + Entry = values.finishAndCreateGlobal( + "OBJC_PROTOCOL_" + PD->getName(), CGM.getPointerAlign(), + /*constant*/ false, llvm::GlobalValue::PrivateLinkage); Entry->setSection("__OBJC,__protocol,regular,no_dead_strip"); Protocols[PD->getIdentifier()] = Entry; @@ -3096,36 +3026,30 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) { llvm::Constant * CGObjCMac::EmitProtocolExtension(const ObjCProtocolDecl *PD, const ProtocolMethodLists &methodLists) { - auto optInstanceMethods = - methodLists.emitMethodList(this, PD, - ProtocolMethodLists::OptionalInstanceMethods); - auto optClassMethods = - methodLists.emitMethodList(this, PD, - ProtocolMethodLists::OptionalClassMethods); - - auto extendedMethodTypes = - EmitProtocolMethodTypes("OBJC_PROTOCOL_METHOD_TYPES_" + PD->getName(), - methodLists.emitExtendedTypesArray(this), - ObjCTypes); - - auto instanceProperties = - EmitPropertyList("OBJC_$_PROP_PROTO_LIST_" + PD->getName(), nullptr, PD, - ObjCTypes, false); + auto optInstanceMethods = methodLists.emitMethodList( + this, PD, ProtocolMethodLists::OptionalInstanceMethods); + auto optClassMethods = methodLists.emitMethodList( + this, PD, ProtocolMethodLists::OptionalClassMethods); + + auto extendedMethodTypes = EmitProtocolMethodTypes( + "OBJC_PROTOCOL_METHOD_TYPES_" + PD->getName(), + methodLists.emitExtendedTypesArray(this), ObjCTypes); + + auto instanceProperties = EmitPropertyList( + "OBJC_$_PROP_PROTO_LIST_" + PD->getName(), nullptr, PD, ObjCTypes, false); auto classProperties = - EmitPropertyList("OBJC_$_CLASS_PROP_PROTO_LIST_" + PD->getName(), nullptr, - PD, ObjCTypes, true); + EmitPropertyList("OBJC_$_CLASS_PROP_PROTO_LIST_" + PD->getName(), nullptr, + PD, ObjCTypes, true); // Return null if no extension bits are used. - if (optInstanceMethods->isNullValue() && - optClassMethods->isNullValue() && - extendedMethodTypes->isNullValue() && - instanceProperties->isNullValue() && + if (optInstanceMethods->isNullValue() && optClassMethods->isNullValue() && + extendedMethodTypes->isNullValue() && instanceProperties->isNullValue() && classProperties->isNullValue()) { return llvm::Constant::getNullValue(ObjCTypes.ProtocolExtensionPtrTy); } uint64_t size = - CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ProtocolExtensionTy); + CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ProtocolExtensionTy); ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(ObjCTypes.ProtocolExtensionTy); @@ -3187,11 +3111,10 @@ CGObjCMac::EmitProtocolList(Twine name, return GV; } -static void -PushProtocolProperties(llvm::SmallPtrSet &PropertySet, - SmallVectorImpl &Properties, - const ObjCProtocolDecl *Proto, - bool IsClassProperty) { +static void PushProtocolProperties( + llvm::SmallPtrSet &PropertySet, + SmallVectorImpl &Properties, + const ObjCProtocolDecl *Proto, bool IsClassProperty) { for (const auto *PD : Proto->properties()) { if (IsClassProperty != PD->isClassProperty()) continue; @@ -3216,11 +3139,9 @@ PushProtocolProperties(llvm::SmallPtrSet &PropertySet, struct _objc_property[prop_count]; }; */ -llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, - const Decl *Container, - const ObjCContainerDecl *OCD, - const ObjCCommonTypesHelper &ObjCTypes, - bool IsClassProperty) { +llvm::Constant *CGObjCCommonMac::EmitPropertyList( + Twine Name, const Decl *Container, const ObjCContainerDecl *OCD, + const ObjCCommonTypesHelper &ObjCTypes, bool IsClassProperty) { if (IsClassProperty) { // Make this entry NULL for OS X with deployment target < 10.11, for iOS // with deployment target < 9.0. @@ -3231,7 +3152,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, } SmallVector Properties; - llvm::SmallPtrSet PropertySet; + llvm::SmallPtrSet PropertySet; if (const ObjCInterfaceDecl *OID = dyn_cast(OCD)) for (const ObjCCategoryDecl *ClassExt : OID->known_extensions()) @@ -3259,8 +3180,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, if (const ObjCInterfaceDecl *OID = dyn_cast(OCD)) { for (const auto *P : OID->all_referenced_protocols()) PushProtocolProperties(PropertySet, Properties, P, IsClassProperty); - } - else if (const ObjCCategoryDecl *CD = dyn_cast(OCD)) { + } else if (const ObjCCategoryDecl *CD = dyn_cast(OCD)) { for (const auto *P : CD->protocols()) PushProtocolProperties(PropertySet, Properties, P, IsClassProperty); } @@ -3270,7 +3190,7 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, return llvm::Constant::getNullValue(ObjCTypes.PropertyListPtrTy); unsigned propertySize = - CGM.getDataLayout().getTypeAllocSize(ObjCTypes.PropertyTy); + CGM.getDataLayout().getTypeAllocSize(ObjCTypes.PropertyTy); ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(); @@ -3295,16 +3215,15 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name, return GV; } -llvm::Constant * -CGObjCCommonMac::EmitProtocolMethodTypes(Twine Name, - ArrayRef MethodTypes, - const ObjCCommonTypesHelper &ObjCTypes) { +llvm::Constant *CGObjCCommonMac::EmitProtocolMethodTypes( + Twine Name, ArrayRef MethodTypes, + const ObjCCommonTypesHelper &ObjCTypes) { // Return null for empty list. if (MethodTypes.empty()) return llvm::Constant::getNullValue(ObjCTypes.Int8PtrPtrTy); - llvm::ArrayType *AT = llvm::ArrayType::get(ObjCTypes.Int8PtrTy, - MethodTypes.size()); + llvm::ArrayType *AT = + llvm::ArrayType::get(ObjCTypes.Int8PtrTy, MethodTypes.size()); llvm::Constant *Init = llvm::ConstantArray::get(AT, MethodTypes); StringRef Section; @@ -3337,20 +3256,16 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { // @implementation so everyone else can live life under a clear blue sky. const ObjCInterfaceDecl *Interface = OCD->getClassInterface(); const ObjCCategoryDecl *Category = - Interface->FindCategoryDeclaration(OCD->getIdentifier()); + Interface->FindCategoryDeclaration(OCD->getIdentifier()); SmallString<256> ExtName; - llvm::raw_svector_ostream(ExtName) << Interface->getName() << '_' - << OCD->getName(); + llvm::raw_svector_ostream(ExtName) + << Interface->getName() << '_' << OCD->getName(); ConstantInitBuilder Builder(CGM); auto Values = Builder.beginStruct(ObjCTypes.CategoryTy); - enum { - InstanceMethods, - ClassMethods, - NumMethodLists - }; + enum { InstanceMethods, ClassMethods, NumMethodLists }; SmallVector Methods[NumMethodLists]; for (const auto *MD : OCD->methods()) { if (!MD->isDirectMethod()) @@ -3366,9 +3281,9 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { Values.add(emitMethodList(ExtName, MethodListType::CategoryClassMethods, Methods[ClassMethods])); if (Category) { - Values.add( - EmitProtocolList("OBJC_CATEGORY_PROTOCOLS_" + ExtName.str(), - Category->protocol_begin(), Category->protocol_end())); + Values.add(EmitProtocolList("OBJC_CATEGORY_PROTOCOLS_" + ExtName.str(), + Category->protocol_begin(), + Category->protocol_end())); } else { Values.addNullPointer(ObjCTypes.ProtocolListPtrTy); } @@ -3376,25 +3291,25 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { // If there is no category @interface then there can be no properties. if (Category) { - Values.add(EmitPropertyList("_OBJC_$_PROP_LIST_" + ExtName.str(), - OCD, Category, ObjCTypes, false)); - Values.add(EmitPropertyList("_OBJC_$_CLASS_PROP_LIST_" + ExtName.str(), - OCD, Category, ObjCTypes, true)); + Values.add(EmitPropertyList("_OBJC_$_PROP_LIST_" + ExtName.str(), OCD, + Category, ObjCTypes, false)); + Values.add(EmitPropertyList("_OBJC_$_CLASS_PROP_LIST_" + ExtName.str(), OCD, + Category, ObjCTypes, true)); } else { Values.addNullPointer(ObjCTypes.PropertyListPtrTy); Values.addNullPointer(ObjCTypes.PropertyListPtrTy); } - llvm::GlobalVariable *GV = - CreateMetadataVar("OBJC_CATEGORY_" + ExtName.str(), Values, - "__OBJC,__category,regular,no_dead_strip", - CGM.getPointerAlign(), true); + llvm::GlobalVariable *GV = CreateMetadataVar( + "OBJC_CATEGORY_" + ExtName.str(), Values, + "__OBJC,__category,regular,no_dead_strip", CGM.getPointerAlign(), true); DefinedCategories.push_back(GV); DefinedCategoryNames.insert(llvm::CachedHashString(ExtName)); // method definition entries must be clear for next implementation. MethodDefinitions.clear(); } +// clang-format off enum FragileClassFlags { /// Apparently: is not a meta-class. FragileABI_Class_Factory = 0x00001, @@ -3445,6 +3360,7 @@ enum NonFragileClassFlags { /// Exclusive with CompiledByARC. NonFragileABI_Class_HasMRCWeakIvars = 0x00200, }; +// clang-format on static bool hasWeakMember(QualType type) { if (type.getObjCLifetime() == Qualifiers::OCL_Weak) { @@ -3466,11 +3382,12 @@ static bool hasWeakMember(QualType type) { /// __weak ivars. static bool hasMRCWeakIvars(CodeGenModule &CGM, const ObjCImplementationDecl *ID) { - if (!CGM.getLangOpts().ObjCWeak) return false; + if (!CGM.getLangOpts().ObjCWeak) + return false; assert(CGM.getLangOpts().getGC() == LangOptions::NonGC); for (const ObjCIvarDecl *ivar = - ID->getClassInterface()->all_declared_ivar_begin(); + ID->getClassInterface()->all_declared_ivar_begin(); ivar; ivar = ivar->getNextIvar()) { if (hasWeakMember(ivar->getType())) return true; @@ -3506,7 +3423,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { std::string ClassName = ID->getNameAsString(); // FIXME: Gross ObjCInterfaceDecl *Interface = - const_cast(ID->getClassInterface()); + const_cast(ID->getClassInterface()); llvm::Constant *Protocols = EmitProtocolList("OBJC_CLASS_PROTOCOLS_" + ID->getName(), Interface->all_referenced_protocol_begin(), @@ -3523,17 +3440,13 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { Flags |= FragileABI_Class_HasMRCWeakIvars; CharUnits Size = - CGM.getContext().getASTObjCImplementationLayout(ID).getSize(); + CGM.getContext().getASTObjCImplementationLayout(ID).getSize(); // FIXME: Set CXX-structors flag. if (ID->getClassInterface()->getVisibility() == HiddenVisibility) Flags |= FragileABI_Class_Hidden; - enum { - InstanceMethods, - ClassMethods, - NumMethodLists - }; + enum { InstanceMethods, ClassMethods, NumMethodLists }; SmallVector Methods[NumMethodLists]; for (const auto *MD : ID->methods()) { if (!MD->isDirectMethod()) @@ -3599,9 +3512,10 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { MethodDefinitions.clear(); } -llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, - llvm::Constant *Protocols, - ArrayRef Methods) { +llvm::Constant * +CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, + llvm::Constant *Protocols, + ArrayRef Methods) { unsigned Flags = FragileABI_Class_Meta; unsigned Size = CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassTy); @@ -3629,16 +3543,16 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID, values.addInt(ObjCTypes.LongTy, Flags); values.addInt(ObjCTypes.LongTy, Size); values.add(EmitIvarList(ID, true)); - values.add(emitMethodList(ID->getName(), MethodListType::ClassMethods, - Methods)); + values.add( + emitMethodList(ID->getName(), MethodListType::ClassMethods, Methods)); // cache is always NULL. values.addNullPointer(ObjCTypes.CachePtrTy); values.add(Protocols); // ivar_layout for metaclass is always NULL. values.addNullPointer(ObjCTypes.Int8PtrTy); // The class extension is used to store class properties for metaclasses. - values.add(EmitClassExtension(ID, CharUnits::Zero(), false/*hasMRCWeak*/, - /*isMetaclass*/true)); + values.add(EmitClassExtension(ID, CharUnits::Zero(), false /*hasMRCWeak*/, + /*isMetaclass*/ true)); std::string Name("OBJC_METACLASS_"); Name += ID->getName(); @@ -3707,10 +3621,10 @@ llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) { struct _objc_property_list *properties; }; */ -llvm::Constant * -CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID, - CharUnits InstanceSize, bool hasMRCWeakIvars, - bool isMetaclass) { +llvm::Constant *CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID, + CharUnits InstanceSize, + bool hasMRCWeakIvars, + bool isMetaclass) { // Weak ivar layout. llvm::Constant *layout; if (isMetaclass) { @@ -3722,10 +3636,10 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID, // Properties. llvm::Constant *propertyList = - EmitPropertyList((isMetaclass ? Twine("_OBJC_$_CLASS_PROP_LIST_") - : Twine("_OBJC_$_PROP_LIST_")) - + ID->getName(), - ID, ID->getClassInterface(), ObjCTypes, isMetaclass); + EmitPropertyList((isMetaclass ? Twine("_OBJC_$_CLASS_PROP_LIST_") + : Twine("_OBJC_$_PROP_LIST_")) + + ID->getName(), + ID, ID->getClassInterface(), ObjCTypes, isMetaclass); // Return null if no extension bits are used. if (layout->isNullValue() && propertyList->isNullValue()) { @@ -3733,7 +3647,7 @@ CGObjCMac::EmitClassExtension(const ObjCImplementationDecl *ID, } uint64_t size = - CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassExtensionTy); + CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassExtensionTy); ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(ObjCTypes.ClassExtensionTy); @@ -3775,8 +3689,8 @@ llvm::Constant *CGObjCMac::EmitIvarList(const ObjCImplementationDecl *ID, auto countSlot = ivarList.addPlaceholder(); auto ivars = ivarList.beginArray(ObjCTypes.IvarTy); - for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); - IVD; IVD = IVD->getNextIvar()) { + for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); IVD; + IVD = IVD->getNextIvar()) { // Ignore unnamed bit-fields. if (!IVD->getDeclName()) continue; @@ -3852,8 +3766,9 @@ void CGObjCMac::emitMethodConstant(ConstantArrayBuilder &builder, /// int count; /// struct objc_method_description list[count]; /// }; -llvm::Constant *CGObjCMac::emitMethodList(Twine name, MethodListType MLT, - ArrayRef methods) { +llvm::Constant * +CGObjCMac::emitMethodList(Twine name, MethodListType MLT, + ArrayRef methods) { StringRef prefix; StringRef section; bool forProtocol = false; @@ -3902,9 +3817,9 @@ llvm::Constant *CGObjCMac::emitMethodList(Twine name, MethodListType MLT, // Return null for empty list. if (methods.empty()) - return llvm::Constant::getNullValue(forProtocol - ? ObjCTypes.MethodDescriptionListPtrTy - : ObjCTypes.MethodListPtrTy); + return llvm::Constant::getNullValue( + forProtocol ? ObjCTypes.MethodDescriptionListPtrTy + : ObjCTypes.MethodListPtrTy); // For protocols, this is an objc_method_description_list, which has // a slightly different structure. @@ -3952,9 +3867,8 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD, CodeGenTypes &Types = CGM.getTypes(); llvm::FunctionType *MethodTy = Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); - Method = - llvm::Function::Create(MethodTy, llvm::GlobalValue::InternalLinkage, - Name, &CGM.getModule()); + Method = llvm::Function::Create( + MethodTy, llvm::GlobalValue::InternalLinkage, Name, &CGM.getModule()); } MethodDefinitions.insert(std::make_pair(OMD, Method)); @@ -3986,7 +3900,7 @@ CGObjCCommonMac::GenerateDirectMethod(const ObjCMethodDecl *OMD, CodeGenTypes &Types = CGM.getTypes(); llvm::FunctionType *MethodTy = - Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); + Types.GetFunctionType(Types.arrangeObjCMethodDeclaration(OMD)); if (OldFn) { Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, @@ -4096,11 +4010,10 @@ void CGObjCCommonMac::GenerateDirectMethodPrologue( } } -llvm::GlobalVariable *CGObjCCommonMac::CreateMetadataVar(Twine Name, - ConstantStructBuilder &Init, - StringRef Section, - CharUnits Align, - bool AddToUsed) { +llvm::GlobalVariable * +CGObjCCommonMac::CreateMetadataVar(Twine Name, ConstantStructBuilder &Init, + StringRef Section, CharUnits Align, + bool AddToUsed) { llvm::GlobalValue::LinkageTypes LT = getLinkageTypeForObjCMetadata(CGM, Section); llvm::GlobalVariable *GV = @@ -4136,10 +4049,18 @@ CGObjCCommonMac::CreateCStringLiteral(StringRef Name, ObjCLabelType Type, bool NullTerminate) { StringRef Label; switch (Type) { - case ObjCLabelType::ClassName: Label = "OBJC_CLASS_NAME_"; break; - case ObjCLabelType::MethodVarName: Label = "OBJC_METH_VAR_NAME_"; break; - case ObjCLabelType::MethodVarType: Label = "OBJC_METH_VAR_TYPE_"; break; - case ObjCLabelType::PropertyName: Label = "OBJC_PROP_NAME_ATTR_"; break; + case ObjCLabelType::ClassName: + Label = "OBJC_CLASS_NAME_"; + break; + case ObjCLabelType::MethodVarName: + Label = "OBJC_METH_VAR_NAME_"; + break; + case ObjCLabelType::MethodVarType: + Label = "OBJC_METH_VAR_TYPE_"; + break; + case ObjCLabelType::PropertyName: + Label = "OBJC_PROP_NAME_ATTR_"; + break; } bool NonFragile = ForceNonFragileABI || isNonFragileABI(); @@ -4166,10 +4087,9 @@ CGObjCCommonMac::CreateCStringLiteral(StringRef Name, ObjCLabelType Type, llvm::Constant *Value = llvm::ConstantDataArray::getString(VMContext, Name, NullTerminate); - llvm::GlobalVariable *GV = - new llvm::GlobalVariable(CGM.getModule(), Value->getType(), - /*isConstant=*/true, - llvm::GlobalValue::PrivateLinkage, Value, Label); + llvm::GlobalVariable *GV = new llvm::GlobalVariable( + CGM.getModule(), Value->getType(), + /*isConstant=*/true, llvm::GlobalValue::PrivateLinkage, Value, Label); if (CGM.getTriple().isOSBinFormatMachO()) GV->setSection(Section); GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); @@ -4228,85 +4148,84 @@ void CGObjCMac::EmitSynchronizedStmt(CodeGenFunction &CGF, } namespace { - struct PerformFragileFinally final : EHScopeStack::Cleanup { - const Stmt &S; - Address SyncArgSlot; - Address CallTryExitVar; - Address ExceptionData; - ObjCTypesHelper &ObjCTypes; - PerformFragileFinally(const Stmt *S, - Address SyncArgSlot, - Address CallTryExitVar, - Address ExceptionData, - ObjCTypesHelper *ObjCTypes) +struct PerformFragileFinally final : EHScopeStack::Cleanup { + const Stmt &S; + Address SyncArgSlot; + Address CallTryExitVar; + Address ExceptionData; + ObjCTypesHelper &ObjCTypes; + PerformFragileFinally(const Stmt *S, Address SyncArgSlot, + Address CallTryExitVar, Address ExceptionData, + ObjCTypesHelper *ObjCTypes) : S(*S), SyncArgSlot(SyncArgSlot), CallTryExitVar(CallTryExitVar), ExceptionData(ExceptionData), ObjCTypes(*ObjCTypes) {} - void Emit(CodeGenFunction &CGF, Flags flags) override { - // Check whether we need to call objc_exception_try_exit. - // In optimized code, this branch will always be folded. - llvm::BasicBlock *FinallyCallExit = + void Emit(CodeGenFunction &CGF, Flags flags) override { + // Check whether we need to call objc_exception_try_exit. + // In optimized code, this branch will always be folded. + llvm::BasicBlock *FinallyCallExit = CGF.createBasicBlock("finally.call_exit"); - llvm::BasicBlock *FinallyNoCallExit = + llvm::BasicBlock *FinallyNoCallExit = CGF.createBasicBlock("finally.no_call_exit"); - CGF.Builder.CreateCondBr(CGF.Builder.CreateLoad(CallTryExitVar), - FinallyCallExit, FinallyNoCallExit); + CGF.Builder.CreateCondBr(CGF.Builder.CreateLoad(CallTryExitVar), + FinallyCallExit, FinallyNoCallExit); - CGF.EmitBlock(FinallyCallExit); - CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryExitFn(), - ExceptionData.emitRawPointer(CGF)); + CGF.EmitBlock(FinallyCallExit); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryExitFn(), + ExceptionData.emitRawPointer(CGF)); - CGF.EmitBlock(FinallyNoCallExit); + CGF.EmitBlock(FinallyNoCallExit); - if (isa(S)) { - if (const ObjCAtFinallyStmt* FinallyStmt = + if (isa(S)) { + if (const ObjCAtFinallyStmt *FinallyStmt = cast(S).getFinallyStmt()) { - // Don't try to do the @finally if this is an EH cleanup. - if (flags.isForEHCleanup()) return; + // Don't try to do the @finally if this is an EH cleanup. + if (flags.isForEHCleanup()) + return; - // Save the current cleanup destination in case there's - // control flow inside the finally statement. - llvm::Value *CurCleanupDest = + // Save the current cleanup destination in case there's + // control flow inside the finally statement. + llvm::Value *CurCleanupDest = CGF.Builder.CreateLoad(CGF.getNormalCleanupDestSlot()); - CGF.EmitStmt(FinallyStmt->getFinallyBody()); + CGF.EmitStmt(FinallyStmt->getFinallyBody()); - if (CGF.HaveInsertPoint()) { - CGF.Builder.CreateStore(CurCleanupDest, - CGF.getNormalCleanupDestSlot()); - } else { - // Currently, the end of the cleanup must always exist. - CGF.EnsureInsertPoint(); - } + if (CGF.HaveInsertPoint()) { + CGF.Builder.CreateStore(CurCleanupDest, + CGF.getNormalCleanupDestSlot()); + } else { + // Currently, the end of the cleanup must always exist. + CGF.EnsureInsertPoint(); } - } else { - // Emit objc_sync_exit(expr); as finally's sole statement for - // @synchronized. - llvm::Value *SyncArg = CGF.Builder.CreateLoad(SyncArgSlot); - CGF.EmitNounwindRuntimeCall(ObjCTypes.getSyncExitFn(), SyncArg); } + } else { + // Emit objc_sync_exit(expr); as finally's sole statement for + // @synchronized. + llvm::Value *SyncArg = CGF.Builder.CreateLoad(SyncArgSlot); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getSyncExitFn(), SyncArg); } - }; + } +}; - class FragileHazards { - CodeGenFunction &CGF; - SmallVector Locals; - llvm::DenseSet BlocksBeforeTry; +class FragileHazards { + CodeGenFunction &CGF; + SmallVector Locals; + llvm::DenseSet BlocksBeforeTry; - llvm::InlineAsm *ReadHazard; - llvm::InlineAsm *WriteHazard; + llvm::InlineAsm *ReadHazard; + llvm::InlineAsm *WriteHazard; - llvm::FunctionType *GetAsmFnType(); + llvm::FunctionType *GetAsmFnType(); - void collectLocals(); - void emitReadHazard(CGBuilderTy &Builder); + void collectLocals(); + void emitReadHazard(CGBuilderTy &Builder); - public: - FragileHazards(CodeGenFunction &CGF); +public: + FragileHazards(CodeGenFunction &CGF); - void emitWriteHazard(); - void emitHazardsInNewBlocks(); - }; + void emitWriteHazard(); + void emitHazardsInNewBlocks(); +}; } // end anonymous namespace /// Create the fragile-ABI read and write hazards based on the current @@ -4317,11 +4236,12 @@ namespace { FragileHazards::FragileHazards(CodeGenFunction &CGF) : CGF(CGF) { collectLocals(); - if (Locals.empty()) return; + if (Locals.empty()) + return; // Collect all the blocks in the function. - for (llvm::Function::iterator - I = CGF.CurFn->begin(), E = CGF.CurFn->end(); I != E; ++I) + for (llvm::Function::iterator I = CGF.CurFn->begin(), E = CGF.CurFn->end(); + I != E; ++I) BlocksBeforeTry.insert(&*I); llvm::FunctionType *AsmFnTy = GetAsmFnType(); @@ -4334,7 +4254,8 @@ FragileHazards::FragileHazards(CodeGenFunction &CGF) : CGF(CGF) { { std::string Constraint; for (unsigned I = 0, E = Locals.size(); I != E; ++I) { - if (I) Constraint += ','; + if (I) + Constraint += ','; Constraint += "*m"; } @@ -4348,7 +4269,8 @@ FragileHazards::FragileHazards(CodeGenFunction &CGF) : CGF(CGF) { { std::string Constraint; for (unsigned I = 0, E = Locals.size(); I != E; ++I) { - if (I) Constraint += ','; + if (I) + Constraint += ','; Constraint += "=*m"; } @@ -4358,13 +4280,16 @@ FragileHazards::FragileHazards(CodeGenFunction &CGF) : CGF(CGF) { /// Emit a write hazard at the current location. void FragileHazards::emitWriteHazard() { - if (Locals.empty()) return; + if (Locals.empty()) + return; llvm::CallInst *Call = CGF.EmitNounwindRuntimeCall(WriteHazard, Locals); for (auto Pair : llvm::enumerate(Locals)) - Call->addParamAttr(Pair.index(), llvm::Attribute::get( - CGF.getLLVMContext(), llvm::Attribute::ElementType, - cast(Pair.value())->getAllocatedType())); + Call->addParamAttr( + Pair.index(), + llvm::Attribute::get( + CGF.getLLVMContext(), llvm::Attribute::ElementType, + cast(Pair.value())->getAllocatedType())); } void FragileHazards::emitReadHazard(CGBuilderTy &Builder) { @@ -4373,27 +4298,31 @@ void FragileHazards::emitReadHazard(CGBuilderTy &Builder) { call->setDoesNotThrow(); call->setCallingConv(CGF.getRuntimeCC()); for (auto Pair : llvm::enumerate(Locals)) - call->addParamAttr(Pair.index(), llvm::Attribute::get( - Builder.getContext(), llvm::Attribute::ElementType, - cast(Pair.value())->getAllocatedType())); + call->addParamAttr( + Pair.index(), + llvm::Attribute::get( + Builder.getContext(), llvm::Attribute::ElementType, + cast(Pair.value())->getAllocatedType())); } /// Emit read hazards in all the protected blocks, i.e. all the blocks /// which have been inserted since the beginning of the try. void FragileHazards::emitHazardsInNewBlocks() { - if (Locals.empty()) return; + if (Locals.empty()) + return; CGBuilderTy Builder(CGF, CGF.getLLVMContext()); // Iterate through all blocks, skipping those prior to the try. - for (llvm::Function::iterator - FI = CGF.CurFn->begin(), FE = CGF.CurFn->end(); FI != FE; ++FI) { + for (llvm::Function::iterator FI = CGF.CurFn->begin(), FE = CGF.CurFn->end(); + FI != FE; ++FI) { llvm::BasicBlock &BB = *FI; - if (BlocksBeforeTry.count(&BB)) continue; + if (BlocksBeforeTry.count(&BB)) + continue; // Walk through all the calls in the block. - for (llvm::BasicBlock::iterator - BI = BB.begin(), BE = BB.end(); BI != BE; ++BI) { + for (llvm::BasicBlock::iterator BI = BB.begin(), BE = BB.end(); BI != BE; + ++BI) { llvm::Instruction &I = *BI; // Ignore instructions that aren't non-intrinsic calls. @@ -4419,7 +4348,7 @@ void FragileHazards::emitHazardsInNewBlocks() { } } -static void addIfPresent(llvm::DenseSet &S, Address V) { +static void addIfPresent(llvm::DenseSet &S, Address V) { if (V.isValid()) if (llvm::Value *Ptr = V.getBasePointer()) S.insert(Ptr); @@ -4427,15 +4356,15 @@ static void addIfPresent(llvm::DenseSet &S, Address V) { void FragileHazards::collectLocals() { // Compute a set of allocas to ignore. - llvm::DenseSet AllocasToIgnore; + llvm::DenseSet AllocasToIgnore; addIfPresent(AllocasToIgnore, CGF.ReturnValue); addIfPresent(AllocasToIgnore, CGF.NormalCleanupDest); // Collect all the allocas currently in the function. This is // probably way too aggressive. llvm::BasicBlock &Entry = CGF.CurFn->getEntryBlock(); - for (llvm::BasicBlock::iterator - I = Entry.begin(), E = Entry.end(); I != E; ++I) + for (llvm::BasicBlock::iterator I = Entry.begin(), E = Entry.end(); I != E; + ++I) if (isa(*I) && !AllocasToIgnore.count(&*I)) Locals.push_back(&*I); } @@ -4562,12 +4491,12 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // A destination for the fall-through edges of the catch handlers to // jump to. CodeGenFunction::JumpDest FinallyEnd = - CGF.getJumpDestInCurrentScope("finally.end"); + CGF.getJumpDestInCurrentScope("finally.end"); // A destination for the rethrow edge of the catch handlers to jump // to. CodeGenFunction::JumpDest FinallyRethrow = - CGF.getJumpDestInCurrentScope("finally.rethrow"); + CGF.getJumpDestInCurrentScope("finally.rethrow"); // For @synchronized, call objc_sync_enter(sync.expr). The // evaluation of the expression must occur before we enter the @@ -4577,7 +4506,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, Address SyncArgSlot = Address::invalid(); if (!isTry) { llvm::Value *SyncArg = - CGF.EmitScalarExpr(cast(S).getSynchExpr()); + CGF.EmitScalarExpr(cast(S).getSynchExpr()); SyncArg = CGF.Builder.CreateBitCast(SyncArg, ObjCTypes.ObjectPtrTy); CGF.EmitNounwindRuntimeCall(ObjCTypes.getSyncEnterFn(), SyncArg); @@ -4588,9 +4517,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // Allocate memory for the setjmp buffer. This needs to be kept // live throughout the try and catch blocks. - Address ExceptionData = CGF.CreateTempAlloca(ObjCTypes.ExceptionDataTy, - CGF.getPointerAlign(), - "exceptiondata.ptr"); + Address ExceptionData = CGF.CreateTempAlloca( + ObjCTypes.ExceptionDataTy, CGF.getPointerAlign(), "exceptiondata.ptr"); // Create the fragile hazards. Note that this will not capture any // of the allocas required for exception processing, but will @@ -4606,9 +4534,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // The setjmp-safety rule here is that we should always store to this // variable in a place that dominates the branch through the cleanup // without passing through any setjmps. - Address CallTryExitVar = CGF.CreateTempAlloca(CGF.Builder.getInt1Ty(), - CharUnits::One(), - "_call_try_exit"); + Address CallTryExitVar = CGF.CreateTempAlloca( + CGF.Builder.getInt1Ty(), CharUnits::One(), "_call_try_exit"); // A slot containing the exception to rethrow. Only needed when we // have both a @catch and a @finally. @@ -4616,10 +4543,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // Push a normal cleanup to leave the try scope. CGF.EHStack.pushCleanup(NormalAndEHCleanup, &S, - SyncArgSlot, - CallTryExitVar, - ExceptionData, - &ObjCTypes); + SyncArgSlot, CallTryExitVar, + ExceptionData, &ObjCTypes); // Enter a try block: // - Call objc_exception_try_enter to push ExceptionData on top of @@ -4629,7 +4554,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // - Call setjmp on the exception data buffer. llvm::Constant *Zero = llvm::ConstantInt::get(CGF.Builder.getInt32Ty(), 0); - llvm::Value *GEPIndexes[] = { Zero, Zero, Zero }; + llvm::Value *GEPIndexes[] = {Zero, Zero, Zero}; llvm::Value *SetJmpBuffer = CGF.Builder.CreateGEP( ObjCTypes.ExceptionDataTy, ExceptionData.emitRawPointer(CGF), GEPIndexes, "setjmp_buffer"); @@ -4642,7 +4567,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, llvm::BasicBlock *TryBlock = CGF.createBasicBlock("try"); llvm::BasicBlock *TryHandler = CGF.createBasicBlock("try.handler"); llvm::Value *DidCatch = - CGF.Builder.CreateIsNotNull(SetJmpResult, "did_catch_exception"); + CGF.Builder.CreateIsNotNull(SetJmpResult, "did_catch_exception"); CGF.Builder.CreateCondBr(DidCatch, TryHandler, TryBlock); // Emit the protected block. @@ -4678,7 +4603,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // benefit of any @throws in the handlers. CGF.ObjCEHValueStack.push_back(Caught); - const ObjCAtTryStmt* AtTryStmt = cast(&S); + const ObjCAtTryStmt *AtTryStmt = cast(&S); bool HasFinally = (AtTryStmt->getFinallyStmt() != nullptr); @@ -4687,9 +4612,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, if (HasFinally) { // Save the currently-propagating exception before // objc_exception_try_enter clears the exception slot. - PropagatingExnVar = CGF.CreateTempAlloca(Caught->getType(), - CGF.getPointerAlign(), - "propagating_exception"); + PropagatingExnVar = CGF.CreateTempAlloca( + Caught->getType(), CGF.getPointerAlign(), "propagating_exception"); CGF.Builder.CreateStore(Caught, PropagatingExnVar); // Enter a new exception try block (in case a @catch block @@ -4697,13 +4621,12 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryEnterFn(), ExceptionData.emitRawPointer(CGF)); - llvm::CallInst *SetJmpResult = - CGF.EmitNounwindRuntimeCall(ObjCTypes.getSetJmpFn(), - SetJmpBuffer, "setjmp.result"); + llvm::CallInst *SetJmpResult = CGF.EmitNounwindRuntimeCall( + ObjCTypes.getSetJmpFn(), SetJmpBuffer, "setjmp.result"); SetJmpResult->setCanReturnTwice(); llvm::Value *Threw = - CGF.Builder.CreateIsNotNull(SetJmpResult, "did_catch_exception"); + CGF.Builder.CreateIsNotNull(SetJmpResult, "did_catch_exception"); CatchBlock = CGF.createBasicBlock("catch"); CatchHandler = CGF.createBasicBlock("catch_for_catch"); @@ -4767,10 +4690,9 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // Check if the @catch block matches the exception object. llvm::Value *Class = EmitClassRef(CGF, IDecl); - llvm::Value *matchArgs[] = { Class, Caught }; - llvm::CallInst *Match = - CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionMatchFn(), - matchArgs, "match"); + llvm::Value *matchArgs[] = {Class, Caught}; + llvm::CallInst *Match = CGF.EmitNounwindRuntimeCall( + ObjCTypes.getExceptionMatchFn(), matchArgs, "match"); llvm::BasicBlock *MatchedBlock = CGF.createBasicBlock("match"); llvm::BasicBlock *NextCatchBlock = CGF.createBasicBlock("catch.next"); @@ -4789,9 +4711,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, assert(CGF.HaveInsertPoint() && "DeclStmt destroyed insert point?"); // Initialize the catch variable. - llvm::Value *Tmp = - CGF.Builder.CreateBitCast(Caught, - CGF.ConvertType(CatchParam->getType())); + llvm::Value *Tmp = CGF.Builder.CreateBitCast( + Caught, CGF.ConvertType(CatchParam->getType())); EmitInitOfCatchParam(CGF, Tmp, CatchParam); CGF.EmitStmt(CatchStmt->getCatchBody()); @@ -4821,7 +4742,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, // In theory we might now need a write hazard, but actually it's // unnecessary because there's no local-accessing code between // the try's write hazard and here. - //Hazards.emitWriteHazard(); + // Hazards.emitWriteHazard(); // Extract the new exception and save it to the // propagating-exception slot. @@ -4879,7 +4800,7 @@ void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF, if (const Expr *ThrowExpr = S.getThrowExpr()) { llvm::Value *Exception = CGF.EmitObjCThrowOperand(ThrowExpr); ExceptionAsObject = - CGF.Builder.CreateBitCast(Exception, ObjCTypes.ObjectPtrTy); + CGF.Builder.CreateBitCast(Exception, ObjCTypes.ObjectPtrTy); } else { assert((!CGF.ObjCEHValueStack.empty() && CGF.ObjCEHValueStack.back()) && "Unexpected rethrow outside @catch block."); @@ -4887,7 +4808,7 @@ void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF, } CGF.EmitRuntimeCall(ObjCTypes.getExceptionThrowFn(), ExceptionAsObject) - ->setDoesNotReturn(); + ->setDoesNotReturn(); CGF.Builder.CreateUnreachable(); // Clear the insertion point to indicate we are in unreachable code. @@ -4898,14 +4819,13 @@ void CGObjCMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF, /// EmitObjCWeakRead - Code gen for loading value of a __weak /// object: objc_read_weak (id *src) /// -llvm::Value * CGObjCMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, - Address AddrWeakObj) { - llvm::Type* DestTy = AddrWeakObj.getElementType(); +llvm::Value *CGObjCMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, + Address AddrWeakObj) { + llvm::Type *DestTy = AddrWeakObj.getElementType(); llvm::Value *AddrWeakObjVal = CGF.Builder.CreateBitCast( AddrWeakObj.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); - llvm::Value *read_weak = - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcReadWeakFn(), - AddrWeakObjVal, "weakread"); + llvm::Value *read_weak = CGF.EmitNounwindRuntimeCall( + ObjCTypes.getGcReadWeakFn(), AddrWeakObjVal, "weakread"); read_weak = CGF.Builder.CreateBitCast(read_weak, DestTy); return read_weak; } @@ -4915,7 +4835,7 @@ llvm::Value * CGObjCMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, /// void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst) { - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); @@ -4926,9 +4846,9 @@ void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); - llvm::Value *args[] = { src, dstVal }; - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(), - args, "weakassign"); + llvm::Value *args[] = {src, dstVal}; + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(), args, + "weakassign"); } /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object. @@ -4937,7 +4857,7 @@ void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, void CGObjCMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst, bool threadlocal) { - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); @@ -4950,11 +4870,11 @@ void CGObjCMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, ObjCTypes.PtrObjectPtrTy); llvm::Value *args[] = {src, dstVal}; if (!threadlocal) - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(), - args, "globalassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(), args, + "globalassign"); else - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignThreadLocalFn(), - args, "threadlocalassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignThreadLocalFn(), args, + "threadlocalassign"); } /// EmitObjCIvarAssign - Code gen for assigning to a __strong object. @@ -4964,7 +4884,7 @@ void CGObjCMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst, llvm::Value *ivarOffset) { assert(ivarOffset && "EmitObjCIvarAssign - ivarOffset is NULL"); - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); @@ -4984,7 +4904,7 @@ void CGObjCMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, /// void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst) { - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); @@ -4996,8 +4916,8 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); llvm::Value *args[] = {src, dstVal}; - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(), - args, "strongassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(), args, + "strongassign"); } void CGObjCMac::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, @@ -5016,7 +4936,7 @@ LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers) { const ObjCInterfaceDecl *ID = - ObjectTy->castAs()->getInterface(); + ObjectTy->castAs()->getInterface(); return EmitValueForIvarAtOffset(CGF, ID, BaseValue, Ivar, CVRQualifiers, EmitIvarOffset(CGF, ID, Ivar)); } @@ -5026,8 +4946,7 @@ llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const ObjCIvarDecl *Ivar) { uint64_t Offset = ComputeIvarBaseOffset(CGM, Interface, Ivar); return llvm::ConstantInt::get( - CGM.getTypes().ConvertType(CGM.getContext().LongTy), - Offset); + CGM.getTypes().ConvertType(CGM.getContext().LongTy), Offset); } /* *** Private Interface *** */ @@ -5060,6 +4979,7 @@ std::string CGObjCCommonMac::GetSectionName(StringRef Section, llvm_unreachable("Unhandled llvm::Triple::ObjectFormatType enum"); } +// clang-format off /// EmitImageInfo - Emit the image info marker used to encode some module /// level information. /// @@ -5081,6 +5001,7 @@ enum ImageInfoFlags { eImageInfo_ImageIsSimulated = (1 << 5), eImageInfo_ClassProperties = (1 << 6) }; +// clang-format on void CGObjCCommonMac::EmitImageInfo() { unsigned version = 0; // Version is unused? @@ -5103,15 +5024,13 @@ void CGObjCCommonMac::EmitImageInfo() { auto Int8Ty = llvm::Type::getInt8Ty(VMContext); if (CGM.getLangOpts().getGC() == LangOptions::NonGC) { // Non-GC overrides those files which specify GC. - Mod.addModuleFlag(llvm::Module::Error, - "Objective-C Garbage Collection", - llvm::ConstantInt::get(Int8Ty,0)); + Mod.addModuleFlag(llvm::Module::Error, "Objective-C Garbage Collection", + llvm::ConstantInt::get(Int8Ty, 0)); } else { // Add the ObjC garbage collection value. - Mod.addModuleFlag(llvm::Module::Error, - "Objective-C Garbage Collection", - llvm::ConstantInt::get(Int8Ty, - (uint8_t)eImageInfo_GarbageCollected)); + Mod.addModuleFlag( + llvm::Module::Error, "Objective-C Garbage Collection", + llvm::ConstantInt::get(Int8Ty, (uint8_t)eImageInfo_GarbageCollected)); if (CGM.getLangOpts().getGC() == LangOptions::GCOnly) { // Add the ObjC GC Only value. @@ -5121,8 +5040,8 @@ void CGObjCCommonMac::EmitImageInfo() { // Require that GC be specified and set to eImageInfo_GarbageCollected. llvm::Metadata *Ops[2] = { llvm::MDString::get(VMContext, "Objective-C Garbage Collection"), - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( - Int8Ty, eImageInfo_GarbageCollected))}; + llvm::ConstantAsMetadata::get( + llvm::ConstantInt::get(Int8Ty, eImageInfo_GarbageCollected))}; Mod.addModuleFlag(llvm::Module::Require, "Objective-C GC Only", llvm::MDNode::get(VMContext, Ops)); } @@ -5181,7 +5100,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { // The runtime expects exactly the list of defined classes followed // by the list of defined categories, in a single array. auto array = values.beginArray(ObjCTypes.Int8PtrTy); - for (unsigned i=0; igetImplementation()) @@ -5191,7 +5110,7 @@ llvm::Constant *CGObjCMac::EmitModuleSymbols() { array.add(DefinedClasses[i]); } - for (unsigned i=0; igetDecl(); // If this is a union, remember that we had one, because it might mess @@ -5284,11 +5203,12 @@ void IvarLayoutBuilder::visitRecord(const RecordType *RT, const ASTRecordLayout *recLayout = nullptr; visitAggregate(RD->field_begin(), RD->field_end(), offset, [&](const FieldDecl *field) -> CharUnits { - if (!recLayout) - recLayout = &CGM.getContext().getASTRecordLayout(RD); - auto offsetInBits = recLayout->getFieldOffset(field->getFieldIndex()); - return CGM.getContext().toCharUnitsFromBits(offsetInBits); - }); + if (!recLayout) + recLayout = &CGM.getContext().getASTRecordLayout(RD); + auto offsetInBits = + recLayout->getFieldOffset(field->getFieldIndex()); + return CGM.getContext().toCharUnitsFromBits(offsetInBits); + }); } template @@ -5331,7 +5251,8 @@ void IvarLayoutBuilder::visitField(const FieldDecl *field, // If we ended up with a zero-sized array, we've done what we can do within // the limits of this layout encoding. - if (numElts == 0) return; + if (numElts == 0) + return; // Recurse if the base element type is a record type. if (auto recType = fieldType->getAs()) { @@ -5361,10 +5282,10 @@ void IvarLayoutBuilder::visitField(const FieldDecl *field, Qualifiers::GC GCAttr = GetGCAttrTypeForType(CGM.getContext(), fieldType); // If it matches what we're looking for, add an entry. - if ((ForStrongLayout && GCAttr == Qualifiers::Strong) - || (!ForStrongLayout && GCAttr == Qualifiers::Weak)) { - assert(CGM.getContext().getTypeSizeInChars(fieldType) - == CGM.getPointerSize()); + if ((ForStrongLayout && GCAttr == Qualifiers::Strong) || + (!ForStrongLayout && GCAttr == Qualifiers::Weak)) { + assert(CGM.getContext().getTypeSizeInChars(fieldType) == + CGM.getPointerSize()); IvarsInfo.push_back(IvarInfo(fieldOffset, numElts)); } } @@ -5372,8 +5293,9 @@ void IvarLayoutBuilder::visitField(const FieldDecl *field, /// buildBitmap - This routine does the horsework of taking the offsets of /// strong/weak references and creating a bitmap. The bitmap is also /// returned in the given buffer, suitable for being passed to \c dump(). -llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, - llvm::SmallVectorImpl &buffer) { +llvm::Constant * +IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, + llvm::SmallVectorImpl &buffer) { // The bitmap is a series of skip/scan instructions, aligned to word // boundaries. The skip is performed first. const unsigned char MaxNibble = 0xF; @@ -5454,7 +5376,8 @@ llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, // Ignore scan requests that don't start at an even multiple of the // word size. We can't encode them. - if ((beginOfScan % WordSize) != 0) continue; + if ((beginOfScan % WordSize) != 0) + continue; // Ignore scan requests that start before the instance start. // This assumes that scans never span that boundary. The boundary @@ -5479,7 +5402,8 @@ llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, beginOfScanInWords = endOfLastScanInWords; // If that leaves us with nothing to scan, ignore this request. - if (beginOfScanInWords >= endOfScanInWords) continue; + if (beginOfScanInWords >= endOfScanInWords) + continue; } // Scan to the end of the request. @@ -5496,7 +5420,7 @@ llvm::Constant *IvarLayoutBuilder::buildBitmap(CGObjCCommonMac &CGObjC, // or necessary for the ARC-style layout strings. if (CGM.getLangOpts().getGC() != LangOptions::NonGC) { unsigned lastOffsetInWords = - (InstanceEnd - InstanceBegin + WordSize - CharUnits::One()) / WordSize; + (InstanceEnd - InstanceBegin + WordSize - CharUnits::One()) / WordSize; if (lastOffsetInWords > endOfLastScanInWords) { skip(lastOffsetInWords - endOfLastScanInWords); } @@ -5539,7 +5463,7 @@ CGObjCCommonMac::BuildIvarLayout(const ObjCImplementationDecl *OMD, return llvm::Constant::getNullValue(PtrTy); const ObjCInterfaceDecl *OI = OMD->getClassInterface(); - SmallVector ivars; + SmallVector ivars; // GC layout strings include the complete object layout, possibly // inaccurately in the non-fragile ABI; the runtime knows how to fix this @@ -5553,22 +5477,21 @@ CGObjCCommonMac::BuildIvarLayout(const ObjCImplementationDecl *OMD, // MRC weak layout strings follow the ARC style. CharUnits baseOffset; if (CGM.getLangOpts().getGC() == LangOptions::NonGC) { - for (const ObjCIvarDecl *IVD = OI->all_declared_ivar_begin(); - IVD; IVD = IVD->getNextIvar()) + for (const ObjCIvarDecl *IVD = OI->all_declared_ivar_begin(); IVD; + IVD = IVD->getNextIvar()) ivars.push_back(IVD); if (isNonFragileABI()) { baseOffset = beginOffset; // InstanceStart } else if (!ivars.empty()) { baseOffset = - CharUnits::fromQuantity(ComputeIvarBaseOffset(CGM, OMD, ivars[0])); + CharUnits::fromQuantity(ComputeIvarBaseOffset(CGM, OMD, ivars[0])); } else { baseOffset = CharUnits::Zero(); } baseOffset = baseOffset.alignTo(CGM.getPointerAlign()); - } - else { + } else { CGM.getContext().DeepCollectObjCIvars(OI, true, ivars); baseOffset = CharUnits::Zero(); @@ -5581,8 +5504,9 @@ CGObjCCommonMac::BuildIvarLayout(const ObjCImplementationDecl *OMD, builder.visitAggregate(ivars.begin(), ivars.end(), CharUnits::Zero(), [&](const ObjCIvarDecl *ivar) -> CharUnits { - return CharUnits::fromQuantity(ComputeIvarBaseOffset(CGM, OMD, ivar)); - }); + return CharUnits::fromQuantity( + ComputeIvarBaseOffset(CGM, OMD, ivar)); + }); if (!builder.hasBitmapData()) return llvm::Constant::getNullValue(PtrTy); @@ -5590,7 +5514,7 @@ CGObjCCommonMac::BuildIvarLayout(const ObjCImplementationDecl *OMD, llvm::SmallVector buffer; llvm::Constant *C = builder.buildBitmap(*this, buffer); - if (CGM.getLangOpts().ObjCGCBitmapPrint && !buffer.empty()) { + if (CGM.getLangOpts().ObjCGCBitmapPrint && !buffer.empty()) { printf("\n%s ivar layout for class '%s': ", ForStrongLayout ? "strong" : "weak", OMD->getClassInterface()->getName().str().c_str()); @@ -5603,7 +5527,8 @@ llvm::Constant *CGObjCCommonMac::GetMethodVarName(Selector Sel) { llvm::GlobalVariable *&Entry = MethodVarNames[Sel]; // FIXME: Avoid std::string in "Sel.getAsString()" if (!Entry) - Entry = CreateCStringLiteral(Sel.getAsString(), ObjCLabelType::MethodVarName); + Entry = + CreateCStringLiteral(Sel.getAsString(), ObjCLabelType::MethodVarName); return getConstantGEP(VMContext, Entry, 0, 0); } @@ -5625,7 +5550,7 @@ llvm::Constant *CGObjCCommonMac::GetMethodVarType(const FieldDecl *Field) { llvm::Constant *CGObjCCommonMac::GetMethodVarType(const ObjCMethodDecl *D, bool Extended) { std::string TypeStr = - CGM.getContext().getObjCEncodingForMethodDecl(D, Extended); + CGM.getContext().getObjCEncodingForMethodDecl(D, Extended); llvm::GlobalVariable *&Entry = MethodVarTypes[TypeStr]; if (!Entry) @@ -5647,7 +5572,7 @@ llvm::Constant * CGObjCCommonMac::GetPropertyTypeString(const ObjCPropertyDecl *PD, const Decl *Container) { std::string TypeStr = - CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container); + CGM.getContext().getObjCEncodingForPropertyDecl(PD, Container); return GetPropertyName(&CGM.getContext().Idents.get(TypeStr)); } @@ -5707,8 +5632,8 @@ CGObjCNonFragileABIMac::CGObjCNonFragileABIMac(CodeGen::CodeGenModule &cgm) /* *** */ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm) - : VMContext(cgm.getLLVMContext()), CGM(cgm), ExternalProtocolPtrTy(nullptr) -{ + : VMContext(cgm.getLLVMContext()), CGM(cgm), + ExternalProtocolPtrTy(nullptr) { CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace(); @@ -5727,12 +5652,10 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm) else IvarOffsetVarTy = LongTy; - ObjectPtrTy = - cast(Types.ConvertType(Ctx.getObjCIdType())); - PtrObjectPtrTy = - llvm::PointerType::getUnqual(ObjectPtrTy); + ObjectPtrTy = cast(Types.ConvertType(Ctx.getObjCIdType())); + PtrObjectPtrTy = llvm::PointerType::getUnqual(ObjectPtrTy); SelectorPtrTy = - cast(Types.ConvertType(Ctx.getObjCSelType())); + cast(Types.ConvertType(Ctx.getObjCSelType())); // I'm not sure I like this. The implicit coordination is a bit // gross. We should solve this in a reasonable fashion because this @@ -5793,7 +5716,7 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm) } ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) - : ObjCCommonTypesHelper(cgm) { + : ObjCCommonTypesHelper(cgm) { // struct _objc_method_description { // SEL name; // char *types; @@ -5811,7 +5734,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) // struct _objc_method_description_list * MethodDescriptionListPtrTy = - llvm::PointerType::getUnqual(MethodDescriptionListTy); + llvm::PointerType::getUnqual(MethodDescriptionListTy); // Protocol description structures @@ -5867,13 +5790,12 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) IntTy); // struct _objc_ivar_list * - IvarListTy = - llvm::StructType::create(VMContext, "struct._objc_ivar_list"); + IvarListTy = llvm::StructType::create(VMContext, "struct._objc_ivar_list"); IvarListPtrTy = llvm::PointerType::getUnqual(IvarListTy); // struct _objc_method_list * MethodListTy = - llvm::StructType::create(VMContext, "struct._objc_method_list"); + llvm::StructType::create(VMContext, "struct._objc_method_list"); MethodListPtrTy = llvm::PointerType::getUnqual(MethodListTy); // struct _objc_class_extension * @@ -5954,8 +5876,9 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm) llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy); } -ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule &cgm) - : ObjCCommonTypesHelper(cgm) { +ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper( + CodeGen::CodeGenModule &cgm) + : ObjCCommonTypesHelper(cgm) { // struct _method_list_t { // uint32_t entsize; // sizeof(struct _objc_method) // uint32_t method_count; @@ -6122,7 +6045,6 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul // SuperMessageRefPtrTy - LLVM for struct _super_message_ref_t* SuperMessageRefPtrTy = llvm::PointerType::getUnqual(SuperMessageRefTy); - // struct objc_typeinfo { // const void** vtable; // objc_ehtype_vtable + 2 // const char* name; // c++ typeinfo string @@ -6148,14 +6070,12 @@ void CGObjCNonFragileABIMac::AddModuleClassList( if (!NumClasses) return; - SmallVector Symbols(NumClasses); - for (unsigned i=0; i Symbols(NumClasses); + for (unsigned i = 0; i < NumClasses; i++) Symbols[i] = Container[i]; - llvm::Constant *Init = - llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.Int8PtrTy, - Symbols.size()), - Symbols); + llvm::Constant *Init = llvm::ConstantArray::get( + llvm::ArrayType::get(ObjCTypes.Int8PtrTy, Symbols.size()), Symbols); // Section name is obtained by calling GetSectionName, which returns // sections in the __DATA segment on MachO. @@ -6176,36 +6096,37 @@ void CGObjCNonFragileABIMac::FinishNonFragileABIModule() { // Build list of all implemented class addresses in array // L_OBJC_LABEL_CLASS_$. - for (unsigned i=0, NumClasses=ImplementedClasses.size(); igetImplementation()) // We are implementing a weak imported interface. Give it external linkage if (ID->isWeakImported() && !IMP->isWeakImported()) { DefinedClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage); - DefinedMetaClasses[i]->setLinkage(llvm::GlobalVariable::ExternalLinkage); + DefinedMetaClasses[i]->setLinkage( + llvm::GlobalVariable::ExternalLinkage); } } - AddModuleClassList(DefinedClasses, "OBJC_LABEL_CLASS_$", - GetSectionName("__objc_classlist", - "regular,no_dead_strip")); + AddModuleClassList( + DefinedClasses, "OBJC_LABEL_CLASS_$", + GetSectionName("__objc_classlist", "regular,no_dead_strip")); - AddModuleClassList(DefinedNonLazyClasses, "OBJC_LABEL_NONLAZY_CLASS_$", - GetSectionName("__objc_nlclslist", - "regular,no_dead_strip")); + AddModuleClassList( + DefinedNonLazyClasses, "OBJC_LABEL_NONLAZY_CLASS_$", + GetSectionName("__objc_nlclslist", "regular,no_dead_strip")); // Build list of all implemented category addresses in array // L_OBJC_LABEL_CATEGORY_$. AddModuleClassList(DefinedCategories, "OBJC_LABEL_CATEGORY_$", - GetSectionName("__objc_catlist", - "regular,no_dead_strip")); - AddModuleClassList(DefinedStubCategories, "OBJC_LABEL_STUB_CATEGORY_$", - GetSectionName("__objc_catlist2", - "regular,no_dead_strip")); - AddModuleClassList(DefinedNonLazyCategories, "OBJC_LABEL_NONLAZY_CATEGORY_$", - GetSectionName("__objc_nlcatlist", - "regular,no_dead_strip")); + GetSectionName("__objc_catlist", "regular,no_dead_strip")); + AddModuleClassList( + DefinedStubCategories, "OBJC_LABEL_STUB_CATEGORY_$", + GetSectionName("__objc_catlist2", "regular,no_dead_strip")); + AddModuleClassList( + DefinedNonLazyCategories, "OBJC_LABEL_NONLAZY_CATEGORY_$", + GetSectionName("__objc_nlcatlist", "regular,no_dead_strip")); EmitImageInfo(); } @@ -6264,7 +6185,7 @@ bool CGObjCNonFragileABIMac::isVTableDispatchedSelector(Selector Sel) { &CGM.getContext().Idents.get("objects"), &CGM.getContext().Idents.get("count")}; VTableDispatchMethods.insert( - CGM.getContext().Selectors.getSelector(3, KeyIdents)); + CGM.getContext().Selectors.getSelector(3, KeyIdents)); } } @@ -6286,11 +6207,9 @@ bool CGObjCNonFragileABIMac::isVTableDispatchedSelector(Selector Sel) { /// const struct _prop_list_t * const properties; /// } /// -llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( - unsigned flags, - unsigned InstanceStart, - unsigned InstanceSize, - const ObjCImplementationDecl *ID) { +llvm::GlobalVariable *CGObjCNonFragileABIMac::BuildClassRoTInitializer( + unsigned flags, unsigned InstanceStart, unsigned InstanceSize, + const ObjCImplementationDecl *ID) { std::string ClassName = std::string(ID->getObjCRuntimeNameAsString()); CharUnits beginInstance = CharUnits::fromQuantity(InstanceStart); @@ -6309,12 +6228,12 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( values.addInt(ObjCTypes.IntTy, InstanceStart); values.addInt(ObjCTypes.IntTy, InstanceSize); values.add((flags & NonFragileABI_Class_Meta) - ? GetIvarLayoutName(nullptr, ObjCTypes) - : BuildStrongIvarLayout(ID, beginInstance, endInstance)); + ? GetIvarLayoutName(nullptr, ObjCTypes) + : BuildStrongIvarLayout(ID, beginInstance, endInstance)); values.add(GetClassName(ID->getObjCRuntimeNameAsString())); // const struct _method_list_t * const baseMethods; - SmallVector methods; + SmallVector methods; if (flags & NonFragileABI_Class_Meta) { for (const auto *MD : ID->class_methods()) if (!MD->isDirectMethod()) @@ -6327,29 +6246,29 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( values.add(emitMethodList(ID->getObjCRuntimeNameAsString(), (flags & NonFragileABI_Class_Meta) - ? MethodListType::ClassMethods - : MethodListType::InstanceMethods, + ? MethodListType::ClassMethods + : MethodListType::InstanceMethods, methods)); const ObjCInterfaceDecl *OID = ID->getClassInterface(); assert(OID && "CGObjCNonFragileABIMac::BuildClassRoTInitializer"); - values.add(EmitProtocolList("_OBJC_CLASS_PROTOCOLS_$_" - + OID->getObjCRuntimeNameAsString(), + values.add(EmitProtocolList("_OBJC_CLASS_PROTOCOLS_$_" + + OID->getObjCRuntimeNameAsString(), OID->all_referenced_protocol_begin(), OID->all_referenced_protocol_end())); if (flags & NonFragileABI_Class_Meta) { values.addNullPointer(ObjCTypes.IvarListnfABIPtrTy); values.add(GetIvarLayoutName(nullptr, ObjCTypes)); - values.add(EmitPropertyList( - "_OBJC_$_CLASS_PROP_LIST_" + ID->getObjCRuntimeNameAsString(), - ID, ID->getClassInterface(), ObjCTypes, true)); + values.add(EmitPropertyList("_OBJC_$_CLASS_PROP_LIST_" + + ID->getObjCRuntimeNameAsString(), + ID, ID->getClassInterface(), ObjCTypes, true)); } else { values.add(EmitIvarList(ID)); values.add(BuildWeakIvarLayout(ID, beginInstance, endInstance, hasMRCWeak)); - values.add(EmitPropertyList( - "_OBJC_$_PROP_LIST_" + ID->getObjCRuntimeNameAsString(), - ID, ID->getClassInterface(), ObjCTypes, false)); + values.add(EmitPropertyList("_OBJC_$_PROP_LIST_" + + ID->getObjCRuntimeNameAsString(), + ID, ID->getClassInterface(), ObjCTypes, false)); } llvm::SmallString<64> roLabel; @@ -6371,13 +6290,10 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer( /// struct class_ro_t *ro; /// } /// -llvm::GlobalVariable * -CGObjCNonFragileABIMac::BuildClassObject(const ObjCInterfaceDecl *CI, - bool isMetaclass, - llvm::Constant *IsAGV, - llvm::Constant *SuperClassGV, - llvm::Constant *ClassRoGV, - bool HiddenVisibility) { +llvm::GlobalVariable *CGObjCNonFragileABIMac::BuildClassObject( + const ObjCInterfaceDecl *CI, bool isMetaclass, llvm::Constant *IsAGV, + llvm::Constant *SuperClassGV, llvm::Constant *ClassRoGV, + bool HiddenVisibility) { ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(ObjCTypes.ClassnfABITy); values.add(IsAGV); @@ -6390,8 +6306,8 @@ CGObjCNonFragileABIMac::BuildClassObject(const ObjCInterfaceDecl *CI, values.add(ObjCEmptyVtableVar); values.add(ClassRoGV); - llvm::GlobalVariable *GV = - cast(GetClassGlobal(CI, isMetaclass, ForDefinition)); + llvm::GlobalVariable *GV = cast( + GetClassGlobal(CI, isMetaclass, ForDefinition)); values.finishAndSetAsInitializer(GV); if (CGM.getTriple().isOSBinFormatMachO()) @@ -6414,7 +6330,7 @@ void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID, uint32_t &InstanceStart, uint32_t &InstanceSize) { const ASTRecordLayout &RL = - CGM.getContext().getASTObjCImplementationLayout(OID); + CGM.getContext().getASTObjCImplementationLayout(OID); // InstanceSize is really instance end. InstanceSize = RL.getDataSize().getQuantity(); @@ -6448,27 +6364,26 @@ static llvm::GlobalValue::DLLStorageClassTypes getStorage(CodeGenModule &CGM, void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { if (!ObjCEmptyCacheVar) { - ObjCEmptyCacheVar = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.CacheTy, false, - llvm::GlobalValue::ExternalLinkage, nullptr, - "_objc_empty_cache"); + ObjCEmptyCacheVar = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.CacheTy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, "_objc_empty_cache"); if (CGM.getTriple().isOSBinFormatCOFF()) - ObjCEmptyCacheVar->setDLLStorageClass(getStorage(CGM, "_objc_empty_cache")); + ObjCEmptyCacheVar->setDLLStorageClass( + getStorage(CGM, "_objc_empty_cache")); // Only OS X with deployment version <10.9 use the empty vtable symbol const llvm::Triple &Triple = CGM.getTarget().getTriple(); if (Triple.isMacOSX() && Triple.isMacOSXVersionLT(10, 9)) - ObjCEmptyVtableVar = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ImpnfABITy, false, - llvm::GlobalValue::ExternalLinkage, nullptr, - "_objc_empty_vtable"); + ObjCEmptyVtableVar = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.ImpnfABITy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, "_objc_empty_vtable"); else ObjCEmptyVtableVar = llvm::ConstantPointerNull::get(CGM.UnqualPtrTy); } // FIXME: Is this correct (that meta class size is never computed)? uint32_t InstanceStart = - CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassnfABITy); + CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassnfABITy); uint32_t InstanceSize = InstanceStart; uint32_t flags = NonFragileABI_Class_Meta; @@ -6512,9 +6427,8 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { llvm::GlobalVariable *CLASS_RO_GV = BuildClassRoTInitializer(flags, InstanceStart, InstanceSize, ID); - llvm::GlobalVariable *MetaTClass = - BuildClassObject(CI, /*metaclass*/ true, - IsAGV, SuperClassGV, CLASS_RO_GV, classIsHidden); + llvm::GlobalVariable *MetaTClass = BuildClassObject( + CI, /*metaclass*/ true, IsAGV, SuperClassGV, CLASS_RO_GV, classIsHidden); CGM.setGVProperties(MetaTClass, CI); DefinedMetaClasses.push_back(MetaTClass); @@ -6553,8 +6467,8 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { BuildClassRoTInitializer(flags, InstanceStart, InstanceSize, ID); llvm::GlobalVariable *ClassMD = - BuildClassObject(CI, /*metaclass*/ false, - MetaTClass, SuperClassGV, CLASS_RO_GV, classIsHidden); + BuildClassObject(CI, /*metaclass*/ false, MetaTClass, SuperClassGV, + CLASS_RO_GV, classIsHidden); CGM.setGVProperties(ClassMD, CI); DefinedClasses.push_back(ClassMD); ImplementedClasses.push_back(CI); @@ -6565,7 +6479,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { // Force the definition of the EHType if necessary. if (flags & NonFragileABI_Class_Exception) - (void) GetInterfaceEHType(CI, ForDefinition); + (void)GetInterfaceEHType(CI, ForDefinition); // Make sure method definition entries are all clear for next implementation. MethodDefinitions.clear(); } @@ -6578,8 +6492,9 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { /// It generates a weak reference to l_OBJC_PROTOCOL_REFERENCE_$_Proto1 /// which will hold address of the protocol meta-data. /// -llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF, - const ObjCProtocolDecl *PD) { +llvm::Value * +CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF, + const ObjCProtocolDecl *PD) { // This routine is called for @protocol only. So, we must build definition // of protocol's meta-data (not a reference to it!) @@ -6598,8 +6513,8 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF, PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, llvm::GlobalValue::WeakAnyLinkage, Init, ProtocolName); - PTGV->setSection(GetSectionName("__objc_protorefs", - "coalesced,no_dead_strip")); + PTGV->setSection( + GetSectionName("__objc_protorefs", "coalesced,no_dead_strip")); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); PTGV->setAlignment(Align.getAsAlign()); if (!CGM.getTriple().isOSBinFormatMachO()) @@ -6749,9 +6664,8 @@ void CGObjCNonFragileABIMac::emitMethodConstant(ConstantArrayBuilder &builder, /// struct _objc_method method_list[method_count]; /// } /// -llvm::Constant * -CGObjCNonFragileABIMac::emitMethodList(Twine name, MethodListType kind, - ArrayRef methods) { +llvm::Constant *CGObjCNonFragileABIMac::emitMethodList( + Twine name, MethodListType kind, ArrayRef methods) { // Return null for empty list. if (methods.empty()) return llvm::Constant::getNullValue(ObjCTypes.MethodListnfABIPtrTy); @@ -6824,10 +6738,9 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID, Name += Ivar->getName(); llvm::GlobalVariable *IvarOffsetGV = CGM.getModule().getGlobalVariable(Name); if (!IvarOffsetGV) { - IvarOffsetGV = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.IvarOffsetVarTy, - false, llvm::GlobalValue::ExternalLinkage, - nullptr, Name.str()); + IvarOffsetGV = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.IvarOffsetVarTy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, Name.str()); if (CGM.getTriple().isOSBinFormatCOFF()) { bool IsPrivateOrPackage = Ivar->getAccessControl() == ObjCIvarDecl::Private || @@ -6836,11 +6749,11 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID, const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface(); if (ContainingID->hasAttr()) - IvarOffsetGV - ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + IvarOffsetGV->setDLLStorageClass( + llvm::GlobalValue::DLLImportStorageClass); else if (ContainingID->hasAttr() && !IsPrivateOrPackage) - IvarOffsetGV - ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); + IvarOffsetGV->setDLLStorageClass( + llvm::GlobalValue::DLLExportStorageClass); } } return IvarOffsetGV; @@ -6895,8 +6808,8 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const ObjCInterfaceDecl *ID, /// } /// -llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( - const ObjCImplementationDecl *ID) { +llvm::Constant * +CGObjCNonFragileABIMac::EmitIvarList(const ObjCImplementationDecl *ID) { ConstantInitBuilder builder(CGM); auto ivarList = builder.beginStruct(); @@ -6910,8 +6823,8 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( // FIXME. Consolidate this with similar code in GenerateClass. - for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); - IVD; IVD = IVD->getNextIvar()) { + for (const ObjCIvarDecl *IVD = OID->all_declared_ivar_begin(); IVD; + IVD = IVD->getNextIvar()) { // Ignore unnamed bit-fields. if (!IVD->getDeclName()) continue; @@ -6921,11 +6834,11 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( ComputeIvarBaseOffset(CGM, ID, IVD))); ivar.add(GetMethodVarName(IVD->getIdentifier())); ivar.add(GetMethodVarType(IVD)); - llvm::Type *FieldTy = - CGM.getTypes().ConvertTypeForMem(IVD->getType()); + llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(IVD->getType()); unsigned Size = CGM.getDataLayout().getTypeAllocSize(FieldTy); - unsigned Align = CGM.getContext().getPreferredTypeAlign( - IVD->getType().getTypePtr()) >> 3; + unsigned Align = + CGM.getContext().getPreferredTypeAlign(IVD->getType().getTypePtr()) >> + 3; Align = llvm::Log2_32(Align); ivar.addInt(ObjCTypes.IntTy, Align); // NOTE. Size of a bitfield does not match gcc's, because of the @@ -6954,8 +6867,8 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList( return GV; } -llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef( - const ObjCProtocolDecl *PD) { +llvm::Constant * +CGObjCNonFragileABIMac::GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) { llvm::GlobalVariable *&Entry = Protocols[PD->getIdentifier()]; assert(!PD->isNonRuntimeProtocol() && @@ -6965,8 +6878,8 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef( // reference or not. At module finalization we add the empty // contents for protocols which were referenced but never defined. llvm::SmallString<64> Protocol; - llvm::raw_svector_ostream(Protocol) << "_OBJC_PROTOCOL_$_" - << PD->getObjCRuntimeNameAsString(); + llvm::raw_svector_ostream(Protocol) + << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString(); Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABITy, false, llvm::GlobalValue::ExternalLinkage, @@ -6998,8 +6911,8 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocolRef( /// @endcode /// -llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( - const ObjCProtocolDecl *PD) { +llvm::Constant * +CGObjCNonFragileABIMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) { llvm::GlobalVariable *Entry = Protocols[PD->getIdentifier()]; // Early exit if a defining object has already been generated. @@ -7019,36 +6932,34 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( // isa is NULL values.addNullPointer(ObjCTypes.ObjectPtrTy); values.add(GetClassName(PD->getObjCRuntimeNameAsString())); - values.add(EmitProtocolList("_OBJC_$_PROTOCOL_REFS_" - + PD->getObjCRuntimeNameAsString(), - PD->protocol_begin(), - PD->protocol_end())); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::RequiredInstanceMethods)); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::RequiredClassMethods)); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::OptionalInstanceMethods)); - values.add(methodLists.emitMethodList(this, PD, - ProtocolMethodLists::OptionalClassMethods)); - values.add(EmitPropertyList( - "_OBJC_$_PROP_LIST_" + PD->getObjCRuntimeNameAsString(), - nullptr, PD, ObjCTypes, false)); + values.add(EmitProtocolList("_OBJC_$_PROTOCOL_REFS_" + + PD->getObjCRuntimeNameAsString(), + PD->protocol_begin(), PD->protocol_end())); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::RequiredInstanceMethods)); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::RequiredClassMethods)); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::OptionalInstanceMethods)); + values.add(methodLists.emitMethodList( + this, PD, ProtocolMethodLists::OptionalClassMethods)); + values.add( + EmitPropertyList("_OBJC_$_PROP_LIST_" + PD->getObjCRuntimeNameAsString(), + nullptr, PD, ObjCTypes, false)); uint32_t Size = - CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ProtocolnfABITy); + CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ProtocolnfABITy); values.addInt(ObjCTypes.IntTy, Size); values.addInt(ObjCTypes.IntTy, 0); - values.add(EmitProtocolMethodTypes("_OBJC_$_PROTOCOL_METHOD_TYPES_" - + PD->getObjCRuntimeNameAsString(), - methodLists.emitExtendedTypesArray(this), - ObjCTypes)); + values.add(EmitProtocolMethodTypes( + "_OBJC_$_PROTOCOL_METHOD_TYPES_" + PD->getObjCRuntimeNameAsString(), + methodLists.emitExtendedTypesArray(this), ObjCTypes)); // const char *demangledName; values.addNullPointer(ObjCTypes.Int8PtrTy); - values.add(EmitPropertyList( - "_OBJC_$_CLASS_PROP_LIST_" + PD->getObjCRuntimeNameAsString(), - nullptr, PD, ObjCTypes, true)); + values.add(EmitPropertyList("_OBJC_$_CLASS_PROP_LIST_" + + PD->getObjCRuntimeNameAsString(), + nullptr, PD, ObjCTypes, true)); if (Entry) { // Already created, fix the linkage and update the initializer. @@ -7057,7 +6968,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( } else { llvm::SmallString<64> symbolName; llvm::raw_svector_ostream(symbolName) - << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString(); + << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString(); Entry = values.finishAndCreateGlobal(symbolName, CGM.getPointerAlign(), /*constant*/ false, @@ -7073,19 +6984,18 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( // Use this protocol meta-data to build protocol list table in section // __DATA, __objc_protolist llvm::SmallString<64> ProtocolRef; - llvm::raw_svector_ostream(ProtocolRef) << "_OBJC_LABEL_PROTOCOL_$_" - << PD->getObjCRuntimeNameAsString(); + llvm::raw_svector_ostream(ProtocolRef) + << "_OBJC_LABEL_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString(); - llvm::GlobalVariable *PTGV = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ProtocolnfABIPtrTy, - false, llvm::GlobalValue::WeakAnyLinkage, Entry, - ProtocolRef); + llvm::GlobalVariable *PTGV = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.ProtocolnfABIPtrTy, false, + llvm::GlobalValue::WeakAnyLinkage, Entry, ProtocolRef); if (!CGM.getTriple().isOSBinFormatMachO()) PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef)); PTGV->setAlignment( CGM.getDataLayout().getABITypeAlign(ObjCTypes.ProtocolnfABIPtrTy)); - PTGV->setSection(GetSectionName("__objc_protolist", - "coalesced,no_dead_strip")); + PTGV->setSection( + GetSectionName("__objc_protolist", "coalesced,no_dead_strip")); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); CGM.addUsedGlobal(PTGV); return Entry; @@ -7099,10 +7009,9 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( /// } /// @endcode /// -llvm::Constant * -CGObjCNonFragileABIMac::EmitProtocolList(Twine Name, - ObjCProtocolDecl::protocol_iterator begin, - ObjCProtocolDecl::protocol_iterator end) { +llvm::Constant *CGObjCNonFragileABIMac::EmitProtocolList( + Twine Name, ObjCProtocolDecl::protocol_iterator begin, + ObjCProtocolDecl::protocol_iterator end) { // Just return null for empty protocol lists auto Protocols = GetRuntimeProtocolList(begin, end); if (Protocols.empty()) @@ -7123,7 +7032,7 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name, SmallString<256> TmpName; Name.toVector(TmpName); llvm::GlobalVariable *GV = - CGM.getModule().getGlobalVariable(TmpName.str(), true); + CGM.getModule().getGlobalVariable(TmpName.str(), true); if (GV) return GV; @@ -7153,11 +7062,8 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name, /// @encode /// LValue CGObjCNonFragileABIMac::EmitObjCValueForIvar( - CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, - const ObjCIvarDecl *Ivar, - unsigned CVRQualifiers) { + CodeGen::CodeGenFunction &CGF, QualType ObjectTy, llvm::Value *BaseValue, + const ObjCIvarDecl *Ivar, unsigned CVRQualifiers) { ObjCInterfaceDecl *ID = ObjectTy->castAs()->getInterface(); llvm::Value *Offset = EmitIvarOffset(CGF, ID, Ivar); return EmitValueForIvarAtOffset(CGF, ID, BaseValue, Ivar, CVRQualifiers, @@ -7175,9 +7081,8 @@ CGObjCNonFragileABIMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF, ComputeIvarBaseOffset(CGM, Interface->getImplementation(), Ivar)); } else { llvm::GlobalVariable *GV = ObjCIvarOffsetVariable(Interface, Ivar); - IvarOffsetValue = - CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV, - CGF.getSizeAlign(), "ivar"); + IvarOffsetValue = CGF.Builder.CreateAlignedLoad(GV->getValueType(), GV, + CGF.getSizeAlign(), "ivar"); if (IsIvarOffsetKnownIdempotent(CGF, Ivar)) cast(IvarOffsetValue) ->setMetadata(llvm::LLVMContext::MD_invariant_load, @@ -7216,16 +7121,10 @@ static void appendSelectorForMessageRefTable(std::string &buffer, /// appropriate vtable slot, and if not, it substitues a stub function /// which tail-calls objc_msgSend. Both stubs adjust the selector /// argument to correctly point to the selector. -RValue -CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, - ReturnValueSlot returnSlot, - QualType resultType, - Selector selector, - llvm::Value *arg0, - QualType arg0Type, - bool isSuper, - const CallArgList &formalArgs, - const ObjCMethodDecl *method) { +RValue CGObjCNonFragileABIMac::EmitVTableMessageSend( + CodeGenFunction &CGF, ReturnValueSlot returnSlot, QualType resultType, + Selector selector, llvm::Value *arg0, QualType arg0Type, bool isSuper, + const CallArgList &formalArgs, const ObjCMethodDecl *method) { // Compute the actual arguments. CallArgList args; @@ -7281,18 +7180,17 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, // would have used colons. appendSelectorForMessageRefTable(messageRefName, selector); - llvm::GlobalVariable *messageRef - = CGM.getModule().getGlobalVariable(messageRefName); + llvm::GlobalVariable *messageRef = + CGM.getModule().getGlobalVariable(messageRefName); if (!messageRef) { // Build the message ref structure. ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(); values.add(cast(fn.getCallee())); values.add(GetMethodVarName(selector)); - messageRef = values.finishAndCreateGlobal(messageRefName, - CharUnits::fromQuantity(16), - /*constant*/ false, - llvm::GlobalValue::WeakAnyLinkage); + messageRef = values.finishAndCreateGlobal( + messageRefName, CharUnits::fromQuantity(16), + /*constant*/ false, llvm::GlobalValue::WeakAnyLinkage); messageRef->setVisibility(llvm::GlobalValue::HiddenVisibility); messageRef->setSection(GetSectionName("__objc_msgrefs", "coalesced")); } @@ -7309,8 +7207,8 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, } Address mref = - Address(CGF.Builder.CreateBitCast(messageRef, ObjCTypes.MessageRefPtrTy), - ObjCTypes.MessageRefTy, CGF.getPointerAlign()); + Address(CGF.Builder.CreateBitCast(messageRef, ObjCTypes.MessageRefPtrTy), + ObjCTypes.MessageRefTy, CGF.getPointerAlign()); // Update the message ref argument. args[1].setRValue(RValue::get(mref, CGF)); @@ -7328,22 +7226,17 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF, } /// Generate code for a message send expression in the nonfragile abi. -CodeGen::RValue -CGObjCNonFragileABIMac::GenerateMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Receiver, - const CallArgList &CallArgs, - const ObjCInterfaceDecl *Class, - const ObjCMethodDecl *Method) { +CodeGen::RValue CGObjCNonFragileABIMac::GenerateMessageSend( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, llvm::Value *Receiver, const CallArgList &CallArgs, + const ObjCInterfaceDecl *Class, const ObjCMethodDecl *Method) { return isVTableDispatchedSelector(Sel) - ? EmitVTableMessageSend(CGF, Return, ResultType, Sel, - Receiver, CGF.getContext().getObjCIdType(), - false, CallArgs, Method) - : EmitMessageSend(CGF, Return, ResultType, Sel, - Receiver, CGF.getContext().getObjCIdType(), - false, CallArgs, Method, Class, ObjCTypes); + ? EmitVTableMessageSend(CGF, Return, ResultType, Sel, Receiver, + CGF.getContext().getObjCIdType(), false, + CallArgs, Method) + : EmitMessageSend(CGF, Return, ResultType, Sel, Receiver, + CGF.getContext().getObjCIdType(), false, + CallArgs, Method, Class, ObjCTypes); } llvm::Constant * @@ -7351,13 +7244,12 @@ CGObjCNonFragileABIMac::GetClassGlobal(const ObjCInterfaceDecl *ID, bool metaclass, ForDefinition_t isForDefinition) { auto prefix = - (metaclass ? getMetaclassSymbolPrefix() : getClassSymbolPrefix()); + (metaclass ? getMetaclassSymbolPrefix() : getClassSymbolPrefix()); return GetClassGlobal((prefix + ID->getObjCRuntimeNameAsString()).str(), - isForDefinition, - ID->isWeakImported(), - !isForDefinition - && CGM.getTriple().isOSBinFormatCOFF() - && ID->hasAttr()); + isForDefinition, ID->isWeakImported(), + !isForDefinition && + CGM.getTriple().isOSBinFormatCOFF() && + ID->hasAttr()); } llvm::Constant * @@ -7390,8 +7282,8 @@ CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name, llvm::Constant * CGObjCNonFragileABIMac::GetClassGlobalForClassRef(const ObjCInterfaceDecl *ID) { - llvm::Constant *ClassGV = GetClassGlobal(ID, /*metaclass*/ false, - NotForDefinition); + llvm::Constant *ClassGV = + GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition); if (!ID->hasAttr()) return ClassGV; @@ -7411,18 +7303,16 @@ CGObjCNonFragileABIMac::EmitLoadOfClassRef(CodeGenFunction &CGF, if (ID && ID->hasAttr()) { // Classrefs pointing at Objective-C stub classes must be loaded by calling // a special runtime function. - return CGF.EmitRuntimeCall( - ObjCTypes.getLoadClassrefFn(), Entry, "load_classref_result"); + return CGF.EmitRuntimeCall(ObjCTypes.getLoadClassrefFn(), Entry, + "load_classref_result"); } CharUnits Align = CGF.getPointerAlign(); return CGF.Builder.CreateAlignedLoad(Entry->getValueType(), Entry, Align); } -llvm::Value * -CGObjCNonFragileABIMac::EmitClassRefFromId(CodeGenFunction &CGF, - IdentifierInfo *II, - const ObjCInterfaceDecl *ID) { +llvm::Value *CGObjCNonFragileABIMac::EmitClassRefFromId( + CodeGenFunction &CGF, IdentifierInfo *II, const ObjCInterfaceDecl *ID) { llvm::GlobalVariable *&Entry = ClassReferences[II]; if (!Entry) { @@ -7462,8 +7352,8 @@ llvm::Value *CGObjCNonFragileABIMac::EmitClassRef(CodeGenFunction &CGF, return EmitClassRefFromId(CGF, ID->getIdentifier(), ID); } -llvm::Value *CGObjCNonFragileABIMac::EmitNSAutoreleasePoolClassRef( - CodeGenFunction &CGF) { +llvm::Value * +CGObjCNonFragileABIMac::EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) { IdentifierInfo *II = &CGM.getContext().Idents.get("NSAutoreleasePool"); return EmitClassRefFromId(CGF, II, nullptr); } @@ -7491,11 +7381,10 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF, /// EmitMetaClassRef - Return a Value * of the address of _class_t /// meta-data /// -llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID, - bool Weak) { +llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef( + CodeGenFunction &CGF, const ObjCInterfaceDecl *ID, bool Weak) { CharUnits Align = CGF.getPointerAlign(); - llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()]; + llvm::GlobalVariable *&Entry = MetaClassReferences[ID->getIdentifier()]; if (!Entry) { auto MetaClassGV = GetClassGlobal(ID, /*metaclass*/ true, NotForDefinition); std::string SectionName = @@ -7528,17 +7417,11 @@ llvm::Value *CGObjCNonFragileABIMac::GetClass(CodeGenFunction &CGF, /// Generates a message send where the super is the receiver. This is /// a message send to self with special delivery semantics indicating /// which class's method should be called. -CodeGen::RValue -CGObjCNonFragileABIMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - const ObjCInterfaceDecl *Class, - bool isCategoryImpl, - llvm::Value *Receiver, - bool IsClassMessage, - const CodeGen::CallArgList &CallArgs, - const ObjCMethodDecl *Method) { +CodeGen::RValue CGObjCNonFragileABIMac::GenerateMessageSendSuper( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, const ObjCInterfaceDecl *Class, bool isCategoryImpl, + llvm::Value *Receiver, bool IsClassMessage, + const CodeGen::CallArgList &CallArgs, const ObjCMethodDecl *Method) { // ... // Create and init a super structure; this is a (receiver, class) // pair we will pass to objc_msgSendSuper. @@ -7546,38 +7429,38 @@ CGObjCNonFragileABIMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, ObjCTypes.SuperTy, CGF.getPointerAlign(), "objc_super"); llvm::Value *ReceiverAsObject = - CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy); + CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy); CGF.Builder.CreateStore(ReceiverAsObject, CGF.Builder.CreateStructGEP(ObjCSuper, 0)); // If this is a class message the metaclass is passed as the target. llvm::Value *Target; if (IsClassMessage) - Target = EmitMetaClassRef(CGF, Class, Class->isWeakImported()); + Target = EmitMetaClassRef(CGF, Class, Class->isWeakImported()); else Target = EmitSuperClassRef(CGF, Class); // FIXME: We shouldn't need to do this cast, rectify the ASTContext and // ObjCTypes types. llvm::Type *ClassTy = - CGM.getTypes().ConvertType(CGF.getContext().getObjCClassType()); + CGM.getTypes().ConvertType(CGF.getContext().getObjCClassType()); Target = CGF.Builder.CreateBitCast(Target, ClassTy); CGF.Builder.CreateStore(Target, CGF.Builder.CreateStructGEP(ObjCSuper, 1)); return (isVTableDispatchedSelector(Sel)) - ? EmitVTableMessageSend(CGF, Return, ResultType, Sel, - ObjCSuper.getPointer(), ObjCTypes.SuperPtrCTy, - true, CallArgs, Method) - : EmitMessageSend(CGF, Return, ResultType, Sel, - ObjCSuper.getPointer(), ObjCTypes.SuperPtrCTy, - true, CallArgs, Method, Class, ObjCTypes); + ? EmitVTableMessageSend( + CGF, Return, ResultType, Sel, ObjCSuper.getPointer(), + ObjCTypes.SuperPtrCTy, true, CallArgs, Method) + : EmitMessageSend(CGF, Return, ResultType, Sel, + ObjCSuper.getPointer(), ObjCTypes.SuperPtrCTy, + true, CallArgs, Method, Class, ObjCTypes); } llvm::Value *CGObjCNonFragileABIMac::EmitSelector(CodeGenFunction &CGF, Selector Sel) { Address Addr = EmitSelectorAddr(Sel); - llvm::LoadInst* LI = CGF.Builder.CreateLoad(Addr); + llvm::LoadInst *LI = CGF.Builder.CreateLoad(Addr); LI->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(VMContext, {})); return LI; @@ -7606,15 +7489,14 @@ ConstantAddress CGObjCNonFragileABIMac::EmitSelectorAddr(Selector Sel) { /// objc_assign_ivar (id src, id *dst, ptrdiff_t) /// void CGObjCNonFragileABIMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, - Address dst, + llvm::Value *src, Address dst, llvm::Value *ivarOffset) { - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); src = (Size == 4 ? CGF.Builder.CreateBitCast(src, ObjCTypes.IntTy) - : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); + : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); @@ -7628,22 +7510,21 @@ void CGObjCNonFragileABIMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, /// objc_assign_strongCast (id src, id *dst) /// void CGObjCNonFragileABIMac::EmitObjCStrongCastAssign( - CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dst) { - llvm::Type * SrcTy = src->getType(); + CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst) { + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); src = (Size == 4 ? CGF.Builder.CreateBitCast(src, ObjCTypes.IntTy) - : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); + : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); llvm::Value *args[] = {src, dstVal}; - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(), - args, "weakassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(), args, + "weakassign"); } void CGObjCNonFragileABIMac::EmitGCMemmoveCollectable( @@ -7657,15 +7538,14 @@ void CGObjCNonFragileABIMac::EmitGCMemmoveCollectable( /// EmitObjCWeakRead - Code gen for loading value of a __weak /// object: objc_read_weak (id *src) /// -llvm::Value * CGObjCNonFragileABIMac::EmitObjCWeakRead( - CodeGen::CodeGenFunction &CGF, - Address AddrWeakObj) { +llvm::Value * +CGObjCNonFragileABIMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, + Address AddrWeakObj) { llvm::Type *DestTy = AddrWeakObj.getElementType(); llvm::Value *AddrWeakObjVal = CGF.Builder.CreateBitCast( AddrWeakObj.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); - llvm::Value *read_weak = - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcReadWeakFn(), - AddrWeakObjVal, "weakread"); + llvm::Value *read_weak = CGF.EmitNounwindRuntimeCall( + ObjCTypes.getGcReadWeakFn(), AddrWeakObjVal, "weakread"); read_weak = CGF.Builder.CreateBitCast(read_weak, DestTy); return read_weak; } @@ -7675,34 +7555,34 @@ llvm::Value * CGObjCNonFragileABIMac::EmitObjCWeakRead( /// void CGObjCNonFragileABIMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dst) { - llvm::Type * SrcTy = src->getType(); + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); src = (Size == 4 ? CGF.Builder.CreateBitCast(src, ObjCTypes.IntTy) - : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); + : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy); llvm::Value *args[] = {src, dstVal}; - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(), - args, "weakassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(), args, + "weakassign"); } /// EmitObjCGlobalAssign - Code gen for assigning to a __strong object. /// objc_assign_global (id src, id *dst) /// void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, - llvm::Value *src, Address dst, - bool threadlocal) { - llvm::Type * SrcTy = src->getType(); + llvm::Value *src, Address dst, + bool threadlocal) { + llvm::Type *SrcTy = src->getType(); if (!isa(SrcTy)) { unsigned Size = CGM.getDataLayout().getTypeAllocSize(SrcTy); assert(Size <= 8 && "does not support size > 8"); src = (Size == 4 ? CGF.Builder.CreateBitCast(src, ObjCTypes.IntTy) - : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); + : CGF.Builder.CreateBitCast(src, ObjCTypes.LongTy)); src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy); } src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy); @@ -7710,30 +7590,27 @@ void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, ObjCTypes.PtrObjectPtrTy); llvm::Value *args[] = {src, dstVal}; if (!threadlocal) - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(), - args, "globalassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(), args, + "globalassign"); else - CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignThreadLocalFn(), - args, "threadlocalassign"); + CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignThreadLocalFn(), args, + "threadlocalassign"); } -void -CGObjCNonFragileABIMac::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF, - const ObjCAtSynchronizedStmt &S) { +void CGObjCNonFragileABIMac::EmitSynchronizedStmt( + CodeGen::CodeGenFunction &CGF, const ObjCAtSynchronizedStmt &S) { EmitAtSynchronizedStmt(CGF, S, ObjCTypes.getSyncEnterFn(), ObjCTypes.getSyncExitFn()); } -llvm::Constant * -CGObjCNonFragileABIMac::GetEHType(QualType T) { +llvm::Constant *CGObjCNonFragileABIMac::GetEHType(QualType T) { // There's a particular fixed type info for 'id'. if (T->isObjCIdType() || T->isObjCQualifiedIdType()) { auto *IDEHType = CGM.getModule().getGlobalVariable("OBJC_EHTYPE_id"); if (!IDEHType) { - IDEHType = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, false, - llvm::GlobalValue::ExternalLinkage, nullptr, - "OBJC_EHTYPE_id"); + IDEHType = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.EHTypeTy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, "OBJC_EHTYPE_id"); if (CGM.getTriple().isOSBinFormatCOFF()) IDEHType->setDLLStorageClass(getStorage(CGM, "OBJC_EHTYPE_id")); } @@ -7781,7 +7658,7 @@ void CGObjCNonFragileABIMac::EmitThrowStmt(CodeGen::CodeGenFunction &CGF, llvm::Constant * CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID, ForDefinition_t IsForDefinition) { - llvm::GlobalVariable * &Entry = EHTypeReferences[ID->getIdentifier()]; + llvm::GlobalVariable *&Entry = EHTypeReferences[ID->getIdentifier()]; StringRef ClassName = ID->getObjCRuntimeNameAsString(); // If we don't need a definition, return the entry if found or check @@ -7794,9 +7671,9 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID, // attribute, emit an external reference. if (hasObjCExceptionAttribute(CGM.getContext(), ID)) { std::string EHTypeName = ("OBJC_EHTYPE_$_" + ClassName).str(); - Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.EHTypeTy, - false, llvm::GlobalValue::ExternalLinkage, - nullptr, EHTypeName); + Entry = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.EHTypeTy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, EHTypeName); CGM.setGVProperties(Entry, ID); return Entry; } @@ -7808,10 +7685,9 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID, std::string VTableName = "objc_ehtype_vtable"; auto *VTableGV = CGM.getModule().getGlobalVariable(VTableName); if (!VTableGV) { - VTableGV = - new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.Int8PtrTy, false, - llvm::GlobalValue::ExternalLinkage, nullptr, - VTableName); + VTableGV = new llvm::GlobalVariable( + CGM.getModule(), ObjCTypes.Int8PtrTy, false, + llvm::GlobalValue::ExternalLinkage, nullptr, VTableName); if (CGM.getTriple().isOSBinFormatCOFF()) VTableGV->setDLLStorageClass(getStorage(CGM, VTableName)); } @@ -7819,9 +7695,8 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID, llvm::Value *VTableIdx = llvm::ConstantInt::get(CGM.Int32Ty, 2); ConstantInitBuilder builder(CGM); auto values = builder.beginStruct(ObjCTypes.EHTypeTy); - values.add( - llvm::ConstantExpr::getInBoundsGetElementPtr(VTableGV->getValueType(), - VTableGV, VTableIdx)); + values.add(llvm::ConstantExpr::getInBoundsGetElementPtr( + VTableGV->getValueType(), VTableGV, VTableIdx)); values.add(GetClassName(ClassName)); values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition)); @@ -7834,8 +7709,7 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID, } else { Entry = values.finishAndCreateGlobal("OBJC_EHTYPE_$_" + ClassName, CGM.getPointerAlign(), - /*constant*/ false, - L); + /*constant*/ false, L); if (hasObjCExceptionAttribute(CGM.getContext(), ID)) CGM.setGVProperties(Entry, ID); } @@ -7858,7 +7732,7 @@ CodeGen::CGObjCRuntime * CodeGen::CreateMacObjCRuntime(CodeGen::CodeGenModule &CGM) { switch (CGM.getLangOpts().ObjCRuntime.getKind()) { case ObjCRuntime::FragileMacOSX: - return new CGObjCMac(CGM); + return new CGObjCMac(CGM); case ObjCRuntime::MacOSX: case ObjCRuntime::iOS: diff --git a/clang/lib/CodeGen/CGObjCRuntime.h b/clang/lib/CodeGen/CGObjCRuntime.h index 3bd981256f47..72997bf6348a 100644 --- a/clang/lib/CodeGen/CGObjCRuntime.h +++ b/clang/lib/CodeGen/CGObjCRuntime.h @@ -23,40 +23,40 @@ #include "llvm/ADT/UniqueVector.h" namespace llvm { - class Constant; - class Function; - class Module; - class StructLayout; - class StructType; - class Type; - class Value; -} +class Constant; +class Function; +class Module; +class StructLayout; +class StructType; +class Type; +class Value; +} // namespace llvm namespace clang { namespace CodeGen { class CGFunctionInfo; class CodeGenFunction; -} - - class FieldDecl; - class ObjCAtTryStmt; - class ObjCAtThrowStmt; - class ObjCAtSynchronizedStmt; - class ObjCContainerDecl; - class ObjCCategoryImplDecl; - class ObjCImplementationDecl; - class ObjCInterfaceDecl; - class ObjCMessageExpr; - class ObjCMethodDecl; - class ObjCProtocolDecl; - class Selector; - class ObjCIvarDecl; - class ObjCStringLiteral; - class BlockDeclRefExpr; +} // namespace CodeGen + +class FieldDecl; +class ObjCAtTryStmt; +class ObjCAtThrowStmt; +class ObjCAtSynchronizedStmt; +class ObjCContainerDecl; +class ObjCCategoryImplDecl; +class ObjCImplementationDecl; +class ObjCInterfaceDecl; +class ObjCMessageExpr; +class ObjCMethodDecl; +class ObjCProtocolDecl; +class Selector; +class ObjCIvarDecl; +class ObjCStringLiteral; +class BlockDeclRefExpr; namespace CodeGen { - class CodeGenModule; - class CGBlockInfo; +class CodeGenModule; +class CGBlockInfo; // FIXME: Several methods should be pure virtual but aren't to avoid the // partially-implemented subclass breaking. @@ -88,8 +88,7 @@ class CGObjCRuntime { const ObjCInterfaceDecl *OID, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, - unsigned CVRQualifiers, - llvm::Value *Offset); + unsigned CVRQualifiers, llvm::Value *Offset); /// Emits a try / catch statement. This function is intended to be called by /// subclasses, and provides a generic mechanism for generating these, which /// should be usable by all runtimes. The caller must provide the functions @@ -145,7 +144,7 @@ class CGObjCRuntime { /// error to Sema. virtual llvm::Constant *GetEHType(QualType T) = 0; - virtual CatchTypeInfo getCatchAllTypeInfo() { return { nullptr, 0 }; } + virtual CatchTypeInfo getCatchAllTypeInfo() { return {nullptr, 0}; } /// Generate a constant string object. virtual ConstantAddress GenerateConstantString(const StringLiteral *) = 0; @@ -165,11 +164,8 @@ class CGObjCRuntime { /// \param Method - The method being called, this may be null if synthesizing /// a property setter or getter. virtual CodeGen::RValue - GenerateMessageSend(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot ReturnSlot, - QualType ResultType, - Selector Sel, - llvm::Value *Receiver, + GenerateMessageSend(CodeGen::CodeGenFunction &CGF, ReturnValueSlot ReturnSlot, + QualType ResultType, Selector Sel, llvm::Value *Receiver, const CallArgList &CallArgs, const ObjCInterfaceDecl *Class = nullptr, const ObjCMethodDecl *Method = nullptr) = 0; @@ -178,16 +174,11 @@ class CGObjCRuntime { /// /// This variant allows for the call to be substituted with an optimized /// variant. - CodeGen::RValue - GeneratePossiblySpecializedMessageSend(CodeGenFunction &CGF, - ReturnValueSlot Return, - QualType ResultType, - Selector Sel, - llvm::Value *Receiver, - const CallArgList& Args, - const ObjCInterfaceDecl *OID, - const ObjCMethodDecl *Method, - bool isClassMessage); + CodeGen::RValue GeneratePossiblySpecializedMessageSend( + CodeGenFunction &CGF, ReturnValueSlot Return, QualType ResultType, + Selector Sel, llvm::Value *Receiver, const CallArgList &Args, + const ObjCInterfaceDecl *OID, const ObjCMethodDecl *Method, + bool isClassMessage); /// Generate an Objective-C message send operation to the super /// class initiated in a method for Class and with the given Self @@ -195,17 +186,11 @@ class CGObjCRuntime { /// /// \param Method - The method being called, this may be null if synthesizing /// a property setter or getter. - virtual CodeGen::RValue - GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, - ReturnValueSlot ReturnSlot, - QualType ResultType, - Selector Sel, - const ObjCInterfaceDecl *Class, - bool isCategoryImpl, - llvm::Value *Self, - bool IsClassMessage, - const CallArgList &CallArgs, - const ObjCMethodDecl *Method = nullptr) = 0; + virtual CodeGen::RValue GenerateMessageSendSuper( + CodeGen::CodeGenFunction &CGF, ReturnValueSlot ReturnSlot, + QualType ResultType, Selector Sel, const ObjCInterfaceDecl *Class, + bool isCategoryImpl, llvm::Value *Self, bool IsClassMessage, + const CallArgList &CallArgs, const ObjCMethodDecl *Method = nullptr) = 0; /// Walk the list of protocol references from a class, category or /// protocol to traverse the DAG formed from it's inheritance hierarchy. Find @@ -272,7 +257,6 @@ class CGObjCRuntime { virtual llvm::Value *GetClass(CodeGenFunction &CGF, const ObjCInterfaceDecl *OID) = 0; - virtual llvm::Value *EmitNSAutoreleasePoolClassRef(CodeGenFunction &CGF) { llvm_unreachable("autoreleasepool unsupported in this ABI"); } @@ -287,14 +271,14 @@ class CGObjCRuntime { const ObjCAtTryStmt &S) = 0; virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, const ObjCAtThrowStmt &S, - bool ClearInsertionPoint=true) = 0; + bool ClearInsertionPoint = true) = 0; virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, Address AddrWeakObj) = 0; virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest) = 0; virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, - bool threadlocal=false) = 0; + bool threadlocal = false) = 0; virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, llvm::Value *ivarOffset) = 0; @@ -302,21 +286,21 @@ class CGObjCRuntime { llvm::Value *src, Address dest) = 0; virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, - QualType ObjectTy, - llvm::Value *BaseValue, + QualType ObjectTy, llvm::Value *BaseValue, const ObjCIvarDecl *Ivar, unsigned CVRQualifiers) = 0; virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF, const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar) = 0; virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, - Address DestPtr, - Address SrcPtr, + Address DestPtr, Address SrcPtr, llvm::Value *Size) = 0; - virtual llvm::Constant *BuildGCBlockLayout(CodeGen::CodeGenModule &CGM, - const CodeGen::CGBlockInfo &blockInfo) = 0; - virtual llvm::Constant *BuildRCBlockLayout(CodeGen::CodeGenModule &CGM, - const CodeGen::CGBlockInfo &blockInfo) = 0; + virtual llvm::Constant * + BuildGCBlockLayout(CodeGen::CodeGenModule &CGM, + const CodeGen::CGBlockInfo &blockInfo) = 0; + virtual llvm::Constant * + BuildRCBlockLayout(CodeGen::CodeGenModule &CGM, + const CodeGen::CGBlockInfo &blockInfo) = 0; virtual std::string getRCBlockLayoutStr(CodeGen::CodeGenModule &CGM, const CGBlockInfo &blockInfo) { return {}; @@ -332,15 +316,14 @@ class CGObjCRuntime { MessageSendInfo(const CGFunctionInfo &callInfo, llvm::PointerType *messengerType) - : CallInfo(callInfo), MessengerType(messengerType) {} + : CallInfo(callInfo), MessengerType(messengerType) {} }; MessageSendInfo getMessageSendInfo(const ObjCMethodDecl *method, QualType resultType, CallArgList &callArgs); bool canMessageReceiverBeNull(CodeGenFunction &CGF, - const ObjCMethodDecl *method, - bool isSuper, + const ObjCMethodDecl *method, bool isSuper, const ObjCInterfaceDecl *classReceiver, llvm::Value *receiver); static bool isWeakLinkedClass(const ObjCInterfaceDecl *cls); @@ -364,9 +347,9 @@ class CGObjCRuntime { }; /// Creates an instance of an Objective-C runtime class. -//TODO: This should include some way of selecting which runtime to target. +// TODO: This should include some way of selecting which runtime to target. CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); -} -} +} // namespace CodeGen +} // namespace clang #endif diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index e7a5100a9fa2..f3af9b4ace44 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -54,7 +54,7 @@ class SwitchInst; class Twine; class Value; class CanonicalLoopInfo; -} +} // namespace llvm namespace clang { class ASTContext; @@ -102,6 +102,7 @@ class TargetCodeGenInfo; struct OMPTaskDataTy; struct CGCoroData; +// clang-format off /// The kind of evaluation to perform on values of a particular /// type. Basically, is the code in CGExprScalar, CGExprComplex, or /// CGExprAgg? @@ -112,6 +113,7 @@ enum TypeEvaluationKind { TEK_Complex, TEK_Aggregate }; +// clang-format on #define LIST_SANITIZER_CHECKS \ SANITIZER_CHECK(AddOverflow, add_overflow, 0) \ @@ -150,7 +152,7 @@ enum SanitizerHandler { /// Helper class with most of the code for saving a value for a /// conditional expression cleanup. struct DominatingLLVMValue { - typedef llvm::PointerIntPair saved_type; + typedef llvm::PointerIntPair saved_type; /// Answer whether the given value needs extra work to be saved. static bool needsSaving(llvm::Value *value) { @@ -158,7 +160,8 @@ struct DominatingLLVMValue { return false; // If it's not an instruction, we don't need to save. - if (!isa(value)) return false; + if (!isa(value)) + return false; // If it's an instruction in the entry block, we don't need to save. llvm::BasicBlock *block = cast(value)->getParent(); @@ -171,10 +174,10 @@ struct DominatingLLVMValue { /// A partial specialization of DominatingValue for llvm::Values that /// might be llvm::Instructions. -template struct DominatingPointer : DominatingLLVMValue { +template struct DominatingPointer : DominatingLLVMValue { typedef T *type; static type restore(CodeGenFunction &CGF, saved_type value) { - return static_cast(DominatingLLVMValue::restore(CGF, value)); + return static_cast(DominatingLLVMValue::restore(CGF, value)); } }; @@ -212,8 +215,13 @@ template <> struct DominatingValue
{ template <> struct DominatingValue { typedef RValue type; class saved_type { - enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, - AggregateAddress, ComplexAddress }; + enum Kind { + ScalarLiteral, + ScalarAddress, + AggregateLiteral, + AggregateAddress, + ComplexAddress + }; union { struct { DominatingLLVMValue::saved_type first, second; @@ -241,9 +249,7 @@ template <> struct DominatingValue { // implementations in CGCleanup.cpp }; - static bool needsSaving(type value) { - return saved_type::needsSaving(value); - } + static bool needsSaving(type value) { return saved_type::needsSaving(value); } static saved_type save(CodeGenFunction &CGF, type value) { return saved_type::save(CGF, value); } @@ -259,6 +265,7 @@ class CodeGenFunction : public CodeGenTypeCache { void operator=(const CodeGenFunction &) = delete; friend class CGCXXABI; + public: /// A jump destination is an abstract label, branching to which may /// require a jump out through normal cleanups. @@ -284,7 +291,7 @@ class CodeGenFunction : public CodeGenTypeCache { unsigned Index; }; - CodeGenModule &CGM; // Per-module state. + CodeGenModule &CGM; // Per-module state. const TargetInfo &Target; // For EH/SEH outlined funclets, this field points to parent's CGF @@ -369,9 +376,7 @@ class CodeGenFunction : public CodeGenTypeCache { }; CGCoroInfo CurCoro; - bool isCoroutine() const { - return CurCoro.Data != nullptr; - } + bool isCoroutine() const { return CurCoro.Data != nullptr; } bool inSuspendBlock() const { return isCoroutine() && CurCoro.InSuspendBlock; @@ -464,10 +469,10 @@ class CodeGenFunction : public CodeGenTypeCache { : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) {} explicit CGCapturedStmtInfo(const CapturedStmt &S, CapturedRegionKind K = CR_Default) - : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { + : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { RecordDecl::field_iterator Field = - S.getCapturedRecordDecl()->field_begin(); + S.getCapturedRecordDecl()->field_begin(); for (CapturedStmt::const_capture_iterator I = S.capture_begin(), E = S.capture_end(); I != E; ++I, ++Field) { @@ -496,9 +501,7 @@ class CodeGenFunction : public CodeGenTypeCache { bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; } virtual FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; } - static bool classof(const CGCapturedStmtInfo *) { - return true; - } + static bool classof(const CGCapturedStmtInfo *) { return true; } /// Emit the captured statement body. virtual void EmitBody(CodeGenFunction &CGF, const Stmt *S) { @@ -535,6 +538,7 @@ class CodeGenFunction : public CodeGenTypeCache { private: CodeGenFunction &CGF; CGCapturedStmtInfo *PrevCapturedStmtInfo; + public: CGCapturedStmtRAII(CodeGenFunction &CGF, CGCapturedStmtInfo *NewCapturedStmtInfo) @@ -578,6 +582,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// RAII object to set/unset CodeGenFunction::IsSanitizerScope. class SanitizerScope { CodeGenFunction *CGF; + public: SanitizerScope(CodeGenFunction *CGF); ~SanitizerScope(); @@ -832,7 +837,7 @@ class CodeGenFunction : public CodeGenTypeCache { public: /// ObjCEHValueStack - Stack of Objective-C exception values, used for /// rethrows. - SmallVector ObjCEHValueStack; + SmallVector ObjCEHValueStack; /// A class controlling the emission of a finally block. class FinallyInfo { @@ -900,7 +905,8 @@ class CodeGenFunction : public CodeGenTypeCache { SavedTuple Saved{saveValueInCond(A)...}; typedef EHScopeStack::ConditionalCleanup CleanupType; - pushCleanupAfterFullExprWithActiveFlag(Kind, ActiveFlag, Saved); + pushCleanupAfterFullExprWithActiveFlag(Kind, ActiveFlag, + Saved); } template @@ -990,15 +996,16 @@ class CodeGenFunction : public CodeGenTypeCache { size_t LifetimeExtendedCleanupStackSize; CleanupDeactivationScope DeactivateCleanups; bool OldDidCallStackSave; + protected: bool PerformCleanup; - private: + private: RunCleanupsScope(const RunCleanupsScope &) = delete; void operator=(const RunCleanupsScope &) = delete; protected: - CodeGenFunction& CGF; + CodeGenFunction &CGF; public: /// Enter a new cleanup scope. @@ -1030,7 +1037,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// the insertion point after cleanup emission. If cleanup emission created /// a shared cleanup block, these value pointers will be rewritten. /// Otherwise, they not will be modified. - void ForceCleanup(std::initializer_list ValuesToReload = {}) { + void + ForceCleanup(std::initializer_list ValuesToReload = {}) { assert(PerformCleanup && "Already forced cleanup"); CGF.DidCallStackSave = OldDidCallStackSave; DeactivateCleanups.ForceDeactivate(); @@ -1047,7 +1055,7 @@ class CodeGenFunction : public CodeGenTypeCache { class LexicalScope : public RunCleanupsScope { SourceRange Range; - SmallVector Labels; + SmallVector Labels; LexicalScope *ParentScope; LexicalScope(const LexicalScope &) = delete; @@ -1056,7 +1064,8 @@ class CodeGenFunction : public CodeGenTypeCache { public: /// Enter a new cleanup scope. explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) - : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) { + : RunCleanupsScope(CGF), Range(Range), + ParentScope(CGF.CurLexicalScope) { CGF.CurLexicalScope = this; if (CGDebugInfo *DI = CGF.getDebugInfo()) DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); @@ -1091,9 +1100,7 @@ class CodeGenFunction : public CodeGenTypeCache { rescopeLabels(); } - bool hasLabels() const { - return !Labels.empty(); - } + bool hasLabels() const { return !Labels.empty(); } void rescopeLabels(); }; @@ -1120,7 +1127,8 @@ class CodeGenFunction : public CodeGenTypeCache { Address TempAddr) { LocalVD = LocalVD->getCanonicalDecl(); // Only save it once. - if (SavedLocals.count(LocalVD)) return false; + if (SavedLocals.count(LocalVD)) + return false; // Copy the existing local entry to SavedLocals. auto it = CGF.LocalDeclMap.find(LocalVD); @@ -1259,8 +1267,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// target of a potentially scope-crossing jump; get a stable handle /// to which we can perform this jump later. JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { - return JumpDest(Target, - EHStack.getInnermostNormalCleanup(), + return JumpDest(Target, EHStack.getInnermostNormalCleanup(), NextCleanupDestIndex++); } @@ -1297,7 +1304,7 @@ class CodeGenFunction : public CodeGenTypeCache { public: ConditionalEvaluation(CodeGenFunction &CGF) - : StartBB(CGF.Builder.GetInsertBlock()) {} + : StartBB(CGF.Builder.GetInsertBlock()) {} void begin(CodeGenFunction &CGF) { assert(CGF.OutermostConditional != this); @@ -1313,9 +1320,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// Returns a block which will be executed prior to each /// evaluation of the conditional code. - llvm::BasicBlock *getStartingBlock() const { - return StartBB; - } + llvm::BasicBlock *getStartingBlock() const { return StartBB; } }; /// isInConditionalBranch - Return true if we're currently emitting @@ -1343,7 +1348,7 @@ class CodeGenFunction : public CodeGenTypeCache { public: StmtExprEvaluation(CodeGenFunction &CGF) - : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { + : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { CGF.OutermostConditional = nullptr; } @@ -1375,9 +1380,9 @@ class CodeGenFunction : public CodeGenTypeCache { bool BoundLValue; CodeGenFunction::PeepholeProtection Protection; - OpaqueValueMappingData(const OpaqueValueExpr *ov, - bool boundLValue) - : OpaqueValue(ov), BoundLValue(boundLValue) {} + OpaqueValueMappingData(const OpaqueValueExpr *ov, bool boundLValue) + : OpaqueValue(ov), BoundLValue(boundLValue) {} + public: OpaqueValueMappingData() : OpaqueValue(nullptr) {} @@ -1387,30 +1392,26 @@ class CodeGenFunction : public CodeGenTypeCache { // always keeps them in memory. Expressions of function type // act exactly like l-values but are formally required to be // r-values in C. - return expr->isGLValue() || - expr->getType()->isFunctionType() || + return expr->isGLValue() || expr->getType()->isFunctionType() || hasAggregateEvaluationKind(expr->getType()); } - static OpaqueValueMappingData bind(CodeGenFunction &CGF, - const OpaqueValueExpr *ov, - const Expr *e) { + static OpaqueValueMappingData + bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const Expr *e) { if (shouldBindAsLValue(ov)) return bind(CGF, ov, CGF.EmitLValue(e)); return bind(CGF, ov, CGF.EmitAnyExpr(e)); } - static OpaqueValueMappingData bind(CodeGenFunction &CGF, - const OpaqueValueExpr *ov, - const LValue &lv) { + static OpaqueValueMappingData + bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const LValue &lv) { assert(shouldBindAsLValue(ov)); CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); return OpaqueValueMappingData(ov, true); } - static OpaqueValueMappingData bind(CodeGenFunction &CGF, - const OpaqueValueExpr *ov, - const RValue &rv) { + static OpaqueValueMappingData + bind(CodeGenFunction &CGF, const OpaqueValueExpr *ov, const RValue &rv) { assert(!shouldBindAsLValue(ov)); CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); @@ -1455,7 +1456,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// helpful. /// OpaqueValueMapping(CodeGenFunction &CGF, - const AbstractConditionalOperator *op) : CGF(CGF) { + const AbstractConditionalOperator *op) + : CGF(CGF) { if (isa(op)) // Leave Data empty. return; @@ -1476,17 +1478,15 @@ class CodeGenFunction : public CodeGenTypeCache { } } - OpaqueValueMapping(CodeGenFunction &CGF, - const OpaqueValueExpr *opaqueValue, + OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue, LValue lvalue) - : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { - } + : CGF(CGF), + Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) {} - OpaqueValueMapping(CodeGenFunction &CGF, - const OpaqueValueExpr *opaqueValue, + OpaqueValueMapping(CodeGenFunction &CGF, const OpaqueValueExpr *opaqueValue, RValue rvalue) - : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { - } + : CGF(CGF), + Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) {} void pop() { Data.unbind(CGF); @@ -1494,7 +1494,8 @@ class CodeGenFunction : public CodeGenTypeCache { } ~OpaqueValueMapping() { - if (Data.isValid()) Data.unbind(CGF); + if (Data.isValid()) + Data.unbind(CGF); } }; @@ -1534,13 +1535,13 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::DenseMap EscapedLocals; /// LabelMap - This keeps track of the LLVM basic block for each C label. - llvm::DenseMap LabelMap; + llvm::DenseMap LabelMap; // BreakContinueStack - This keeps track of where break and continue // statements should jump to. struct BreakContinue { BreakContinue(JumpDest Break, JumpDest Continue) - : BreakBlock(Break), ContinueBlock(Continue) {} + : BreakBlock(Break), ContinueBlock(Continue) {} JumpDest BreakBlock; JumpDest ContinueBlock; @@ -1716,12 +1717,9 @@ class CodeGenFunction : public CodeGenTypeCache { /// Get the profiler's current count. This is generally the count for the most /// recently incremented counter. - uint64_t getCurrentProfileCount() { - return PGO.getCurrentRegionCount(); - } + uint64_t getCurrentProfileCount() { return PGO.getCurrentRegionCount(); } private: - /// SwitchInsn - This is nearest current switch instruction. It is null if /// current context is not in a switch. llvm::SwitchInst *SwitchInsn = nullptr; @@ -1746,7 +1744,7 @@ class CodeGenFunction : public CodeGenTypeCache { // multiple VLA types can share the same size expression. // FIXME: Maybe this could be a stack of maps that is pushed/popped as we // enter/leave scopes. - llvm::DenseMap VLASizeMap; + llvm::DenseMap VLASizeMap; /// A block containing a single 'unreachable' instruction. Created /// lazily by getUnreachableBlock(). @@ -1788,7 +1786,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this' /// is overridden to be the object under construction. - class CXXDefaultInitExprScope { + class CXXDefaultInitExprScope { public: CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E) : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue), @@ -1819,12 +1817,10 @@ class CodeGenFunction : public CodeGenTypeCache { class ArrayInitLoopExprScope { public: ArrayInitLoopExprScope(CodeGenFunction &CGF, llvm::Value *Index) - : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) { + : CGF(CGF), OldArrayInitIndex(CGF.ArrayInitIndex) { CGF.ArrayInitIndex = Index; } - ~ArrayInitLoopExprScope() { - CGF.ArrayInitIndex = OldArrayInitIndex; - } + ~ArrayInitLoopExprScope() { CGF.ArrayInitIndex = OldArrayInitIndex; } private: CodeGenFunction &CGF; @@ -2151,7 +2147,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn); public: - CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); + CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext = false); ~CodeGenFunction(); CodeGenTypes &getTypes() const { return CGM.getTypes(); } @@ -2191,7 +2187,8 @@ class CodeGenFunction : public CodeGenTypeCache { } llvm::BasicBlock *getInvokeDest() { - if (!EHStack.requiresLandingPad()) return nullptr; + if (!EHStack.requiresLandingPad()) + return nullptr; return getInvokeDestImpl(); } @@ -2220,10 +2217,10 @@ class CodeGenFunction : public CodeGenTypeCache { CharUnits elementAlignment, Destroyer *destroyer); - void pushDestroy(QualType::DestructionKind dtorKind, - Address addr, QualType type); - void pushEHDestroy(QualType::DestructionKind dtorKind, - Address addr, QualType type); + void pushDestroy(QualType::DestructionKind dtorKind, Address addr, + QualType type); + void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, + QualType type); void pushDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray); void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, @@ -2248,8 +2245,8 @@ class CodeGenFunction : public CodeGenTypeCache { const VarDecl *VD); void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, - Destroyer *destroyer, - bool checkZeroLength, bool useEHCleanup); + Destroyer *destroyer, bool checkZeroLength, + bool useEHCleanup); Destroyer *getDestroyer(QualType::DestructionKind destructionKind); @@ -2311,8 +2308,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// captured variables, etc. llvm::Value *EmitBlockLiteral(const BlockExpr *); - llvm::Function *GenerateBlockFunction(GlobalDecl GD, - const CGBlockInfo &Info, + llvm::Function *GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info, const DeclMapTy &ldm, bool IsLambdaConversionToBlock, bool BuildGlobalBlock); @@ -2322,10 +2318,10 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); - llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( - const ObjCPropertyImplDecl *PID); - llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( - const ObjCPropertyImplDecl *PID); + llvm::Constant * + GenerateObjCAtomicSetterCopyHelperFunction(const ObjCPropertyImplDecl *PID); + llvm::Constant * + GenerateObjCAtomicGetterCopyHelperFunction(const ObjCPropertyImplDecl *PID); llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, @@ -2364,10 +2360,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// data in a variable which is declared as __block. Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward = true); - Address emitBlockByrefAddress(Address baseAddr, - const BlockByrefInfo &info, - bool followForward, - const llvm::Twine &name); + Address emitBlockByrefAddress(Address baseAddr, const BlockByrefInfo &info, + bool followForward, const llvm::Twine &name); const BlockByrefInfo &getBlockByrefInfo(const VarDecl *var); @@ -2383,11 +2377,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// Emit code for the start of a function. /// \param Loc The location to be associated with the function. /// \param StartLoc The location of the function body. - void StartFunction(GlobalDecl GD, - QualType RetTy, - llvm::Function *Fn, - const CGFunctionInfo &FnInfo, - const FunctionArgList &Args, + void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, + const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc = SourceLocation(), SourceLocation StartLoc = SourceLocation()); @@ -2424,7 +2415,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// FinishFunction - Complete IR generation of the current function. It is /// legal to call this function even if there is no current insertion point. - void FinishFunction(SourceLocation EndLoc=SourceLocation()); + void FinishFunction(SourceLocation EndLoc = SourceLocation()); void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo, bool IsUnprototyped); @@ -2567,8 +2558,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitFunctionProlog - Emit the target specific LLVM code to load the /// arguments for the given function. This is also responsible for naming the /// LLVM function arguments. - void EmitFunctionProlog(const CGFunctionInfo &FI, - llvm::Function *Fn, + void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args); /// EmitFunctionEpilog - Emit the target specific LLVM code to return the @@ -2647,7 +2637,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// IsFinished - If true, indicates that the caller has finished emitting /// branches to the given block and does not expect to emit code into it. This /// means the block can be ignored if it is unreachable. - void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); + void EmitBlock(llvm::BasicBlock *BB, bool IsFinished = false); /// EmitBlockAfterUses - Emit the given block somewhere hopefully /// near its uses, and leave the insertion point in it. @@ -2665,9 +2655,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// HaveInsertPoint - True if an insertion point is defined. If not, this /// indicates that the current code being emitted is unreachable. - bool HaveInsertPoint() const { - return Builder.GetInsertBlock() != nullptr; - } + bool HaveInsertPoint() const { return Builder.GetInsertBlock() != nullptr; } /// EnsureInsertPoint - Ensure that an insertion point is defined so that /// emitted IR has a place to go. Note that by definition, if this function @@ -2768,9 +2756,9 @@ class CodeGenFunction : public CodeGenTypeCache { LValueBaseInfo *PointeeBaseInfo = nullptr, TBAAAccessInfo *PointeeTBAAInfo = nullptr); LValue EmitLoadOfReferenceLValue(LValue RefLVal); - LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, - AlignmentSource Source = - AlignmentSource::Type) { + LValue + EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, + AlignmentSource Source = AlignmentSource::Type) { LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source), CGM.getTBAAAccessInfo(RefTy)); return EmitLoadOfReferenceLValue(RefLVal); @@ -2914,7 +2902,8 @@ class CodeGenFunction : public CodeGenTypeCache { const CGBitFieldInfo &Info, SourceLocation Loc); - /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. + /// EmitIgnoredExpr - Emit an expression in a context which ignores the + /// result. void EmitIgnoredExpr(const Expr *E); /// EmitAnyExpr - Emit code to compute the specified expression which can have @@ -2942,8 +2931,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitAnyExprToMem - Emits the code necessary to evaluate an /// arbitrary expression into the given memory location. - void EmitAnyExprToMem(const Expr *E, Address Location, - Qualifiers Quals, bool IsInitializer); + void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, + bool IsInitializer); void EmitAnyExprToExn(const Expr *E, Address Addr); @@ -3061,8 +3050,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// emitArrayLength - Compute the length of an array, even if it's a /// VLA, and drill down to the base element type. - llvm::Value *emitArrayLength(const ArrayType *arrayType, - QualType &baseType, + llvm::Value *emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr); /// EmitVLASize - Capture all the sizes for the VLA expressions in @@ -3109,24 +3097,21 @@ class CodeGenFunction : public CodeGenTypeCache { /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a /// complete class to the given direct base. - Address - GetAddressOfDirectBaseInCompleteClass(Address Value, - const CXXRecordDecl *Derived, - const CXXRecordDecl *Base, - bool BaseIsVirtual); + Address GetAddressOfDirectBaseInCompleteClass(Address Value, + const CXXRecordDecl *Derived, + const CXXRecordDecl *Base, + bool BaseIsVirtual); static bool ShouldNullCheckClassCastValue(const CastExpr *Cast); /// GetAddressOfBaseClass - This function will add the necessary delta to the /// load of 'this' and returns address of the base class. - Address GetAddressOfBaseClass(Address Value, - const CXXRecordDecl *Derived, + Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc); - Address GetAddressOfDerivedClass(Address Value, - const CXXRecordDecl *Derived, + Address GetAddressOfDerivedClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue); @@ -3185,20 +3170,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Emit assumption that vptr load == global vtable. void EmitVTableAssumptionLoad(const VPtr &vptr, Address This); - void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, - Address This, Address Src, - const CXXConstructExpr *E); + void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, Address This, + Address Src, const CXXConstructExpr *E); void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, - const ArrayType *ArrayTy, - Address ArrayPtr, + const ArrayType *ArrayTy, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization = false); void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, - llvm::Value *NumElements, - Address ArrayPtr, + llvm::Value *NumElements, Address ArrayPtr, const CXXConstructExpr *E, bool NewPointerIsChecked, bool ZeroInitialization = false); @@ -3342,7 +3324,6 @@ class CodeGenFunction : public CodeGenTypeCache { /// Get the record field index as represented in debug info. unsigned getDebugInfoFIndex(const RecordDecl *Rec, unsigned FieldIndex); - //===--------------------------------------------------------------------===// // Declaration Emission //===--------------------------------------------------------------------===// @@ -3426,9 +3407,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// Returns the raw, allocated address, which is not necessarily /// the address of the object itself. It is casted to default /// address space for address space agnostic languages. - Address getAllocatedAddress() const { - return Addr; - } + Address getAllocatedAddress() const { return Addr; } /// Returns the address for the original alloca instruction. RawAddress getOriginalAllocatedAddress() const { return AllocaAddr; } @@ -3437,7 +3416,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// Note that this does not chase the forwarding pointer for /// __block decls. Address getObjectAddress(CodeGenFunction &CGF) const { - if (!IsEscapingByRef) return Addr; + if (!IsEscapingByRef) + return Addr; return CGF.emitBlockByrefAddress(Addr, Variable, /*forward*/ false); } @@ -3453,8 +3433,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// QualTypes and size expression's debug node, so that CGDebugInfo can /// reference this node when creating the DISubrange object to describe the /// array types. - void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, - const VarDecl &D, + void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, const VarDecl &D, bool EmitDebugInfo); void EmitStaticVarDecl(const VarDecl &D, @@ -3557,10 +3536,9 @@ class CodeGenFunction : public CodeGenTypeCache { Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, AggValueSlot AVS = AggValueSlot::ignored()); - Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, - bool GetLast = false, - AggValueSlot AVS = - AggValueSlot::ignored()); + Address + EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast = false, + AggValueSlot AVS = AggValueSlot::ignored()); /// EmitLabel - Emit the block for the given label. It is legal to call this /// function even if there is no current insertion point. @@ -3614,8 +3592,7 @@ class CodeGenFunction : public CodeGenTypeCache { void VolatilizeTryBlocks(llvm::BasicBlock *BB, llvm::SmallPtrSet &V); - void pushSEHCleanup(CleanupKind kind, - llvm::Function *FinallyFunc); + void pushSEHCleanup(CleanupKind kind, llvm::Function *FinallyFunc); void startOutlinedSEHHelper(CodeGenFunction &ParentCGF, bool IsFilter, const Stmt *OutlinedStmt); @@ -3626,8 +3603,7 @@ class CodeGenFunction : public CodeGenTypeCache { const SEHFinallyStmt &Finally); void EmitSEHExceptionCodeSave(CodeGenFunction &ParentCGF, - llvm::Value *ParentFP, - llvm::Value *EntryEBP); + llvm::Value *ParentFP, llvm::Value *EntryEBP); llvm::Value *EmitSEHExceptionCode(); llvm::Value *EmitSEHExceptionInfo(); llvm::Value *EmitSEHAbnormalTermination(); @@ -3647,8 +3623,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// outlined functions. ParentFP is the frame pointer of the outermost parent /// frame. Address recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, - Address ParentVar, - llvm::Value *ParentFP); + Address ParentVar, llvm::Value *ParentFP); void EmitCXXForRangeStmt(const CXXForRangeStmt &S, ArrayRef Attrs = {}); @@ -3701,8 +3676,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// the base array element). /// \param Copy Actual copygin expression for copying data from \a SrcVD to \a /// DestVD. - void EmitOMPCopy(QualType OriginalType, - Address DestAddr, Address SrcAddr, + void EmitOMPCopy(QualType OriginalType, Address DestAddr, Address SrcAddr, const VarDecl *DestVD, const VarDecl *SrcVD, const Expr *Copy); /// Emit atomic update code for constructs: \a X = \a X \a BO \a E or @@ -3828,10 +3802,8 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitOMPTargetTaskBasedDirective(const OMPExecutableDirective &S, const RegionCodeGenTy &BodyGen, OMPTargetDataInfo &InputInfo); - void processInReduction(const OMPExecutableDirective &S, - OMPTaskDataTy &Data, - CodeGenFunction &CGF, - const CapturedStmt *CS, + void processInReduction(const OMPExecutableDirective &S, OMPTaskDataTy &Data, + CodeGenFunction &CGF, const CapturedStmt *CS, OMPPrivateScope &Scope); void EmitOMPMetaDirective(const OMPMetaDirective &S); void EmitOMPParallelDirective(const OMPParallelDirective &S); @@ -4187,13 +4159,11 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E /// and issue an ErrorUnsupported style diagnostic (using the /// provided Name). - RValue EmitUnsupportedRValue(const Expr *E, - const char *Name); + RValue EmitUnsupportedRValue(const Expr *E, const char *Name); /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue /// an ErrorUnsupported style diagnostic (using the provided Name). - LValue EmitUnsupportedLValue(const Expr *E, - const char *Name); + LValue EmitUnsupportedLValue(const Expr *E, const char *Name); /// EmitLValue - Emit code to compute a designator that specifies the location /// of the expression. @@ -4223,8 +4193,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// that the address will be used to access the object. LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); - RValue convertTempToRValue(Address addr, QualType type, - SourceLocation Loc); + RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc); void EmitAtomicInit(Expr *E, LValue lvalue); @@ -4302,25 +4271,26 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitStoreOfScalar - Store a scalar value to an address, taking /// care to appropriately convert from the memory representation to /// the LLVM value representation. - void EmitStoreOfScalar(llvm::Value *Value, Address Addr, - bool Volatile, QualType Ty, + void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, + QualType Ty, AlignmentSource Source = AlignmentSource::Type, bool isInit = false, bool isNontemporal = false) { EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source), CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal); } - void EmitStoreOfScalar(llvm::Value *Value, Address Addr, - bool Volatile, QualType Ty, - LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo, - bool isInit = false, bool isNontemporal = false); + void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, + QualType Ty, LValueBaseInfo BaseInfo, + TBAAAccessInfo TBAAInfo, bool isInit = false, + bool isNontemporal = false); /// EmitStoreOfScalar - Store a scalar value to an address, taking /// care to appropriately convert from the memory representation to /// the LLVM value representation. The l-value must be a simple /// l-value. The isInit flag indicates whether this is an initialization. /// If so, atomic qualifiers are ignored and the store is always non-atomic. - void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); + void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, + bool isInit = false); /// EmitLoadOfLValue - Given an expression that represents a value lvalue, /// this method emits the address of the lvalue, then loads the result as an @@ -4349,7 +4319,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// bit-field contents after the store, appropriate for use as the result of /// an assignment to the bit-field. void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, - llvm::Value **Result=nullptr); + llvm::Value **Result = nullptr); /// Emit an l-value for an assignment (simple or compound) of complex type. LValue EmitComplexAssignmentLValue(const BinaryOperator *E); @@ -4402,9 +4372,10 @@ class CodeGenFunction : public CodeGenTypeCache { TBAAAccessInfo *TBAAInfo = nullptr); class ConstantEmission { - llvm::PointerIntPair ValueAndIsReference; + llvm::PointerIntPair ValueAndIsReference; ConstantEmission(llvm::Constant *C, bool isReference) - : ValueAndIsReference(C, isReference) {} + : ValueAndIsReference(C, isReference) {} + public: ConstantEmission() {} static ConstantEmission forReference(llvm::Constant *C) { @@ -4448,7 +4419,7 @@ class CodeGenFunction : public CodeGenTypeCache { const ObjCIvarDecl *Ivar); llvm::Value *EmitIvarOffsetAsPointerDiff(const ObjCInterfaceDecl *Interface, const ObjCIvarDecl *Ivar); - LValue EmitLValueForField(LValue Base, const FieldDecl* Field); + LValue EmitLValueForField(LValue Base, const FieldDecl *Field); LValue EmitLValueForLambdaField(const FieldDecl *Field); LValue EmitLValueForLambdaField(const FieldDecl *Field, llvm::Value *ThisValue); @@ -4456,12 +4427,10 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that /// if the Field is a reference, this will return the address of the reference /// and not the address of the value stored in the reference. - LValue EmitLValueForFieldInitialization(LValue Base, - const FieldDecl* Field); + LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field); - LValue EmitLValueForIvar(QualType ObjectTy, - llvm::Value* Base, const ObjCIvarDecl *Ivar, - unsigned CVRQualifiers); + LValue EmitLValueForIvar(QualType ObjectTy, llvm::Value *Base, + const ObjCIvarDecl *Ivar, unsigned CVRQualifiers); LValue EmitCXXConstructLValue(const CXXConstructExpr *E); LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); @@ -4473,7 +4442,7 @@ class CodeGenFunction : public CodeGenTypeCache { LValue EmitStmtExprLValue(const StmtExpr *E); LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); - void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init); + void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init); //===--------------------------------------------------------------------===// // Scalar Expression Emission @@ -4540,8 +4509,7 @@ class CodeGenFunction : public CodeGenTypeCache { ArrayRef args); CGCallee BuildAppleKextVirtualCall(const CXXMethodDecl *MD, - NestedNameSpecifier *Qual, - llvm::Type *Ty); + NestedNameSpecifier *Qual, llvm::Type *Ty); CGCallee BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, CXXDtorType Type, @@ -4627,11 +4595,10 @@ class CodeGenFunction : public CodeGenTypeCache { bool HasQualifier, NestedNameSpecifier *Qualifier, bool IsArrow, const Expr *Base, llvm::CallBase **CallOrInvoke); // Compute the object pointer. - Address EmitCXXMemberDataPointerAddress(const Expr *E, Address base, - llvm::Value *memberPtr, - const MemberPointerType *memberPtrType, - LValueBaseInfo *BaseInfo = nullptr, - TBAAAccessInfo *TBAAInfo = nullptr); + Address EmitCXXMemberDataPointerAddress( + const Expr *E, Address base, llvm::Value *memberPtr, + const MemberPointerType *memberPtrType, + LValueBaseInfo *BaseInfo = nullptr, TBAAAccessInfo *TBAAInfo = nullptr); RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, ReturnValueSlot ReturnValue, llvm::CallBase **CallOrInvoke); @@ -4692,22 +4659,18 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Value *EmitCMSEClearRecord(llvm::Value *V, llvm::ArrayType *ATy, QualType RTy); - llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID, - unsigned LLVMIntrinsic, - unsigned AltLLVMIntrinsic, - const char *NameHint, - unsigned Modifier, - const CallExpr *E, - SmallVectorImpl &Ops, - Address PtrOp0, Address PtrOp1, - llvm::Triple::ArchType Arch); + llvm::Value * + EmitCommonNeonBuiltinExpr(unsigned BuiltinID, unsigned LLVMIntrinsic, + unsigned AltLLVMIntrinsic, const char *NameHint, + unsigned Modifier, const CallExpr *E, + SmallVectorImpl &Ops, Address PtrOp0, + Address PtrOp1, llvm::Triple::ArchType Arch); llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID, unsigned Modifier, llvm::Type *ArgTy, const CallExpr *E); llvm::Value *EmitNeonCall(llvm::Function *F, - SmallVectorImpl &O, - const char *name, + SmallVectorImpl &O, const char *name, unsigned shift = 0, bool rightshift = false); llvm::Value *EmitFP8NeonCall(unsigned IID, ArrayRef Tys, SmallVectorImpl &O, @@ -4811,7 +4774,7 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Triple::ArchType Arch); llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E); - llvm::Value *BuildVector(ArrayRef Ops); + llvm::Value *BuildVector(ArrayRef Ops); llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E); @@ -4850,8 +4813,9 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); - llvm::Value *EmitObjCCollectionLiteral(const Expr *E, - const ObjCMethodDecl *MethodWithObjects); + llvm::Value * + EmitObjCCollectionLiteral(const Expr *E, + const ObjCMethodDecl *MethodWithObjects); llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return = ReturnValueSlot()); @@ -4859,8 +4823,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// Retrieves the default cleanup kind for an ARC cleanup. /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. CleanupKind getARCCleanupKind() { - return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions - ? NormalAndEHCleanup : NormalCleanup; + return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions ? NormalAndEHCleanup + : NormalCleanup; } // ARC primitives. @@ -4895,15 +4859,14 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Type *returnType); void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); - std::pair + std::pair EmitARCStoreAutoreleasing(const BinaryOperator *e); - std::pair - EmitARCStoreStrong(const BinaryOperator *e, bool ignored); - std::pair + std::pair EmitARCStoreStrong(const BinaryOperator *e, + bool ignored); + std::pair EmitARCStoreUnsafeUnretained(const BinaryOperator *e, bool ignored); - llvm::Value *EmitObjCAlloc(llvm::Value *value, - llvm::Type *returnType); + llvm::Value *EmitObjCAlloc(llvm::Value *value, llvm::Type *returnType); llvm::Value *EmitObjCAllocWithZone(llvm::Value *value, llvm::Type *returnType); llvm::Value *EmitObjCAllocInit(llvm::Value *value, llvm::Type *resultType); @@ -4919,7 +4882,7 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); llvm::Value *EmitARCUnsafeUnretainedScalarExpr(const Expr *expr); - void EmitARCIntrinsicUse(ArrayRef values); + void EmitARCIntrinsicUse(ArrayRef values); void EmitARCNoopIntrinsicUse(ArrayRef values); @@ -4946,7 +4909,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitScalarExpr - Emit the computation of the specified expression of LLVM /// scalar type, returning the result. - llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); + llvm::Value *EmitScalarExpr(const Expr *E, bool IgnoreResultAssign = false); /// Emit a conversion from the specified type to the specified destination /// type, both of which are LLVM scalar types. @@ -4986,8 +4949,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// EmitComplexExpr - Emit the computation of the specified expression of /// complex type, returning the result. - ComplexPairTy EmitComplexExpr(const Expr *E, - bool IgnoreReal = false, + ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal = false, bool IgnoreImag = false); /// EmitComplexExprIntoLValue - Emit the given expression of complex @@ -5003,7 +4965,8 @@ class CodeGenFunction : public CodeGenTypeCache { ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType); llvm::Value *EmitPromotedScalarExpr(const Expr *E, QualType PromotionType); ComplexPairTy EmitPromotedValue(ComplexPairTy result, QualType PromotionType); - ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType); + ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, + QualType PromotionType); Address emitAddrOfRealComponent(Address complex, QualType complexType); Address emitAddrOfImagComponent(Address complex, QualType complexType); @@ -5012,9 +4975,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// global variable that has already been created for it. If the initializer /// has a different type than GV does, this may free GV and return a different /// one. Otherwise it just returns GV. - llvm::GlobalVariable * - AddInitializerToStaticVarDecl(const VarDecl &D, - llvm::GlobalVariable *GV); + llvm::GlobalVariable *AddInitializerToStaticVarDecl(const VarDecl &D, + llvm::GlobalVariable *GV); // Emit an @llvm.invariant.start call for the given memory region. void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size); @@ -5061,8 +5023,8 @@ class CodeGenFunction : public CodeGenTypeCache { /// Emit a branch to select whether or not to perform guarded initialization. void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, llvm::BasicBlock *InitBlock, - llvm::BasicBlock *NoInitBlock, - GuardKind Kind, const VarDecl *D); + llvm::BasicBlock *NoInitBlock, GuardKind Kind, + const VarDecl *D); /// GenerateCXXGlobalInitFunc - Generates code for initializing global /// variables. @@ -5079,8 +5041,7 @@ class CodeGenFunction : public CodeGenTypeCache { llvm::Constant *>> DtorsOrStermFinalizers); - void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, - const VarDecl *D, + void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit); @@ -5185,8 +5146,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// is a subtraction. llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr, ArrayRef IdxList, - bool SignedIndices, - bool IsSubtraction, + bool SignedIndices, bool IsSubtraction, SourceLocation Loc, const Twine &Name = ""); @@ -5369,8 +5329,7 @@ class CodeGenFunction : public CodeGenTypeCache { /// if E is a parameter with the pass_object_size attribute. llvm::Value *emitBuiltinObjectSize(const Expr *E, unsigned Type, llvm::IntegerType *ResType, - llvm::Value *EmittedE, - bool IsDynamic); + llvm::Value *EmittedE, bool IsDynamic); llvm::Value *emitCountedByMemberSize(const Expr *E, llvm::Value *EmittedE, unsigned Type, @@ -5461,7 +5420,7 @@ class CodeGenFunction : public CodeGenTypeCache { void EmitDeclMetadata(); BlockByrefHelpers *buildByrefHelpers(llvm::StructType &byrefType, - const AutoVarEmission &emission); + const AutoVarEmission &emission); void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); @@ -5481,7 +5440,8 @@ class CodeGenFunction : public CodeGenTypeCache { inline DominatingLLVMValue::saved_type DominatingLLVMValue::save(CodeGenFunction &CGF, llvm::Value *value) { - if (!needsSaving(value)) return saved_type(value, false); + if (!needsSaving(value)) + return saved_type(value, false); // Otherwise, we need an alloca. auto align = CharUnits::fromQuantity( @@ -5496,7 +5456,8 @@ DominatingLLVMValue::save(CodeGenFunction &CGF, llvm::Value *value) { inline llvm::Value *DominatingLLVMValue::restore(CodeGenFunction &CGF, saved_type value) { // If the value says it wasn't saved, trust that it's still dominating. - if (!value.getInt()) return value.getPointer(); + if (!value.getInt()) + return value.getPointer(); // Otherwise, it should be an alloca instruction, as set up in save(). auto alloca = cast(value.getPointer()); @@ -5504,12 +5465,12 @@ inline llvm::Value *DominatingLLVMValue::restore(CodeGenFunction &CGF, alloca->getAlign()); } -} // end namespace CodeGen +} // end namespace CodeGen // Map the LangOption for floating point exception behavior into // the corresponding enum in the IR. llvm::fp::ExceptionBehavior ToConstrainedExceptMD(LangOptions::FPExceptionModeKind Kind); -} // end namespace clang +} // end namespace clang #endif