Add 'MemRegion::getBaseRegion()', a utility method to strip ElementRegions with
index 0.  This will be used for refinements to InvalidateRegion and CastRegion.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77481 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp
index a5ba199..6f480e8 100644
--- a/lib/Analysis/SVals.cpp
+++ b/lib/Analysis/SVals.cpp
@@ -72,7 +72,7 @@
 // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
 SymbolRef SVal::getAsLocSymbol() const {
   if (const loc::MemRegionVal *X = dyn_cast<loc::MemRegionVal>(this)) {
-    const MemRegion *R = X->getRegion();
+    const MemRegion *R = X->getBaseRegion();
     
     while (R) {
       // Blast through region views.
@@ -80,7 +80,6 @@
         R = View->getSuperRegion();
         continue;
       }
-      
       if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R))
         return SymR->getSymbol();
       
@@ -121,6 +120,11 @@
   return 0;
 }
 
+const MemRegion *loc::MemRegionVal::getBaseRegion() const {
+  const MemRegion *R = getRegion();
+  return R ?  R->getBaseRegion() : NULL;
+}
+
 bool SVal::symbol_iterator::operator==(const symbol_iterator &X) const {
   return itr == X.itr;
 }