Fixes for PR114: Thanks to Reid Spencer!

llvm-svn: 10029
diff --git a/llvm/include/Support/Casting.h b/llvm/include/Support/Casting.h
index 4b070c1..abc80aa 100644
--- a/llvm/include/Support/Casting.h
+++ b/llvm/include/Support/Casting.h
@@ -37,7 +37,7 @@
 template<typename From> struct simplify_type<const From> {
   typedef const From SimpleType;
   static SimpleType &getSimplifiedValue(const From &Val) {
-    return simplify_type<From>::getSimplifiedValue((From&)Val);
+    return simplify_type<From>::getSimplifiedValue(static_cast<From&>(Val));
   }
 };
 
@@ -178,7 +178,8 @@
 template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
   // This _is_ a simple type, just cast it.
   static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
-    return (typename cast_retty<To, FromTy>::ret_type)Val;
+    return reinterpret_cast<typename cast_retty<To, FromTy>::ret_type>(
+                         const_cast<FromTy&>(Val));
   }
 };
 
diff --git a/llvm/include/Support/CommandLine.h b/llvm/include/Support/CommandLine.h
index df40d80..0a3cb6f 100644
--- a/llvm/include/Support/CommandLine.h
+++ b/llvm/include/Support/CommandLine.h
@@ -148,19 +148,23 @@
 
   inline enum NumOccurrences getNumOccurrencesFlag() const {
     int NO = Flags & OccurrencesMask;
-    return NO ? (enum NumOccurrences)NO : getNumOccurrencesFlagDefault();
+    return NO ? static_cast<enum NumOccurrences>(NO)
+              : getNumOccurrencesFlagDefault();
   }
   inline enum ValueExpected getValueExpectedFlag() const {
     int VE = Flags & ValueMask;
-    return VE ? (enum ValueExpected)VE : getValueExpectedFlagDefault();
+    return VE ? static_cast<enum ValueExpected>(VE)
+              : getValueExpectedFlagDefault();
   }
   inline enum OptionHidden getOptionHiddenFlag() const {
     int OH = Flags & HiddenMask;
-    return OH ? (enum OptionHidden)OH : getOptionHiddenFlagDefault();
+    return OH ? static_cast<enum OptionHidden>(OH)
+              : getOptionHiddenFlagDefault();
   }
   inline enum FormattingFlags getFormattingFlag() const {
     int OH = Flags & FormattingMask;
-    return OH ? (enum FormattingFlags)OH : getFormattingFlagDefault();
+    return OH ? static_cast<enum FormattingFlags>(OH)
+              : getFormattingFlagDefault();
   }
   inline unsigned getMiscFlags() const {
     return Flags & MiscMask;
@@ -307,7 +311,7 @@
 
     // Process the varargs portion of the values...
     while (const char *EnumName = va_arg(ValueArgs, const char *)) {
-      DataType EnumVal = (DataType)va_arg(ValueArgs, int);
+      DataType EnumVal = static_cast<DataType>(va_arg(ValueArgs, int));
       const char *EnumDesc = va_arg(ValueArgs, const char *);
       Values.push_back(std::make_pair(EnumName,      // Add value to value map
                                       std::make_pair(EnumVal, EnumDesc)));
@@ -452,7 +456,8 @@
   template <class DT>
   void addLiteralOption(const char *Name, const DT &V, const char *HelpStr) {
     assert(findOption(Name) == Values.size() && "Option already exists!");
-    Values.push_back(std::make_pair(Name, std::make_pair((DataType)V,HelpStr)));
+    Values.push_back(std::make_pair(Name,
+                             std::make_pair(static_cast<DataType>(V),HelpStr)));
   }
 
   // removeLiteralOption - Remove the specified option.
diff --git a/llvm/include/Support/GraphWriter.h b/llvm/include/Support/GraphWriter.h
index 7e5aa80..0eace78 100644
--- a/llvm/include/Support/GraphWriter.h
+++ b/llvm/include/Support/GraphWriter.h
@@ -100,7 +100,7 @@
   void writeNode(NodeType *Node) {
     std::string NodeAttributes = DOTTraits::getNodeAttributes(Node);
       
-    O << "\tNode" << (void*)Node << " [shape=record,";
+    O << "\tNode" << reinterpret_cast<const void*>(Node) << " [shape=record,";
     if (!NodeAttributes.empty()) O << NodeAttributes << ",";
     O << "label=\"{"
       << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
@@ -137,10 +137,11 @@
         // Figure out which edge this targets...
         unsigned Offset = std::distance(GTraits::child_begin(TargetNode),
                                         TargetIt);
-        DestPort = (int)Offset;
+        DestPort = static_cast<int>(Offset);
       }
 
-      emitEdge((void *)Node, edgeidx, (void*)TargetNode, DestPort,
+      emitEdge(reinterpret_cast<const void*>(Node), edgeidx,
+               reinterpret_cast<const void*>(TargetNode), DestPort,
                DOTTraits::getEdgeAttributes(Node, EI));
     }
   }
@@ -178,7 +179,7 @@
     O << "\tNode" << SrcNodeID;
     if (SrcNodePort >= 0)
       O << ":g" << SrcNodePort;
-    O << " -> Node" << (void*)DestNodeID;
+    O << " -> Node" << reinterpret_cast<const void*>(DestNodeID);
     if (DestNodePort >= 0)
       O << ":g" << DestNodePort;    
 
diff --git a/llvm/include/Support/HashExtras.h b/llvm/include/Support/HashExtras.h
index 871080c..67f65b5 100644
--- a/llvm/include/Support/HashExtras.h
+++ b/llvm/include/Support/HashExtras.h
@@ -31,7 +31,9 @@
 
 // Provide a hash function for arbitrary pointers...
 template <class T> struct hash<T *> {
-  inline size_t operator()(const T *Val) const { return (size_t)Val; }
+  inline size_t operator()(const T *Val) const {
+    return reinterpret_cast<size_t>(Val);
+  }
 };
 
 }  // End namespace std
