]> granicus.if.org Git - clang/commitdiff
[analyzer] We currently do not fully support CompoundLiterals in
authorAnna Zaks <ganna@apple.com>
Tue, 8 May 2012 23:40:38 +0000 (23:40 +0000)
committerAnna Zaks <ganna@apple.com>
Tue, 8 May 2012 23:40:38 +0000 (23:40 +0000)
RegionStore, so be explicit about it and generate UnknownVal().

This is a hack to ensure we never produce undefined values for a value
coming from a compound value. (The undefined values can lead to
false positives.)

radar://10127782

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156446 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/region-store.c [new file with mode: 0644]

index 8b1371d28f1aa0a18e10b68455c4d82a32da333d..487327e7fcb0e7dba36985c709ccfb9df7311d63 100644 (file)
@@ -1152,7 +1152,16 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R,
 }
 
 SVal RegionStoreManager::getBindingForElement(Store store,
-                                         const ElementRegion* R) {
+                                              const ElementRegion* R) {
+  // We do not currently model bindings of the CompoundLiteralregion.
+  const ElementRegion *Tmp = R;
+  while (Tmp) {
+    const MemRegion *Sup = Tmp->getSuperRegion();
+    if (isa<CompoundLiteralRegion>(Sup))
+      return UnknownVal();
+    Tmp = dyn_cast<ElementRegion>(Sup);
+  }
+
   // Check if the region has a binding.
   RegionBindings B = GetRegionBindings(store);
   if (const Optional<SVal> &V = getDirectBinding(B, R))
diff --git a/test/Analysis/region-store.c b/test/Analysis/region-store.c
new file mode 100644 (file)
index 0000000..09c3f10
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix -verify %s
+
+int printf(const char *restrict,...);
+
+// Testing core functionality of the region store.
+// radar://10127782
+int compoundLiteralTest() {
+    int index = 0;
+    for (index = 0; index < 2; index++) {
+        int thing = (int []){0, 1}[index];
+        printf("thing: %i\n", thing);
+    }
+    return 0;
+}
+
+int compoundLiteralTest2() {
+    int index = 0;
+    for (index = 0; index < 3; index++) {
+        int thing = (int [][3]){{0,0,0}, {1,1,1}, {2,2,2}}[index][index];
+        printf("thing: %i\n", thing);
+    }
+    return 0;
+}