]> granicus.if.org Git - clang/commitdiff
Add getSize() support for StringRegion.
authorZhongxing Xu <xuzhongxing@gmail.com>
Mon, 24 Nov 2008 02:18:56 +0000 (02:18 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Mon, 24 Nov 2008 02:18:56 +0000 (02:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59930 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/MemRegion.h
include/clang/Analysis/PathSensitive/SVals.h
lib/Analysis/RegionStore.cpp
lib/Analysis/SVals.cpp

index 287dd09c2bec7a5e385f110e7f9336bce57fca29..e2f15375511606489ebd269ecb10cfaa93a1972a 100644 (file)
@@ -189,6 +189,9 @@ protected:
                             const MemRegion* superRegion);
 
 public:
+
+  const StringLiteral* getStringLiteral() const { return Str; }
+
   QualType getType(ASTContext& C) const {
     return C.getCanonicalType(Str->getType());
   }
index 16322f111f20359dcb10f967d342b86d17e3248f..0bacc863e14eded64c567a6df069025e35db3a9c 100644 (file)
@@ -170,6 +170,10 @@ public:
   void print(llvm::raw_ostream& Out) const;
   
   // Utility methods to create NonLocs.
+
+  static NonLoc MakeVal(BasicValueFactory& BasicVals, unsigned X, 
+                        bool isUnsigned);
+
   static NonLoc MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T);
   
   static NonLoc MakeVal(BasicValueFactory& BasicVals, IntegerLiteral* I);
index 05d311df8993b279a8afd02245b2d95b093e6899..cdc8b2723d15cd70cb80a6bce6c58dc84925e964 100644 (file)
@@ -272,9 +272,8 @@ SVal RegionStoreManager::getSizeInElements(const GRState* St,
   }
 
   if (const StringRegion* SR = dyn_cast<StringRegion>(R)) {
-    // FIXME: Unsupported yet.
-    SR = 0;
-    return UnknownVal();
+    const StringLiteral* Str = SR->getStringLiteral();
+    return NonLoc::MakeVal(getBasicVals(), Str->getByteLength(), false);
   }
 
   if (const AnonTypedRegion* ATR = dyn_cast<AnonTypedRegion>(R)) {
index 764a05fe8f0a9c384ede5d301a8d8762334d3da2..0210729b46964c2c8498209a2fc6a6ecefc8dfc0 100644 (file)
@@ -242,6 +242,11 @@ NonLoc Loc::NE(BasicValueFactory& BasicVals, const Loc& R) const {
 //===----------------------------------------------------------------------===//
 // Utility methods for constructing Non-Locs.
 //===----------------------------------------------------------------------===//
+NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, unsigned X, 
+                       bool isUnsigned) {
+  return nonloc::ConcreteInt(BasicVals.getValue(X, sizeof(unsigned)*8, 
+                                                isUnsigned));
+}
 
 NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {  
   return nonloc::ConcreteInt(BasicVals.getValue(X, T));