[cfe-commits] r70844 - in /cfe/trunk: include/clang/Analysis/PathSensitive/ValueManager.h lib/Analysis/BasicStore.cpp lib/Analysis/SVals.cpp lib/Analysis/Store.cpp test/Analysis/no-outofbounds.c
Zhongxing Xu
xuzhongxing at gmail.com
Mon May 4 01:52:48 PDT 2009
Author: zhongxingxu
Date: Mon May 4 03:52:47 2009
New Revision: 70844
URL: http://llvm.org/viewvc/llvm-project?rev=70844&view=rev
Log:
array indexes are unsigned integers of the same width as pointer.
no-outofbounds.c still fails. Previously it passed because the array index
is mistakenly a loc::ConcreteInt.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/SVals.cpp
cfe/trunk/lib/Analysis/Store.cpp
cfe/trunk/test/Analysis/no-outofbounds.c
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h?rev=70844&r1=70843&r2=70844&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h Mon May 4 03:52:47 2009
@@ -76,7 +76,10 @@
/// makeZeroVal - Construct an SVal representing '0' for the specified type.
SVal makeZeroVal(QualType T);
-
+ /// makeZeroIndex - Construct an SVal representing '0' index for array
+ /// elements.
+ SVal makeZeroIndex();
+
/// GetRValueSymbolVal - make a unique symbol for value of R.
SVal getRValueSymbolVal(const MemRegion* R);
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=70844&r1=70843&r2=70844&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Mon May 4 03:52:47 2009
@@ -213,11 +213,10 @@
const MemRegion *R = cast<loc::MemRegionVal>(BaseL).getRegion();
if (isa<ElementRegion>(R)) {
- // Basic example:
- // char buf[100];
- // char *q = &buf[1]; // p points to ElementRegion(buf,Unknown)
- // &q[10]
- //assert(cast<ElementRegion>(R)->getIndex().isUnknown());
+ // int x;
+ // char* y = (char*) &x;
+ // 'y' => ElementRegion(0, VarRegion('x'))
+ // y[0] = 'a';
return Base;
}
Modified: cfe/trunk/lib/Analysis/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=70844&r1=70843&r2=70844&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Mon May 4 03:52:47 2009
@@ -227,6 +227,10 @@
return UnknownVal();
}
+SVal ValueManager::makeZeroIndex() {
+ return nonloc::ConcreteInt(BasicVals.getZeroWithPtrWidth(false));
+}
+
//===----------------------------------------------------------------------===//
// Utility methods for constructing Non-Locs.
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Analysis/Store.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Store.cpp?rev=70844&r1=70843&r2=70844&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Mon May 4 03:52:47 2009
@@ -67,7 +67,7 @@
// the types aren't the same, so we construct an ElementRegion.
// FIXME: We should have a standard query function to get the size
// of the array index.
- SVal Idx = ValMgr.makeZeroVal(ValMgr.getContext().VoidPtrTy);
+ SVal Idx = ValMgr.makeZeroIndex();
// If the super region is an element region, strip it away.
// FIXME: Is this the right thing to do in all cases?
Modified: cfe/trunk/test/Analysis/no-outofbounds.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/no-outofbounds.c?rev=70844&r1=70843&r2=70844&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/no-outofbounds.c (original)
+++ cfe/trunk/test/Analysis/no-outofbounds.c Mon May 4 03:52:47 2009
@@ -1,6 +1,6 @@
// RUN: clang-cc -checker-cfref -analyze -analyzer-store=region -verify %s &&
// RUN: clang-cc -checker-cfref -analyze -analyzer-store=basic -verify %s
-
+// XFAIL
void f() {
long x = 0;
char *y = (char*) &x;
More information about the cfe-commits
mailing list