From 33f13595c90c69e8e4938200f7777df5930b8880 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. llvm-svn: 120143 --- clang/lib/Checker/Environment.cpp | 4 ++++ clang/lib/Checker/GRExprEngine.cpp | 12 ++++++++++++ clang/test/Analysis/method-call.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/clang/lib/Checker/Environment.cpp b/clang/lib/Checker/Environment.cpp index b09cb9d60401..798f9ba9dac4 100644 --- a/clang/lib/Checker/Environment.cpp +++ b/clang/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/clang/lib/Checker/GRExprEngine.cpp b/clang/lib/Checker/GRExprEngine.cpp index 2181b705f768..6db8dbab7d8f 100644 --- a/clang/lib/Checker/GRExprEngine.cpp +++ b/clang/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/clang/test/Analysis/method-call.cpp b/clang/test/Analysis/method-call.cpp index 6cfbda895dec..8c6b9da0f401 100644 --- a/clang/test/Analysis/method-call.cpp +++ b/clang/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 + } +} +