]> granicus.if.org Git - clang/commitdiff
Fix a bug in RegionStoreSubRegionManager::add() where multiple subregions wouldn...
authorTed Kremenek <kremenek@apple.com>
Wed, 5 Aug 2009 05:31:02 +0000 (05:31 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 5 Aug 2009 05:31:02 +0000 (05:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78162 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RegionStore.cpp
test/Analysis/misc-ps.m

index c47aaa20e07c9b1b938033aca2a55d6d55b77f74..70201759e100382c0567f12df8f967687854de9f 100644 (file)
@@ -121,8 +121,10 @@ class VISIBILITY_HIDDEN RegionStoreSubRegionMap : public SubRegionMap {
 public:
   void add(const MemRegion* Parent, const MemRegion* SubRegion) {
     Map::iterator I = M.find(Parent);
-    M.insert(std::make_pair(Parent, 
-             F.Add(I == M.end() ? F.GetEmptySet() : I->second, SubRegion)));
+    if (I == M.end())
+      M.insert(std::make_pair(Parent, F.Add(F.GetEmptySet(), SubRegion)));
+    else
+      I->second = F.Add(I->second, SubRegion);
   }
     
   ~RegionStoreSubRegionMap() {}
index 9f48db55d1e14f4ca46e502f28814691ba889094..1ca209dbf8b73fbc6855ef9eb462572e963c14de 100644 (file)
@@ -522,3 +522,14 @@ void test_pass_val() {
   test_pass_val_aux(s);
 }
 
+// This is a reduced test case of a false positive that previously appeared
+// in RegionStoreManager.  Previously the array access resulted in dereferencing
+// an undefined value.
+int test_array_compound(int *q, int *r, int *z) {
+  int *array[] = { q, r, z };
+  int j = 0;
+  for (unsigned i = 0; i < 3 ; ++i)
+    if (*array[i]) ++j; // no-warning
+  return j;
+}
+