Index: lib/StaticAnalyzer/Core/ExprEngineC.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -257,6 +257,13 @@ ProgramStateRef state, const Expr* Ex, const LocationContext* LCtx, QualType T, QualType ExTy, const CastExpr* CastE, StmtNodeBuilder& Bldr, ExplodedNode* Pred) { + if (T->isLValueReferenceType()) { + assert(!CastE->getType()->isLValueReferenceType()); + ExTy = getContext().getLValueReferenceType(ExTy); + } else if (T->isRValueReferenceType()) { + assert(!CastE->getType()->isRValueReferenceType()); + ExTy = getContext().getRValueReferenceType(ExTy); + } // Delegate to SValBuilder to process. SVal OrigV = state->getSVal(Ex, LCtx); SVal V = svalBuilder.evalCast(OrigV, T, ExTy); Index: test/Analysis/casts.cpp =================================================================== --- test/Analysis/casts.cpp +++ test/Analysis/casts.cpp @@ -21,3 +21,17 @@ break; } } + +int *&castToIntPtrLValueRef(char *p) { + return (int *&)*(int *)p; +} +bool testCastToIntPtrLValueRef(char *p, int *s) { + return castToIntPtrLValueRef(p) != s; // no-crash +} + +int *&&castToIntPtrRValueRef(char *p) { + return (int *&&)*(int *)p; +} +bool testCastToIntPtrRValueRef(char *p, int *s) { + return castToIntPtrRValueRef(p) != s; // no-crash +}