[llvm-branch-commits] [cfe-branch] r71328 - in /cfe/branches/Apple/Dib: lib/Analysis/RegionStore.cpp test/Analysis/xfail-no-outofbounds.c

Mike Stump mrs at apple.com
Fri May 8 23:10:47 PDT 2009


Author: mrs
Date: Sat May  9 01:10:47 2009
New Revision: 71328

URL: http://llvm.org/viewvc/llvm-project?rev=71328&view=rev
Log:
Merge in 71080:

Improve RegionStoreManager::getSizeInElements()
 - add a static function getTypeWidth(), which computes the width of a type
   with the help of TargetInfo.
 - no-outofbounds.c now passes for region store.

Modified:
    cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp
    cfe/branches/Apple/Dib/test/Analysis/xfail-no-outofbounds.c

Modified: cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp?rev=71328&r1=71327&r2=71328&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Analysis/RegionStore.cpp Sat May  9 01:10:47 2009
@@ -18,6 +18,7 @@
 #include "clang/Analysis/PathSensitive/GRState.h"
 #include "clang/Analysis/PathSensitive/GRStateTrait.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
+#include "clang/Basic/TargetInfo.h"
 
 #include "llvm/ADT/ImmutableMap.h"
 #include "llvm/ADT/ImmutableList.h"
@@ -296,6 +297,7 @@
   // Utility methods.
   BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); }
   ASTContext& getContext() { return StateMgr.getContext(); }
+  TargetInfo& getTargetInfo() { return getContext().getTargetInfo(); }
   SymbolManager& getSymbolManager() { return StateMgr.getSymbolManager(); }
 
   const GRState* AddRegionView(const GRState* St,
@@ -310,6 +312,45 @@
   return new RegionStoreManager(StMgr);
 }
 
+// getTypeWidth - compute the width of the type. Should pass in
+// canonical type.
+static unsigned getTypeWidth(ASTContext& Ctx, QualType T) {
+  TargetInfo& Target = Ctx.getTargetInfo();
+  QualType CanT = Ctx.getCanonicalType(T);
+
+  if (CanT->isPointerType())
+    return Target.getPointerWidth(0);
+
+  if (CanT->isCharType())
+    return Target.getCharWidth();
+
+  if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanT)) {
+    switch (BT->getKind()) {
+    case BuiltinType::Char_U:
+    case BuiltinType::UChar:
+    case BuiltinType::Char_S:
+    case BuiltinType::SChar:
+      return Target.getCharWidth();
+
+    case BuiltinType::UShort:
+    case BuiltinType::Short:
+      return Target.getShortWidth();
+
+    case BuiltinType::UInt:
+    case BuiltinType::Int:
+      return Target.getIntWidth();
+
+    case BuiltinType::ULong:
+    case BuiltinType::Long:
+      return Target.getLongWidth();
+    default:
+      assert(0 && "Unprocessed builtin type.");
+    }
+  }
+
+  assert(0 && "Unprocessed type.");
+}
+
 SubRegionMap* RegionStoreManager::getSubRegionMap(const GRState *state) {
   RegionBindingsTy B = GetRegionBindings(state->getStore());
   RegionStoreSubRegionMap *M = new RegionStoreSubRegionMap();
@@ -503,7 +544,17 @@
 
     // If the VarRegion is cast to other type, compute the size with respect to
     // that type.
-    
+    GRStateRef state(St, StateMgr);
+    const QualType* CastTy = state.get<RegionCasts>(VR);
+
+    if (CastTy) {
+      QualType EleTy =cast<PointerType>(CastTy->getTypePtr())->getPointeeType();
+      QualType VarTy = VR->getRValueType(getContext());
+      unsigned EleWidth = getTypeWidth(getContext(), EleTy);
+      unsigned VarWidth = getTypeWidth(getContext(), VarTy);
+      return NonLoc::MakeIntVal(getBasicVals(), VarWidth / EleWidth, false);
+    }
+
     // Clients can use ordinary variables as if they were arrays.  These
     // essentially are arrays of size 1.
     return NonLoc::MakeIntVal(getBasicVals(), 1, false);
@@ -613,7 +664,7 @@
 
 RegionStoreManager::CastResult
 RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
-                         QualType CastToTy) {
+                               QualType CastToTy) {
   
   ASTContext& Ctx = StateMgr.getContext();
 

Modified: cfe/branches/Apple/Dib/test/Analysis/xfail-no-outofbounds.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/Analysis/xfail-no-outofbounds.c?rev=71328&r1=71327&r2=71328&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/Analysis/xfail-no-outofbounds.c (original)
+++ cfe/branches/Apple/Dib/test/Analysis/xfail-no-outofbounds.c Sat May  9 01:10:47 2009
@@ -1,5 +1,5 @@
 // RUN: clang-cc -checker-cfref -analyze -analyzer-store=region -verify %s 
-// XFAIL
+
 void f() {
   long x = 0;
   char *y = (char*) &x;





More information about the llvm-branch-commits mailing list