[llvm-commits] [llvm] r41033 - in /llvm/trunk/include/llvm: ADT/DenseMap.h ADT/SmallVector.h Analysis/Dominators.h Analysis/LoopInfo.h Assembly/PrintModulePass.h GlobalValue.h Pass.h PassManagers.h PassSupport.h SymbolTableListTraits.h Target/TargetData.h

Reid Spencer rspencer at reidspencer.com
Sun Aug 12 01:12:37 PDT 2007


Author: reid
Date: Sun Aug 12 03:12:35 2007
New Revision: 41033

URL: http://llvm.org/viewvc/llvm-project?rev=41033&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/ADT/DenseMap.h
    llvm/trunk/include/llvm/ADT/SmallVector.h
    llvm/trunk/include/llvm/Analysis/Dominators.h
    llvm/trunk/include/llvm/Analysis/LoopInfo.h
    llvm/trunk/include/llvm/Assembly/PrintModulePass.h
    llvm/trunk/include/llvm/GlobalValue.h
    llvm/trunk/include/llvm/Pass.h
    llvm/trunk/include/llvm/PassManagers.h
    llvm/trunk/include/llvm/PassSupport.h
    llvm/trunk/include/llvm/SymbolTableListTraits.h
    llvm/trunk/include/llvm/Target/TargetData.h

Modified: llvm/trunk/include/llvm/ADT/DenseMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/DenseMap.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/DenseMap.h (original)
+++ llvm/trunk/include/llvm/ADT/DenseMap.h Sun Aug 12 03:12:35 2007
@@ -32,11 +32,11 @@
 // Provide DenseMapKeyInfo for all pointers.
 template<typename T>
 struct DenseMapKeyInfo<T*> {
-  static inline T* getEmptyKey() { return (T*)-1; }
-  static inline T* getTombstoneKey() { return (T*)-2; }
+  static inline T* getEmptyKey() { return reinterpret_cast<T*>(-1); }
+  static inline T* getTombstoneKey() { return reinterpret_cast<T*>(-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 @@
         P->second.~ValueT();
       P->first.~KeyT();
     }
-    delete[] (char*)Buckets;
+    delete[] reinterpret_cast<char*>(Buckets);
   }
   
   typedef DenseMapIterator<KeyT, ValueT, KeyInfoT> iterator;
@@ -258,7 +258,7 @@
     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<BucketT*>(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 @@
     // Double the number of buckets.
     NumBuckets <<= 1;
     NumTombstones = 0;
-    Buckets = (BucketT*)new char[sizeof(BucketT)*NumBuckets];
+    Buckets = reinterpret_cast<BucketT*>(new char[sizeof(BucketT)*NumBuckets]);
 
     // Initialize all the keys to EmptyKey.
     const KeyT EmptyKey = getEmptyKey();
@@ -298,7 +298,7 @@
     }
     
     // Free the old table.
-    delete[] (char*)OldBuckets;
+    delete[] reinterpret_cast<char*>(OldBuckets);
   }
   
   void shrink_and_clear() {
@@ -309,7 +309,7 @@
     NumBuckets = NumEntries > 32 ? 1 << (Log2_32_Ceil(NumEntries) + 1)
                                  : 64;
     NumTombstones = 0;
-    Buckets = (BucketT*)new char[sizeof(BucketT)*NumBuckets];
+    Buckets = reinterpret_cast<BucketT*>(new char[sizeof(BucketT)*NumBuckets]);
 
     // Initialize all the keys to EmptyKey.
     const KeyT EmptyKey = getEmptyKey();
@@ -327,7 +327,7 @@
     }
     
     // Free the old table.
-    delete[] (char*)OldBuckets;
+    delete[] reinterpret_cast<char*>(OldBuckets);
     
     NumEntries = 0;
   }

Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Sun Aug 12 03:12:35 2007
@@ -73,7 +73,9 @@
 public:
   // Default ctor - Initialize to empty.
   SmallVectorImpl(unsigned N)
