[cfe-commits] r66127 - in /cfe/trunk: lib/Analysis/GRExprEngine.cpp test/Analysis/null-deref-ps.c

Ted Kremenek kremenek at apple.com
Wed Mar 4 18:42:32 PST 2009


Author: kremenek
Date: Wed Mar  4 20:42:32 2009
New Revision: 66127

URL: http://llvm.org/viewvc/llvm-project?rev=66127&view=rev
Log:
GRExprEngine: Polish up handling of casting integer constants to pointers and back.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/test/Analysis/null-deref-ps.c

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Mar  4 20:42:32 2009
@@ -1720,8 +1720,14 @@
     // 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));

Modified: cfe/trunk/test/Analysis/null-deref-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps.c?rev=66127&r1=66126&r2=66127&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Wed Mar  4 20:42:32 2009
@@ -213,3 +213,10 @@
   *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
+}
+
+





More information about the cfe-commits mailing list