[cfe-commits] r71074 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/rdar-6541136-region.c
Zhongxing Xu
xuzhongxing at gmail.com
Wed May 6 01:08:27 PDT 2009
Author: zhongxingxu
Date: Wed May 6 03:08:27 2009
New Revision: 71074
URL: http://llvm.org/viewvc/llvm-project?rev=71074&view=rev
Log:
Implement a heuristic type size comparison method for now.
Modified:
cfe/trunk/lib/Analysis/RegionStore.cpp
cfe/trunk/test/Analysis/rdar-6541136-region.c
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=71074&r1=71073&r2=71074&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Wed May 6 03:08:27 2009
@@ -554,6 +554,10 @@
return UnknownVal();
}
+ if (isa<ElementRegion>(R)) {
+ return UnknownVal();
+ }
+
assert(0 && "Other regions are not supported yet.");
return UnknownVal();
}
@@ -585,6 +589,13 @@
return loc::MemRegionVal(ER);
}
+static bool isSmallerThan(QualType T1, QualType T2) {
+ if (T1->isCharType())
+ return true;
+ else
+ return false;
+}
+
RegionStoreManager::CastResult
RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
QualType CastToTy) {
@@ -637,9 +648,14 @@
// VarRegion.
if (isa<VarRegion>(R) || isa<ElementRegion>(R) || isa<FieldRegion>(R)
|| isa<ObjCIvarRegion>(R) || isa<CompoundLiteralRegion>(R)) {
- // FIXME: create an ElementRegion when the size of the pointee type is
- // smaller than the region.
- return CastResult(state, R);
+ if (isSmallerThan(PointeeTy,
+ cast<TypedRegion>(R)->getRValueType(getContext()))) {
+ SVal Idx = ValMgr.makeZeroArrayIndex();
+ ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx,
+ cast<TypedRegion>(R));
+ return CastResult(state, ER);
+ } else
+ return CastResult(state, R);
}
if (isa<TypedViewRegion>(R)) {
Modified: cfe/trunk/test/Analysis/rdar-6541136-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/rdar-6541136-region.c?rev=71074&r1=71073&r2=71074&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/rdar-6541136-region.c (original)
+++ cfe/trunk/test/Analysis/rdar-6541136-region.c Wed May 6 03:08:27 2009
@@ -13,5 +13,7 @@
struct load_wine *cmd = (void*) &wonky[1];
cmd = cmd;
char *p = (void*) &wonky[1];
- *p = 1; // expected-warning{{Load or store into an out-of-bound memory}}
+ *p = 1;
+ kernel_tea_cheese_t *q = &wonky[1];
+ kernel_tea_cheese_t r = *q; // expected-warning{{out-of-bound memory position}}
}
More information about the cfe-commits
mailing list