OSAtomic simulation: use the original region as the location to load from,
instead of the ElementRegion obtained from casts.

Test cast: the leak cannot occur bacause the true branch cannot be taken.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90964 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 4a960c6..daa249f 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -1483,10 +1483,13 @@
   ExplodedNodeSet Tmp;
   SVal location = state->getSVal(theValueExpr);
   // Here we should use the value type of the region as the load type.
-  const MemRegion *R = location.getAsRegion();
+  const MemRegion *R = location.getAsRegion()->StripCasts();
   QualType LoadTy;
-  if (R)
+  if (R) {
     LoadTy = cast<TypedRegion>(R)->getValueType(C);
+    // Use the region as the real load location.
+    location = loc::MemRegionVal(R);
+  }
   Engine.EvalLoad(Tmp, theValueExpr, Pred, state, location, OSAtomicLoadTag,
                   LoadTy);
 
diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp
index e591842..be4ce2d 100644
--- a/lib/Analysis/Store.cpp
+++ b/lib/Analysis/Store.cpp
@@ -199,7 +199,7 @@
                                      QualType castTy) {
   if (castTy.isNull())
     return V;
-  
+
   assert(ValMgr.getContext().hasSameUnqualifiedType(castTy,
                                          R->getValueType(ValMgr.getContext())));
   return V;
@@ -228,4 +228,4 @@
 SVal StoreManager::getLValueCompoundLiteral(const CompoundLiteralExpr* CL,
                                             const LocationContext *LC) {
   return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC));
-}
\ No newline at end of file
+}