Fix PR 4594 by refactoring almost all casting logic from GRExprEngine::VisitCast
to SValuator::EvalCast. In the process, the StoreManagers now use this new cast
machinery, and the hack in GRExprEngine::EvalBind to handle implicit casts
involving OSAtomicCompareAndSwap and friends has been removed (and replaced with
logic closer to the logic specific to those functions).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ValueManager.cpp b/lib/Analysis/ValueManager.cpp
index 658dfa1..ee6b5cb 100644
--- a/lib/Analysis/ValueManager.cpp
+++ b/lib/Analysis/ValueManager.cpp
@@ -56,6 +56,9 @@
 
 
 SVal ValueManager::convertToArrayIndex(SVal V) {
+  if (V.isUnknownOrUndef())
+    return V;
+  
   // Common case: we have an appropriately sized integer.
   if (nonloc::ConcreteInt* CI = dyn_cast<nonloc::ConcreteInt>(&V)) {
     const llvm::APSInt& I = CI->getValue();
@@ -63,7 +66,7 @@
       return V;
   }
   
-  return SVator->EvalCast(V, ArrayIndexTy);
+  return SVator->EvalCastNL(cast<NonLoc>(V), ArrayIndexTy);
 }
 
 SVal ValueManager::getRegionValueSymbolVal(const MemRegion* R, QualType T) {