[cfe-commits] r156446 - in /cfe/trunk: lib/StaticAnalyzer/Core/RegionStore.cpp test/Analysis/region-store.c
Anna Zaks
ganna at apple.com
Tue May 8 16:40:38 PDT 2012
Author: zaks
Date: Tue May 8 18:40:38 2012
New Revision: 156446
URL: http://llvm.org/viewvc/llvm-project?rev=156446&view=rev
Log:
[analyzer] We currently do not fully support CompoundLiterals in
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
Added:
cfe/trunk/test/Analysis/region-store.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=156446&r1=156445&r2=156446&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Tue May 8 18:40:38 2012
@@ -1152,7 +1152,16 @@
}
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))
Added: cfe/trunk/test/Analysis/region-store.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-store.c?rev=156446&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/region-store.c (added)
+++ cfe/trunk/test/Analysis/region-store.c Tue May 8 18:40:38 2012
@@ -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;
+}
More information about the cfe-commits
mailing list