diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 7 | ||||
-rw-r--r-- | clang/test/Analysis/casts.cpp | 14 |
2 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp index 5a306a5c5f2..1221ddff765 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -257,6 +257,13 @@ ProgramStateRef ExprEngine::handleLValueBitCast( 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); diff --git a/clang/test/Analysis/casts.cpp b/clang/test/Analysis/casts.cpp index f96f19b0ac3..6499b20a79d 100644 --- a/clang/test/Analysis/casts.cpp +++ b/clang/test/Analysis/casts.cpp @@ -21,3 +21,17 @@ void intAsBoolAsSwitchCondition(int c) { 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 +} |