diff options
author | David Blaikie <dblaikie@gmail.com> | 2015-08-13 23:53:09 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2015-08-13 23:53:09 +0000 |
commit | 92551616656d77fb0cb54e2fb576f6aa0551588e (patch) | |
tree | 45b7bac5d231e0b846cc713285dcd934728dc8ee /clang/lib/CodeGen | |
parent | 2dcef9e0a41331f9645bd659ffa37b8da76cab28 (diff) | |
download | bcm5719-llvm-92551616656d77fb0cb54e2fb576f6aa0551588e.tar.gz bcm5719-llvm-92551616656d77fb0cb54e2fb576f6aa0551588e.zip |
Wdeprecated: ByrefHelpers are copy constructed by the ::buildByrefHelpers helper, make sure they're safely copyable
Make the copy/move ctors protected and defaulted in the base, make the
derived classes final to avoid exposing any slicing-prone APIs.
Also, while I'm here, simplify the use of buildByrefHelpers by taking
the parameter by value instead of non-const ref. None of the callers
care aobut observing the state after the call.
llvm-svn: 244990
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGBlocks.cpp | 44 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 1 |
2 files changed, 23 insertions, 22 deletions
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index f70fc4dc73a..c539312c294 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -1599,7 +1599,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { namespace { /// Emits the copy/dispose helper functions for a __block object of id type. -class ObjectByrefHelpers : public CodeGenModule::ByrefHelpers { +class ObjectByrefHelpers final : public CodeGenModule::ByrefHelpers { BlockFieldFlags Flags; public: @@ -1635,7 +1635,7 @@ public: }; /// Emits the copy/dispose helpers for an ARC __block __weak variable. -class ARCWeakByrefHelpers : public CodeGenModule::ByrefHelpers { +class ARCWeakByrefHelpers final : public CodeGenModule::ByrefHelpers { public: ARCWeakByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} @@ -1656,7 +1656,7 @@ public: /// Emits the copy/dispose helpers for an ARC __block __strong variable /// that's not of block-pointer type. -class ARCStrongByrefHelpers : public CodeGenModule::ByrefHelpers { +class ARCStrongByrefHelpers final : public CodeGenModule::ByrefHelpers { public: ARCStrongByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} @@ -1697,7 +1697,7 @@ public: /// Emits the copy/dispose helpers for an ARC __block __strong /// variable that's of block-pointer type. -class ARCStrongBlockByrefHelpers : public CodeGenModule::ByrefHelpers { +class ARCStrongBlockByrefHelpers final : public CodeGenModule::ByrefHelpers { public: ARCStrongBlockByrefHelpers(CharUnits alignment) : ByrefHelpers(alignment) {} @@ -1727,7 +1727,7 @@ public: /// Emits the copy/dispose helpers for a __block variable with a /// nontrivial copy constructor or destructor. -class CXXByrefHelpers : public CodeGenModule::ByrefHelpers { +class CXXByrefHelpers final : public CodeGenModule::ByrefHelpers { QualType VarType; const Expr *CopyExpr; @@ -1894,10 +1894,9 @@ static llvm::Constant *buildByrefDisposeHelper(CodeGenModule &CGM, /// Lazily build the copy and dispose helpers for a __block variable /// with the given information. -template <class T> static T *buildByrefHelpers(CodeGenModule &CGM, - llvm::StructType &byrefTy, - unsigned byrefValueIndex, - T &byrefInfo) { +template <class T> +static T *buildByrefHelpers(CodeGenModule &CGM, llvm::StructType &byrefTy, + unsigned byrefValueIndex, T byrefInfo) { // Increase the field's alignment to be at least pointer alignment, // since the layout of the byref struct will guarantee at least that. byrefInfo.Alignment = std::max(byrefInfo.Alignment, @@ -1916,7 +1915,7 @@ template <class T> static T *buildByrefHelpers(CodeGenModule &CGM, byrefInfo.DisposeHelper = buildByrefDisposeHelper(CGM, byrefTy, byrefValueIndex,byrefInfo); - T *copy = new (CGM.getContext()) T(byrefInfo); + T *copy = new (CGM.getContext()) T(std::move(byrefInfo)); CGM.ByrefHelpersCache.InsertNode(copy, insertPos); return copy; } @@ -1936,8 +1935,9 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, const Expr *copyExpr = CGM.getContext().getBlockVarCopyInits(&var); if (!copyExpr && record->hasTrivialDestructor()) return nullptr; - CXXByrefHelpers byrefInfo(emission.Alignment, type, copyExpr); - return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); + return ::buildByrefHelpers( + CGM, byrefType, byrefValueIndex, + CXXByrefHelpers(emission.Alignment, type, copyExpr)); } // Otherwise, if we don't have a retainable type, there's nothing to do. @@ -1960,24 +1960,24 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, // Tell the runtime that this is ARC __weak, called by the // byref routines. - case Qualifiers::OCL_Weak: { - ARCWeakByrefHelpers byrefInfo(emission.Alignment); - return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); - } + case Qualifiers::OCL_Weak: + return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, + ARCWeakByrefHelpers(emission.Alignment)); // ARC __strong __block variables need to be retained. case Qualifiers::OCL_Strong: // Block pointers need to be copied, and there's no direct // transfer possible. if (type->isBlockPointerType()) { - ARCStrongBlockByrefHelpers byrefInfo(emission.Alignment); - return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); + return ::buildByrefHelpers( + CGM, byrefType, byrefValueIndex, + ARCStrongBlockByrefHelpers(emission.Alignment)); // Otherwise, we transfer ownership of the retain from the stack // to the heap. } else { - ARCStrongByrefHelpers byrefInfo(emission.Alignment); - return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); + return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, + ARCStrongByrefHelpers(emission.Alignment)); } } llvm_unreachable("fell out of lifetime switch!"); @@ -1996,8 +1996,8 @@ CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType, if (type.isObjCGCWeak()) flags |= BLOCK_FIELD_IS_WEAK; - ObjectByrefHelpers byrefInfo(emission.Alignment, flags); - return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, byrefInfo); + return ::buildByrefHelpers(CGM, byrefType, byrefValueIndex, + ObjectByrefHelpers(emission.Alignment, flags)); } std::pair<llvm::Type *, unsigned> diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 848188d72a9..d87354595f9 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -766,6 +766,7 @@ public: CharUnits Alignment; ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} + ByrefHelpers(const ByrefHelpers &) = default; virtual ~ByrefHelpers(); void Profile(llvm::FoldingSetNodeID &id) const { |