[analyzer] Re-enable reasoning about CK_LValueBitCast

It’s important for us to reason about the cast as it is used in std::addressof. The reason we did not
handle the cast previously was a crash on a test case (see commit r157478). The crash was in
processing array to pointer decay when the region type was not an array. Address the issue, by
just returning an unknown in that case.

llvm-svn: 182808
This commit is contained in:
Anna Zaks 2013-05-28 22:32:08 +00:00
parent 0259300325
commit 6477e97af7
3 changed files with 24 additions and 4 deletions

View File

@ -309,7 +309,8 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
case CK_BlockPointerToObjCPointerCast:
case CK_AnyPointerToBlockPointerCast:
case CK_ObjCObjectLValueCast:
case CK_ZeroToOCLEvent: {
case CK_ZeroToOCLEvent:
case CK_LValueBitCast: {
// Delegate to SValBuilder to process.
SVal V = state->getSVal(Ex, LCtx);
V = svalBuilder.evalCast(V, T, ExTy);
@ -381,8 +382,7 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex,
case CK_BaseToDerivedMemberPointer:
case CK_DerivedToBaseMemberPointer:
case CK_ReinterpretMemberPointer:
case CK_VectorSplat:
case CK_LValueBitCast: {
case CK_VectorSplat: {
// Recover some path-sensitivty by conjuring a new value.
QualType resultType = CastE->getType();
if (CastE->isGLValue())

View File

@ -1262,7 +1262,10 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) {
// Strip off typedefs from the ArrayRegion's ValueType.
QualType T = ArrayR->getValueType().getDesugaredType(Ctx);
const ArrayType *AT = cast<ArrayType>(T);
const ArrayType *AT = dyn_cast<ArrayType>(T);
if (!AT)
return UnknownVal();
T = AT->getElementType();
NonLoc ZeroIdx = svalBuilder.makeZeroArrayIndex();

View File

@ -86,3 +86,20 @@ namespace PR15345 {
clang_analyzer_eval(p->x == 42); // expected-warning{{TRUE}}
};
}
int trackpointer_std_addressof() {
int x;
int *p = (int*)&reinterpret_cast<const volatile char&>(x);
*p = 6;
return x; // no warning
}
void set_x1(int *&);
void set_x2(void *&);
int radar_13146953(void) {
int *x = 0, *y = 0;
set_x1(x);
set_x2((void *&)y);
return *x + *y; // no warning
}