GRExprEngine: Polish up handling of casting integer constants to pointers and back.

llvm-svn: 66127
This commit is contained in:
Ted Kremenek 2009-03-05 02:42:32 +00:00
parent cd1280b405
commit eba836a457
2 changed files with 15 additions and 2 deletions

View 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));

View 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
}