From 0e38d5d6775a26f8f39df353e34b0dc14c2d6cfc Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Thu, 25 Nov 2010 03:18:57 +0000 Subject: [PATCH] handle CXXFunctionalCastExpr in visitLValue and Environment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120143 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Checker/Environment.cpp | 4 ++++ lib/Checker/GRExprEngine.cpp | 12 ++++++++++++ test/Analysis/method-call.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/Checker/Environment.cpp b/lib/Checker/Environment.cpp index b09cb9d604..798f9ba9da 100644 --- a/lib/Checker/Environment.cpp +++ b/lib/Checker/Environment.cpp @@ -78,6 +78,10 @@ SVal Environment::GetSVal(const Stmt *E, ValueManager& ValMgr) const { case Stmt::CXXBindTemporaryExprClass: E = cast(E)->getSubExpr(); continue; + + case Stmt::CXXFunctionalCastExprClass: + E = cast(E)->getSubExpr(); + continue; // Handle all other Stmt* using a lookup. default: diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index 2181b705f7..6db8dbab7d 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -1158,6 +1158,18 @@ void GRExprEngine::VisitLValue(const Expr* Ex, ExplodedNode* Pred, break; } + case Stmt::CXXConstructExprClass: { + const CXXConstructExpr *expr = cast(Ex); + VisitCXXConstructExpr(expr, 0, Pred, Dst, true); + break; + } + + case Stmt::CXXFunctionalCastExprClass: { + const CXXFunctionalCastExpr *expr = cast(Ex); + VisitLValue(expr->getSubExpr(), Pred, Dst); + break; + } + case Stmt::CXXTemporaryObjectExprClass: { const CXXTemporaryObjectExpr *expr = cast(Ex); VisitCXXTemporaryObjectExpr(expr, Pred, Dst, true); diff --git a/test/Analysis/method-call.cpp b/test/Analysis/method-call.cpp index 6cfbda895d..8c6b9da0f4 100644 --- a/test/Analysis/method-call.cpp +++ b/test/Analysis/method-call.cpp @@ -17,3 +17,14 @@ void f1() { } } +void f2() { + const A &x = A(3); + if (x.getx() == 3) { + int *p = 0; + *p = 3; // expected-warning{{Dereference of null pointer}} + } else { + int *p = 0; + *p = 3; // no-warning + } +} + -- 2.40.0