diff --git a/llvm/include/Support/MallocAllocator.h b/llvm/include/Support/MallocAllocator.h
index 022953d..3e3da41 100644
--- a/llvm/include/Support/MallocAllocator.h
+++ b/llvm/include/Support/MallocAllocator.h
@@ -47,15 +47,15 @@
   size_type max_size() const { return ~0 / sizeof(T); }
   
   static pointer allocate(size_t n, void* hint = 0) {
-    return (pointer)malloc(n*sizeof(T));
+    return static_cast<pointer>(malloc(n*sizeof(T)));
   }
 
   static void deallocate(pointer p, size_t n) {
-    free((void*)p);
+    free(static_cast<void*>(p));
   }
 
   void construct(pointer p, const T &val) {
-    new((void*)p) T(val);
+    new(static_cast<void*>(p)) T(val);
   }
   void destroy(pointer p) {
     p->~T();
diff --git a/llvm/include/Support/MathExtras.h b/llvm/include/Support/MathExtras.h
index 74958fb..125aff3 100644
--- a/llvm/include/Support/MathExtras.h
+++ b/llvm/include/Support/MathExtras.h
@@ -28,7 +28,7 @@
 inline bool isPowerOf2(int64_t C, unsigned &getPow) {
   if (C < 0) C = -C;
   if (C > 0 && C == (C & ~(C - 1))) {
-    getPow = log2((uint64_t)C);
+    getPow = log2(static_cast<uint64_t>(C));
     return true;
   }
 
diff --git a/llvm/include/Support/StringExtras.h b/llvm/include/Support/StringExtras.h
index 2ebac81..08e5eb7 100644
--- a/llvm/include/Support/StringExtras.h
+++ b/llvm/include/Support/StringExtras.h
@@ -57,14 +57,14 @@
 
 static inline std::string itostr(int64_t X) {
   if (X < 0) 
-    return utostr((uint64_t)-X, true);
+    return utostr(static_cast<uint64_t>(-X), true);
   else
-    return utostr((uint64_t)X);
+    return utostr(static_cast<uint64_t>(X));
 }
 
 
 static inline std::string utostr(unsigned long X, bool isNeg = false) {
-  return utostr((unsigned long long)X, isNeg);
+  return utostr(static_cast<unsigned long long>(X), isNeg);
 }
 
 static inline std::string utostr(unsigned X, bool isNeg = false) {
@@ -86,9 +86,9 @@
 
 static inline std::string itostr(int X) {
   if (X < 0) 
-    return utostr((unsigned)-X, true);
+    return utostr(static_cast<unsigned>(-X), true);
   else
-    return utostr((unsigned)X);
+    return utostr(static_cast<unsigned>(X));
 }
 
 static inline std::string ftostr(double V) {
diff --git a/llvm/include/llvm/ConstantHandling.h b/llvm/include/llvm/ConstantHandling.h
index a0a01e5..b392ad1 100644
--- a/llvm/include/llvm/ConstantHandling.h
+++ b/llvm/include/llvm/ConstantHandling.h
@@ -113,7 +113,8 @@
     case Type::LongTyID:   return castToLong(V);
     case Type::FloatTyID:  return castToFloat(V);
     case Type::DoubleTyID: return castToDouble(V);
-    case Type::PointerTyID:return castToPointer(V, (PointerType*)Ty);
+    case Type::PointerTyID:
+      return castToPointer(V, reinterpret_cast<const PointerType*>(Ty));
     default: return 0;
     }
   }
@@ -125,7 +126,7 @@
   static inline ConstRules *get(const Constant &V1, const Constant &V2) {
     if (isa<ConstantExpr>(V1) || isa<ConstantExpr>(V2))
       return getConstantExprRules();
-    return (ConstRules*)V1.getType()->getOrCreateAnnotation(AID);
+    return static_cast<ConstRules*>(V1.getType()->getOrCreateAnnotation(AID));
   }
 private:
   static ConstRules *getConstantExprRules();
diff --git a/llvm/include/llvm/Constants.h b/llvm/include/llvm/Constants.h
index 5d65b2f..06f1308 100644
--- a/llvm/include/llvm/Constants.h
+++ b/llvm/include/llvm/Constants.h
@@ -301,7 +301,7 @@
   /// which reduces the amount of casting needed in parts of the compiler.
   ///
   inline const ArrayType *getType() const {
-    return (ArrayType*)Value::getType();
+    return reinterpret_cast<const ArrayType*>(Value::getType());
   }
 
   /// getAsString - If the sub-element type of this array is either sbyte or
@@ -354,7 +354,7 @@
 
   /// getType() specialization - Reduce amount of casting...
   inline const StructType *getType() const {
-    return (StructType*)Value::getType();
+    return reinterpret_cast<const StructType*>(Value::getType());
   }
 
   /// getValues - Return a vector of the component constants that make up this
@@ -394,10 +394,11 @@
 class ConstantPointer : public Constant {
   ConstantPointer(const ConstantPointer &);      // DO NOT IMPLEMENT
 protected:
-  inline ConstantPointer(const PointerType *T) : Constant((const Type*)T) {}
+  inline ConstantPointer(const PointerType *T)
+    : Constant(reinterpret_cast<const Type*>(T)) { }
 public:
   inline const PointerType *getType() const {
-    return (PointerType*)Value::getType();
+    return reinterpret_cast<const PointerType*>(Value::getType());
   }
 
   /// isNullValue - Return true if this is the value that would be returned by
diff --git a/llvm/include/llvm/GlobalValue.h b/llvm/include/llvm/GlobalValue.h
index 47a2189..942d9b9 100644
--- a/llvm/include/llvm/GlobalValue.h
+++ b/llvm/include/llvm/GlobalValue.h
@@ -46,7 +46,7 @@
 
   /// getType - Global values are always pointers.
   inline const PointerType *getType() const {
-    return (const PointerType*)User::getType();
+    return reinterpret_cast<const PointerType*>(User::getType());
   }
 
   bool hasExternalLinkage()  const { return Linkage == ExternalLinkage; }
diff --git a/llvm/include/llvm/GlobalVariable.h b/llvm/include/llvm/GlobalVariable.h
index 03c4f39..b09bf40 100644
--- a/llvm/include/llvm/GlobalVariable.h
+++ b/llvm/include/llvm/GlobalVariable.h
@@ -70,18 +70,18 @@
   ///
   inline Constant *getInitializer() const {
     assert(hasInitializer() && "GV doesn't have initializer!");
-    return (Constant*)Operands[0].get();
+    return reinterpret_cast<Constant*>(Operands[0].get());
   }
   inline Constant *getInitializer() {
     assert(hasInitializer() && "GV doesn't have initializer!");
-    return (Constant*)Operands[0].get();
+    return reinterpret_cast<Constant*>(Operands[0].get());
   }
   inline void setInitializer(Constant *CPV) {
     if (CPV == 0) {
       if (hasInitializer()) Operands.pop_back();
     } else {
       if (!hasInitializer()) Operands.push_back(Use(0, this));
-      Operands[0] = (Value*)CPV;
+      Operands[0] = reinterpret_cast<Value*>(CPV);
     }
   }
 
diff --git a/llvm/include/llvm/InstrTypes.h b/llvm/include/llvm/InstrTypes.h
index 7938b48..70cb742 100644
--- a/llvm/include/llvm/InstrTypes.h
+++ b/llvm/include/llvm/InstrTypes.h
@@ -50,7 +50,8 @@
   virtual void setSuccessor(unsigned idx, BasicBlock *B) = 0;
 
   inline BasicBlock *getSuccessor(unsigned idx) {
-    return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
+    const TerminatorInst *TI = this;
+    return const_cast<BasicBlock*>(TI->getSuccessor(idx));
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -110,7 +111,7 @@
   static       Value*    getNotArgument(      BinaryOperator* Bop);
 
   BinaryOps getOpcode() const { 
-    return (BinaryOps)Instruction::getOpcode();
+    return static_cast<BinaryOps>(Instruction::getOpcode());
   }
 
   virtual Instruction *clone() const {
diff --git a/llvm/include/llvm/PassSupport.h b/llvm/include/llvm/PassSupport.h
index d985bf1..bc2b7da 100644
--- a/llvm/include/llvm/PassSupport.h
+++ b/llvm/include/llvm/PassSupport.h
@@ -226,7 +226,8 @@
   RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(),
               bool CFGOnly = false) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
-                              PassInfo::Optimization, (Pass*(*)())ctor));
+                              PassInfo::Optimization, 
+                              static_cast<Pass*(*)()>(ctor)));
     if (CFGOnly) setOnlyUsesCFG();
   }
 
