[cfe-commits] r71430 - /cfe/trunk/lib/Analysis/RegionStore.cpp

Zhongxing Xu xuzhongxing at gmail.com
Mon May 11 07:23:49 PDT 2009


Author: zhongxingxu
Date: Mon May 11 09:23:36 2009
New Revision: 71430

URL: http://llvm.org/viewvc/llvm-project?rev=71430&view=rev
Log:
When retrieving an ElementRegion, if its super region is a StringRegion,
retrieve the string value.

Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp

Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=71430&r1=71429&r2=71430&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Mon May 11 09:23:36 2009
@@ -736,6 +736,24 @@
   if (state.contains<RegionKills>(R))
     return UnknownVal();
 
+  // Check if the region is an element region of a string literal.
+  if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) {
+    if (const StringRegion *StrR=dyn_cast<StringRegion>(ER->getSuperRegion())) {
+      const StringLiteral *Str = StrR->getStringLiteral();
+      SVal Idx = ER->getIndex();
+      if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&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<ElementRegion>(R) || isa<FieldRegion>(R)) {
     const MemRegion* SuperR = cast<SubRegion>(R)->getSuperRegion();





More information about the cfe-commits mailing list