From: Zhongxing Xu Date: Mon, 11 May 2009 14:23:36 +0000 (+0000) Subject: When retrieving an ElementRegion, if its super region is a StringRegion, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c87d5fbfef92c96371c661cb12783c9590a91928;p=clang When retrieving an ElementRegion, if its super region is a StringRegion, retrieve the string value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71430 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 84c8195ecb..9d29a90b3e 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -736,6 +736,24 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) { if (state.contains(R)) return UnknownVal(); + // Check if the region is an element region of a string literal. + if (const ElementRegion *ER = dyn_cast(R)) { + if (const StringRegion *StrR=dyn_cast(ER->getSuperRegion())) { + const StringLiteral *Str = StrR->getStringLiteral(); + SVal Idx = ER->getIndex(); + if (nonloc::ConcreteInt *CI = dyn_cast(&Idx)) { + int64_t i = CI->getValue().getSExtValue(); + char c; + if (i == Str->getByteLength()) + c = '\0'; + else + c = Str->getStrData()[i]; + const llvm::APSInt &V = getBasicVals().getValue(c, getContext().CharTy); + return nonloc::ConcreteInt(V); + } + } + } + // If the region is an element or field, it may have a default value. if (isa(R) || isa(R)) { const MemRegion* SuperR = cast(R)->getSuperRegion();