From: Ted Kremenek Date: Thu, 5 Mar 2009 02:42:32 +0000 (+0000) Subject: GRExprEngine: Polish up handling of casting integer constants to pointers and back. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efcfcc0e27ade4e0bb6626824f2bdc0a01bab32b;p=clang GRExprEngine: Polish up handling of casting integer constants to pointers and back. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66127 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 415bc3f88a..24250166c2 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -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(V), bits); + + if (loc::ConcreteInt *CI = dyn_cast(&V)) { + V = nonloc::ConcreteInt(CI->getValue()); + } + else { + unsigned bits = getContext().getTypeSize(PtrTy); + V = nonloc::LocAsInteger::Make(getBasicVals(), cast(V), bits); + } } MakeNode(Dst, CastE, Pred, BindExpr(state, CastE, V)); diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c index b320e8dd19..fe94d6fe7c 100644 --- a/test/Analysis/null-deref-ps.c +++ b/test/Analysis/null-deref-ps.c @@ -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 +} + +