From 6a677017f4aacee6399cf1d4ad7817e650f86f40 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 12 Aug 2007 08:12:35 +0000 Subject: Change casts from old style to new style. This helps document the details better, gives the compiler a chance to validate the cast and reduces warnings if the user turns on -Wold-style-cast option. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41033 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/DenseMap.h | 20 ++++++++++---------- include/llvm/ADT/SmallVector.h | 11 +++++++---- include/llvm/Analysis/Dominators.h | 4 ++-- include/llvm/Analysis/LoopInfo.h | 2 +- include/llvm/Assembly/PrintModulePass.h | 9 +++++---- include/llvm/GlobalValue.h | 2 +- include/llvm/Pass.h | 2 +- include/llvm/PassManagers.h | 2 +- include/llvm/PassSupport.h | 8 ++++---- include/llvm/SymbolTableListTraits.h | 2 +- include/llvm/Target/TargetData.h | 6 +++--- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index fd3f346..ed74129 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -32,11 +32,11 @@ struct DenseMapKeyInfo { // Provide DenseMapKeyInfo for all pointers. template struct DenseMapKeyInfo { - static inline T* getEmptyKey() { return (T*)-1; } - static inline T* getTombstoneKey() { return (T*)-2; } + static inline T* getEmptyKey() { return reinterpret_cast(-1); } + static inline T* getTombstoneKey() { return reinterpret_cast(-2); } static unsigned getHashValue(const T *PtrVal) { - return (unsigned)((uintptr_t)PtrVal >> 4) ^ - (unsigned)((uintptr_t)PtrVal >> 9); + return (unsigned(uintptr_t(PtrVal)) >> 4) ^ + (unsigned(uintptr_t(PtrVal)) >> 9); } static bool isPod() { return true; } }; @@ -69,7 +69,7 @@ public: P->second.~ValueT(); P->first.~KeyT(); } - delete[] (char*)Buckets; + delete[] reinterpret_cast(Buckets); } typedef DenseMapIterator iterator; @@ -258,7 +258,7 @@ private: NumBuckets = InitBuckets; assert(InitBuckets && (InitBuckets & InitBuckets-1) == 0 && "# initial buckets must be a power of two!"); - Buckets = (BucketT*)new char[sizeof(BucketT)*InitBuckets]; + Buckets = reinterpret_cast(new char[sizeof(BucketT)*InitBuckets]); // Initialize all the keys to EmptyKey. const KeyT EmptyKey = getEmptyKey(); for (unsigned i = 0; i != InitBuckets; ++i) @@ -272,7 +272,7 @@ private: // Double the number of buckets. NumBuckets <<= 1; NumTombstones = 0; - Buckets = (BucketT*)new char[sizeof(BucketT)*NumBuckets]; + Buckets = reinterpret_cast(new char[sizeof(BucketT)*NumBuckets]); // Initialize all the keys to EmptyKey. const KeyT EmptyKey = getEmptyKey(); @@ -298,7 +298,7 @@ private: } // Free the old table. - delete[] (char*)OldBuckets; + delete[] reinterpret_cast(OldBuckets); } void shrink_and_clear() { @@ -309,7 +309,7 @@ private: NumBuckets = NumEntries > 32 ? 1 << (Log2_32_Ceil(NumEntries) + 1) : 64; NumTombstones = 0; - Buckets = (BucketT*)new char[sizeof(BucketT)*NumBuckets]; + Buckets = reinterpret_cast(new char[sizeof(BucketT)*NumBuckets]); // Initialize all the keys to EmptyKey. const KeyT EmptyKey = getEmptyKey(); @@ -327,7 +327,7 @@ private: } // Free the old table. - delete[] (char*)OldBuckets; + delete[] reinterpret_cast(OldBuckets); NumEntries = 0; } diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index e6c81a6..dfb7616 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -73,7 +73,9 @@ protected: public: // Default ctor - Initialize to empty. SmallVectorImpl(unsigned N) - : Begin((T*)&FirstEl), End((T*)&FirstEl), Capacity((T*)&FirstEl+N) { + : Begin(reinterpret_cast(&FirstEl)), + End(reinterpret_cast(&FirstEl)), + Capacity(reinterpret_cast(&FirstEl)+N) { } ~SmallVectorImpl() { @@ -82,7 +84,7 @@ public: // If this wasn't grown from the inline copy, deallocate the old space. if (!isSmall()) - delete[] (char*)Begin; + delete[] reinterpret_cast(Begin); } typedef size_t size_type; @@ -285,7 +287,8 @@ private: /// isSmall - Return true if this is a smallvector which has not had dynamic /// memory allocated for it. bool isSmall() const { - return (void*)Begin == (void*)&FirstEl; + return reinterpret_cast(Begin) == + reinterpret_cast(&FirstEl); } /// grow - double the size of the allocated memory, guaranteeing space for at @@ -323,7 +326,7 @@ void SmallVectorImpl::grow(unsigned MinSize) { // If this wasn't grown from the inline copy, deallocate the old space. if (!isSmall()) - delete[] (char*)Begin; + delete[] reinterpret_cast(Begin); Begin = NewElts; End = NewElts+CurSize; diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index a57f17b..dfb73bd 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -282,7 +282,7 @@ protected: class DominatorTree : public DominatorTreeBase { public: static char ID; // Pass ID, replacement for typeid - DominatorTree() : DominatorTreeBase((intptr_t)&ID, false) {} + DominatorTree() : DominatorTreeBase(intptr_t(&ID), false) {} BasicBlock *getRoot() const { assert(Roots.size() == 1 && "Should always have entry node!"); @@ -399,7 +399,7 @@ class DominanceFrontier : public DominanceFrontierBase { public: static char ID; // Pass ID, replacement for typeid DominanceFrontier() : - DominanceFrontierBase((intptr_t)& ID, false) {} + DominanceFrontierBase(intptr_t(&ID), false) {} BasicBlock *getRoot() const { assert(Roots.size() == 1 && "Should always have entry node!"); diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 07fa2f3..54d7236 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -246,7 +246,7 @@ class LoopInfo : public FunctionPass { public: static char ID; // Pass identification, replacement for typeid - LoopInfo() : FunctionPass((intptr_t)&ID) {} + LoopInfo() : FunctionPass(intptr_t(&ID)) {} ~LoopInfo() { releaseMemory(); } /// iterator/begin/end - The interface to the top-level loops in the current diff --git a/include/llvm/Assembly/PrintModulePass.h b/include/llvm/Assembly/PrintModulePass.h index 0f65235..ed70e9d 100644 --- a/include/llvm/Assembly/PrintModulePass.h +++ b/include/llvm/Assembly/PrintModulePass.h @@ -29,9 +29,10 @@ class PrintModulePass : public ModulePass { bool DeleteStream; // Delete the ostream in our dtor? public: static char ID; - PrintModulePass() : ModulePass((intptr_t)&ID), Out(&cerr), DeleteStream(false) {} + PrintModulePass() : ModulePass(intptr_t(&ID)), Out(&cerr), + DeleteStream(false) {} PrintModulePass(OStream *o, bool DS = false) - : ModulePass((intptr_t)&ID), Out(o), DeleteStream(DS) {} + : ModulePass(intptr_t(&ID)), Out(o), DeleteStream(DS) {} ~PrintModulePass() { if (DeleteStream) delete Out; @@ -53,11 +54,11 @@ class PrintFunctionPass : public FunctionPass { bool DeleteStream; // Delete the ostream in our dtor? public: static char ID; - PrintFunctionPass() : FunctionPass((intptr_t)&ID), Banner(""), Out(&cerr), + PrintFunctionPass() : FunctionPass(intptr_t(&ID)), Banner(""), Out(&cerr), DeleteStream(false) {} PrintFunctionPass(const std::string &B, OStream *o = &cout, bool DS = false) - : FunctionPass((intptr_t)&ID), Banner(B), Out(o), DeleteStream(DS) {} + : FunctionPass(intptr_t(&ID)), Banner(B), Out(o), DeleteStream(DS) {} inline ~PrintFunctionPass() { if (DeleteStream) delete Out; diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index 6735cb5..fe43ed4 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -74,7 +74,7 @@ public: Alignment = Align; } - VisibilityTypes getVisibility() const { return (VisibilityTypes)Visibility; } + VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); } bool hasHiddenVisibility() const { return Visibility == HiddenVisibility; } bool hasProtectedVisibility() const { return Visibility == ProtectedVisibility; diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index ea129e0..e38ee8f 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -170,7 +170,7 @@ public: template static const PassInfo *getClassPassInfo() { - return lookupPassInfo((intptr_t)&AnalysisClass::ID); + return lookupPassInfo(intptr_t(&AnalysisClass::ID)); } // lookupPassInfo - Return the pass info object for the specified pass class, diff --git a/include/llvm/PassManagers.h b/include/llvm/PassManagers.h index bcdea2b..b740f81 100644 --- a/include/llvm/PassManagers.h +++ b/include/llvm/PassManagers.h @@ -341,7 +341,7 @@ class FPPassManager : public ModulePass, public PMDataManager { public: static char ID; explicit FPPassManager(int Depth) - : ModulePass((intptr_t)&ID), PMDataManager(Depth) { } + : ModulePass(intptr_t(&ID)), PMDataManager(Depth) { } /// run - Execute all of the passes scheduled for execution. Keep track of /// whether any of the passes modifies the module, and if so, return true. diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h index f594d45..794b946 100644 --- a/include/llvm/PassSupport.h +++ b/include/llvm/PassSupport.h @@ -165,8 +165,8 @@ struct RegisterPass : public RegisterPassBase { // Register Pass using default constructor... RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false) - : RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID, - (RegisterPassBase::NormalCtor_t)callDefaultCtor, CFGOnly) { + : RegisterPassBase(Name, PassArg, intptr_t(&PassName::ID), + RegisterPassBase::NormalCtor_t(callDefaultCtor), CFGOnly) { } }; @@ -204,12 +204,12 @@ protected: template struct RegisterAnalysisGroup : public RegisterAGBase { explicit RegisterAnalysisGroup(RegisterPassBase &RPB) - : RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(), + : RegisterAGBase(intptr_t(&Interface::ID), RPB.getPassInfo()->getTypeInfo(), Default) { } explicit RegisterAnalysisGroup(const char *Name) - : RegisterAGBase((intptr_t) &Interface::ID) { + : RegisterAGBase(intptr_t(&Interface::ID)) { setGroupName(Name); } }; diff --git a/include/llvm/SymbolTableListTraits.h b/include/llvm/SymbolTableListTraits.h index 205b409..a78d27f 100644 --- a/include/llvm/SymbolTableListTraits.h +++ b/include/llvm/SymbolTableListTraits.h @@ -45,7 +45,7 @@ public: /// getListOwner - Return the object that owns this list. If this is a list /// of instructions, it returns the BasicBlock that owns them. ItemParentClass *getListOwner() { - return reinterpret_cast((char*)this- + return reinterpret_cast(reinterpret_cast(this)- TraitsClass::getListOffset()); } static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); } diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index b51b519..6003e60 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -108,7 +108,7 @@ public: /// /// @note This has to exist, because this is a pass, but it should never be /// used. - TargetData() : ImmutablePass((intptr_t)&ID) { + TargetData() : ImmutablePass(intptr_t(&ID)) { assert(0 && "ERROR: Bad TargetData ctor used. " "Tool did not specify a TargetData to use?"); abort(); @@ -116,7 +116,7 @@ public: /// Constructs a TargetData from a specification string. See init(). explicit TargetData(const std::string &TargetDescription) - : ImmutablePass((intptr_t)&ID) { + : ImmutablePass(intptr_t(&ID)) { init(TargetDescription); } @@ -124,7 +124,7 @@ public: explicit TargetData(const Module *M); TargetData(const TargetData &TD) : - ImmutablePass((intptr_t)&ID), + ImmutablePass(intptr_t(&ID)), LittleEndian(TD.isLittleEndian()), PointerMemSize(TD.PointerMemSize), PointerABIAlign(TD.PointerABIAlign), -- cgit v1.1