]> granicus.if.org Git - clang/commitdiff
GRExprEngine: Polish up handling of casting integer constants to pointers and back.
authorTed Kremenek <kremenek@apple.com>
Thu, 5 Mar 2009 02:42:32 +0000 (02:42 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 5 Mar 2009 02:42:32 +0000 (02:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66127 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp
test/Analysis/null-deref-ps.c

index 415bc3f88a1ce2a7ef76750d151107842e5c125a..24250166c2edabfe103a91db15869f361b284610 100644 (file)
@@ -1720,8 +1720,14 @@ void GRExprEngine::VisitCastPointerToInteger(SVal V, const GRState* state,
     // FIXME: Determine if the number of bits of the target type is 
     // equal or exceeds the number of bits to store the pointer value.
     // If not, flag an error.
-    unsigned bits = getContext().getTypeSize(PtrTy);  
-    V = nonloc::LocAsInteger::Make(getBasicVals(), cast<Loc>(V), bits);
+    
+    if (loc::ConcreteInt *CI = dyn_cast<loc::ConcreteInt>(&V)) {
+      V = nonloc::ConcreteInt(CI->getValue());
+    }
+    else {    
+      unsigned bits = getContext().getTypeSize(PtrTy);  
+      V = nonloc::LocAsInteger::Make(getBasicVals(), cast<Loc>(V), bits);
+    }
   }
   
   MakeNode(Dst, CastE, Pred, BindExpr(state, CastE, V));
index b320e8dd191fb1ee786181633e5f33949eb664c8..fe94d6fe7c85342ca02d44cb6073705d859b0922 100644 (file)
@@ -213,3 +213,10 @@ void f12(HF12ITEM i, char *q) {
   *p = 1; // no-warning
 }
 
+// Test handling of translating between integer "pointers" and back.
+void f13() {
+  int *x = 0;
+  if (((((int) x) << 2) + 1) >> 1) *x = 1; // no-warning
+}
+
+