summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2010-05-29 06:23:24 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2010-05-29 06:23:24 +0000
commit928a190a8ee8a9d5b0929ec8fdab32a44e08e25c (patch)
tree014e7a90847288684a5aa209bf762f2cbe84a8b4
parent04a21441a7ceb68b457d0928f11a8d0e88faa046 (diff)
downloadbcm5719-llvm-928a190a8ee8a9d5b0929ec8fdab32a44e08e25c.tar.gz
bcm5719-llvm-928a190a8ee8a9d5b0929ec8fdab32a44e08e25c.zip
Fix PR7218. Patch by Jordy Rose.
llvm-svn: 105097
-rw-r--r--clang/lib/Checker/RegionStore.cpp20
-rw-r--r--clang/test/Analysis/PR7218.c6
2 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Checker/RegionStore.cpp b/clang/lib/Checker/RegionStore.cpp
index c4072fd8030..c25d2095b13 100644
--- a/clang/lib/Checker/RegionStore.cpp
+++ b/clang/lib/Checker/RegionStore.cpp
@@ -213,6 +213,11 @@ public:
RegionStoreSubRegionMap *getRegionStoreSubRegionMap(Store store);
+ /// canHaveDirectBinding - Disallow direct bindings for certain types,
+ /// like arrays. This lets us distinguish between x and x[0], which was
+ /// causing PR7218 "Assigning to buf[0] makes buf[1] valid".
+ bool canHaveDirectBinding (const MemRegion *R);
+
Optional<SVal> getBinding(RegionBindings B, const MemRegion *R);
Optional<SVal> getDirectBinding(RegionBindings B, const MemRegion *R);
/// getDefaultBinding - Returns an SVal* representing an optional default
@@ -944,11 +949,20 @@ SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R,
//===----------------------------------------------------------------------===//
// Loading values from regions.
//===----------------------------------------------------------------------===//
+bool RegionStoreManager::canHaveDirectBinding (const MemRegion *R) {
+ // Arrays can't have direct binding -- must bind to elements
+ if (const TypedRegion *TR = dyn_cast<TypedRegion>(R))
+ if (TR->getValueType(getContext())->isArrayType())
+ return false;
+
+ return true;
+}
Optional<SVal> RegionStoreManager::getDirectBinding(RegionBindings B,
- const MemRegion *R) {
- if (const SVal *V = Lookup(B, R, BindingKey::Direct))
- return *V;
+ const MemRegion *R) {
+ if (canHaveDirectBinding(R))
+ if (const SVal *V = Lookup(B, R, BindingKey::Direct))
+ return *V;
return Optional<SVal>();
}
diff --git a/clang/test/Analysis/PR7218.c b/clang/test/Analysis/PR7218.c
new file mode 100644
index 00000000000..635e56f053e
--- /dev/null
+++ b/clang/test/Analysis/PR7218.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store region -verify %s
+char PR7218(char a) {
+ char buf[2];
+ buf[0] = a;
+ return buf[1]; // expected-warning {{Undefined or garbage value returned to caller}}
+}
OpenPOWER on IntegriCloud