@@ -246,7 +247,7 @@
               bool CFGOnly = false) {
     registerPass(new PassInfo(Name, PassArg, typeid(PassName),
                               PassInfo::Optimization, 0,
-                              (Pass*(*)(TargetMachine&))targetctor));
+                            static_cast<Pass*(*)(TargetMachine&)>(targetctor)));
     if (CFGOnly) setOnlyUsesCFG();
   }
 };
diff --git a/llvm/include/llvm/Use.h b/llvm/include/llvm/Use.h
index d7c1010..fb5eafb 100644
--- a/llvm/include/llvm/Use.h
+++ b/llvm/include/llvm/Use.h
@@ -83,13 +83,13 @@
 template<> struct simplify_type<Use> {
   typedef Value* SimpleType;
   static SimpleType getSimplifiedValue(const Use &Val) {
-    return (SimpleType)Val.get();
+    return static_cast<SimpleType>(Val.get());
   }
 };
 template<> struct simplify_type<const Use> {
   typedef Value* SimpleType;
   static SimpleType getSimplifiedValue(const Use &Val) {
-    return (SimpleType)Val.get();
+    return static_cast<SimpleType>(Val.get());
   }
 };
 
diff --git a/llvm/include/llvm/User.h b/llvm/include/llvm/User.h
index cdd9b53..0482189 100644
--- a/llvm/include/llvm/User.h
+++ b/llvm/include/llvm/User.h
@@ -96,7 +96,7 @@
   typedef Value* SimpleType;
   
   static SimpleType getSimplifiedValue(const User::op_iterator &Val) {
-    return (SimpleType)Val->get();
+    return static_cast<SimpleType>(Val->get());
   }
 };
 template<> struct simplify_type<const User::op_iterator>
