From: Zhongxing Xu Date: Mon, 4 May 2009 08:52:47 +0000 (+0000) Subject: array indexes are unsigned integers of the same width as pointer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5b848e046e1899a3ebab4ca3822ae97eef36b1e;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70844 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/ValueManager.h b/include/clang/Analysis/PathSensitive/ValueManager.h index 9842983b2c..d840081893 100644 --- a/include/clang/Analysis/PathSensitive/ValueManager.h +++ b/include/clang/Analysis/PathSensitive/ValueManager.h @@ -76,7 +76,10 @@ public: /// 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); diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 969e4c9654..598191f578 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -213,11 +213,10 @@ SVal BasicStoreManager::getLValueElement(const GRState* St, const MemRegion *R = cast(BaseL).getRegion(); if (isa(R)) { - // Basic example: - // char buf[100]; - // char *q = &buf[1]; // p points to ElementRegion(buf,Unknown) - // &q[10] - //assert(cast(R)->getIndex().isUnknown()); + // int x; + // char* y = (char*) &x; + // 'y' => ElementRegion(0, VarRegion('x')) + // y[0] = 'a'; return Base; } diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index 71f09d2dfc..43ede0f7cd 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -227,6 +227,10 @@ SVal ValueManager::makeZeroVal(QualType T) { return UnknownVal(); } +SVal ValueManager::makeZeroIndex() { + return nonloc::ConcreteInt(BasicVals.getZeroWithPtrWidth(false)); +} + //===----------------------------------------------------------------------===// // Utility methods for constructing Non-Locs. //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/Store.cpp b/lib/Analysis/Store.cpp index 76437d2c86..c9c49c6e9b 100644 --- a/lib/Analysis/Store.cpp +++ b/lib/Analysis/Store.cpp @@ -67,7 +67,7 @@ StoreManager::CastRegion(const GRState* state, const MemRegion* R, // 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? diff --git a/test/Analysis/no-outofbounds.c b/test/Analysis/no-outofbounds.c index df21fb27fe..c07bf86a71 100644 --- a/test/Analysis/no-outofbounds.c +++ b/test/Analysis/no-outofbounds.c @@ -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;