]> granicus.if.org Git - clang/commitdiff
[analyzer] Use UnknownVal when default-initializing arrays whose element types we...
authorJordy Rose <jediknil@belkadan.com>
Mon, 27 Jun 2011 20:36:38 +0000 (20:36 +0000)
committerJordy Rose <jediknil@belkadan.com>
Mon, 27 Jun 2011 20:36:38 +0000 (20:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/uninit-vals-ps-region.m
test/Analysis/uninit-vals.m

index d0d8f601f071e74a59fe51051ec8c12e26c90b83..23dd6416a8f1ab4c6ab7e57aad155371949bcb94 100644 (file)
@@ -1377,7 +1377,12 @@ StoreRef RegionStoreManager::setImplicitDefaultValue(Store store,
     V = svalBuilder.makeZeroVal(Ctx.IntTy);
   }
   else {
-    return StoreRef(store, *this);
+    // We can't represent values of this type, but we still need to set a value
+    // to record that the region has been initialized.
+    // If this assertion ever fires, a new case should be added above -- we
+    // should know how to default-initialize any value we can symbolicate.
+    assert(!SymbolManager::canSymbolicate(T) && "This type is representable");
+    V = UnknownVal();
   }
 
   return StoreRef(addBinding(B, R, BindingKey::Default,
index 1700f54dbfb08106e8078e09b64597219c259338..c62818a12e0d78112bf2020b1b64b8c57cf4f48b 100644 (file)
@@ -67,3 +67,12 @@ void rdar_7780304() {
   b.x |= 1; // expected-warning{{The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage}}
 }
 
+
+// The flip side of PR10163 -- float arrays that are actually uninitialized
+// (The main test is in uninit-vals.m)
+void test_PR10163(float);
+void PR10163 (void) {
+  float x[2];
+  test_PR10163(x[1]); // expected-warning{{uninitialized value}}
+}
+
index 2cd5e0c118487b09539ecaee96cce1077ef7faf3..4b7e6f42cf8f4e81b4f98dd96de0b65abbff5bed 100644 (file)
@@ -23,3 +23,12 @@ NSUInteger f8(A* x){
   
   return n;
 }
+
+
+// PR10163 -- don't warn for default-initialized float arrays.
+// (An additional test is in uninit-vals-ps-region.m)
+void test_PR10163(float);
+void PR10163 (void) {
+  float x[2] = {0};
+  test_PR10163(x[1]); // no-warning  
+}