-    : Begin((T*)&FirstEl), End((T*)&FirstEl), Capacity((T*)&FirstEl+N) {
+    : Begin(reinterpret_cast<T*>(&FirstEl)), 
+      End(reinterpret_cast<T*>(&FirstEl)), 
+      Capacity(reinterpret_cast<T*>(&FirstEl)+N) {
   }
   
   ~SmallVectorImpl() {
@@ -82,7 +84,7 @@
 
     // If this wasn't grown from the inline copy, deallocate the old space.
     if (!isSmall())
-      delete[] (char*)Begin;
+      delete[] reinterpret_cast<char*>(Begin);
   }
   
   typedef size_t size_type;
@@ -285,7 +287,8 @@
   /// 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<const void*>(Begin) == 
+           reinterpret_cast<const void*>(&FirstEl);
   }
 
   /// grow - double the size of the allocated memory, guaranteeing space for at
@@ -323,7 +326,7 @@
   
   // If this wasn't grown from the inline copy, deallocate the old space.
   if (!isSmall())
-    delete[] (char*)Begin;
+    delete[] reinterpret_cast<char*>(Begin);
   
   Begin = NewElts;
   End = NewElts+CurSize;

Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
+++ llvm/trunk/include/llvm/Analysis/Dominators.h Sun Aug 12 03:12:35 2007
@@ -282,7 +282,7 @@
 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 @@
 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!");

Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Sun Aug 12 03:12:35 2007
@@ -246,7 +246,7 @@
 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

Modified: llvm/trunk/include/llvm/Assembly/PrintModulePass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Assembly/PrintModulePass.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Assembly/PrintModulePass.h (original)
+++ llvm/trunk/include/llvm/Assembly/PrintModulePass.h Sun Aug 12 03:12:35 2007
@@ -29,9 +29,10 @@
   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 @@
   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;

Modified: llvm/trunk/include/llvm/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalValue.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/GlobalValue.h Sun Aug 12 03:12:35 2007
@@ -74,7 +74,7 @@
     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;

Modified: llvm/trunk/include/llvm/Pass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Pass.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Pass.h (original)
+++ llvm/trunk/include/llvm/Pass.h Sun Aug 12 03:12:35 2007
@@ -170,7 +170,7 @@
 
   template<typename AnalysisClass>
   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,

Modified: llvm/trunk/include/llvm/PassManagers.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassManagers.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/PassManagers.h (original)
+++ llvm/trunk/include/llvm/PassManagers.h Sun Aug 12 03:12:35 2007
@@ -341,7 +341,7 @@
 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.

Modified: llvm/trunk/include/llvm/PassSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassSupport.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Sun Aug 12 03:12:35 2007
@@ -165,8 +165,8 @@
 
   // 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<PassName>, CFGOnly) {
+    : RegisterPassBase(Name, PassArg, intptr_t(&PassName::ID),
+                     RegisterPassBase::NormalCtor_t(callDefaultCtor<PassName>), CFGOnly) {
   }
 };
 
@@ -204,12 +204,12 @@
 template<typename Interface, bool Default = false>
 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);
   }
 };

Modified: llvm/trunk/include/llvm/SymbolTableListTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/SymbolTableListTraits.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/SymbolTableListTraits.h (original)
+++ llvm/trunk/include/llvm/SymbolTableListTraits.h Sun Aug 12 03:12:35 2007
@@ -45,7 +45,7 @@
   /// 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<ItemParentClass*>((char*)this-
+    return reinterpret_cast<ItemParentClass*>(reinterpret_cast<char*>(this)-
                                               TraitsClass::getListOffset());
   }
   static ValueSubClass *getPrev(ValueSubClass *V) { return V->getPrev(); }

Modified: llvm/trunk/include/llvm/Target/TargetData.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetData.h?rev=41033&r1=41032&r2=41033&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetData.h (original)
+++ llvm/trunk/include/llvm/Target/TargetData.h Sun Aug 12 03:12:35 2007
@@ -108,7 +108,7 @@
   ///
   /// @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 @@
     
   /// 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 @@
   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),





More information about the llvm-commits mailing list