@@ -106,7 +106,7 @@
   typedef Value* SimpleType;
   
   static SimpleType getSimplifiedValue(const User::const_op_iterator &Val) {
-    return (SimpleType)Val->get();
+    return static_cast<SimpleType>(Val->get());
   }
 };
 template<> struct simplify_type<const User::const_op_iterator>
diff --git a/llvm/include/llvm/iMemory.h b/llvm/include/llvm/iMemory.h
index e0a551a..bec4502 100644
--- a/llvm/include/llvm/iMemory.h
+++ b/llvm/include/llvm/iMemory.h
@@ -47,7 +47,7 @@
 
   // getType - Overload to return most specific pointer type...
   inline const PointerType *getType() const {
-    return (const PointerType*)Instruction::getType(); 
+    return reinterpret_cast<const PointerType*>(Instruction::getType()); 
   }
 
   // getAllocatedType - Return the type that is being allocated by the
@@ -237,7 +237,7 @@
 
 class GetElementPtrInst : public Instruction {
   GetElementPtrInst(const GetElementPtrInst &EPI)
-    : Instruction((Type*)EPI.getType(), GetElementPtr) {
+    : Instruction(reinterpret_cast<const Type*>(EPI.getType()), GetElementPtr) {
     Operands.reserve(EPI.Operands.size());
     for (unsigned i = 0, E = EPI.Operands.size(); i != E; ++i)
       Operands.push_back(Use(EPI.Operands[i], this));
@@ -249,7 +249,7 @@
   
   // getType - Overload to return most specific pointer type...
   inline const PointerType *getType() const {
-    return (PointerType*)Instruction::getType();
+    return reinterpret_cast<const PointerType*>(Instruction::getType());
   }
 
   /// getIndexedType - Returns the type of the element that would be loaded with
diff --git a/llvm/include/llvm/iOther.h b/llvm/include/llvm/iOther.h
index c611e06..8ecf6b0 100644
--- a/llvm/include/llvm/iOther.h
+++ b/llvm/include/llvm/iOther.h
@@ -113,7 +113,9 @@
     Operands.push_back(Use(SA, this));
   }
 
-  OtherOps getOpcode() const { return (OtherOps)Instruction::getOpcode(); }
+  OtherOps getOpcode() const {
+    return static_cast<OtherOps>(Instruction::getOpcode());
+  }
 
   virtual Instruction *clone() const { return new ShiftInst(*this); }
 
diff --git a/llvm/include/llvm/iPHINode.h b/llvm/include/llvm/iPHINode.h
index 191de04..399c761 100644
--- a/llvm/include/llvm/iPHINode.h
+++ b/llvm/include/llvm/iPHINode.h
@@ -58,11 +58,11 @@
   /// getIncomingBlock - Return incoming basic block #x
   BasicBlock *getIncomingBlock(unsigned i) const { 
     assert(i*2+1 < Operands.size() && "Invalid value number!");
-    return (BasicBlock*)Operands[i*2+1].get();
+    return reinterpret_cast<BasicBlock*>(Operands[i*2+1].get());
   }
   void setIncomingBlock(unsigned i, BasicBlock *BB) {
     assert(i*2+1 < Operands.size() && "Invalid value number!");
-    Operands[i*2+1] = (Value*)BB;
+    Operands[i*2+1] = reinterpret_cast<Value*>(BB);
   }
   unsigned getOperandNumForIncomingBlock(unsigned i) {
     return i*2+1;
@@ -73,7 +73,7 @@
     assert(getType() == D->getType() &&
            "All operands to PHI node must be the same type as the PHI node!");
     Operands.push_back(Use(D, this));
-    Operands.push_back(Use((Value*)BB, this));
+    Operands.push_back(Use(reinterpret_cast<Value*>(BB), this));
   }
   
   /// removeIncomingValue - Remove an incoming value.  This is useful if a
diff --git a/llvm/include/llvm/iTerminators.h b/llvm/include/llvm/iTerminators.h
index 93e3adce..a27ffdf 100644
--- a/llvm/include/llvm/iTerminators.h
+++ b/llvm/include/llvm/iTerminators.h
@@ -87,7 +87,7 @@
   inline bool isConditional()   const { return Operands.size() == 3; }
 
   inline Value *getCondition() const {
-    return isUnconditional() ? 0 : (Value*)Operands[2].get();
+    return isUnconditional() ? 0 : reinterpret_cast<Value*>(Operands[2].get());
   }
 
   void setCondition(Value *V) {
@@ -100,7 +100,7 @@
   //
   void setUnconditionalDest(BasicBlock *Dest) {
     if (isConditional()) Operands.erase(Operands.begin()+1, Operands.end());
-    Operands[0] = (Value*)Dest;
+    Operands[0] = reinterpret_cast<Value*>(Dest);
   }
 
   virtual const BasicBlock *getSuccessor(unsigned i) const {
@@ -109,12 +109,13 @@
                       cast<BasicBlock>(Operands[1].get());
   }
   inline BasicBlock *getSuccessor(unsigned idx) {
-    return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx);
+    const BranchInst *BI = this;
+    return const_cast<BasicBlock*>(BI->getSuccessor(idx));
   }
 
   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < getNumSuccessors() && "Successor # out of range for Branch!");
-    Operands[idx] = (Value*)NewSucc;
+    Operands[idx] = reinterpret_cast<Value*>(NewSucc);
   }
 
   virtual unsigned getNumSuccessors() const { return 1+isConditional(); }
@@ -176,7 +177,7 @@
 
   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
-    Operands[idx*2+1] = (Value*)NewSucc;
+    Operands[idx*2+1] = reinterpret_cast<Value*>(NewSucc);
   }
 
   // getSuccessorValue - Return the value associated with the specified
@@ -243,11 +244,11 @@
   }
 
   inline void setNormalDest(BasicBlock *B){
-    Operands[1] = (Value*)B;
+    Operands[1] = reinterpret_cast<Value*>(B);
   }
 
   inline void setExceptionalDest(BasicBlock *B){
-    Operands[2] = (Value*)B;
+    Operands[2] = reinterpret_cast<Value*>(B);
   }
 
   virtual const BasicBlock *getSuccessor(unsigned i) const {
@@ -261,7 +262,7 @@
 
   virtual void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < 2 && "Successor # out of range for invoke!");
-    Operands[idx+1] = (Value*)NewSucc;
+    Operands[idx+1] = reinterpret_cast<Value*>(NewSucc);
   }
 
   virtual unsigned getNumSuccessors() const { return 2; }