aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/DereferenceChecker.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-11-24 01:33:10 +0000
committerTed Kremenek <kremenek@apple.com>2009-11-24 01:33:10 +0000
commite576af2754bfa309bb10a518bbc17c81b9e0723f (patch)
tree5566c6943c4f7f4ba4e7029eac9dd5aba16b9ada /lib/Analysis/DereferenceChecker.cpp
parent33a33d8abd7a3d49eacc05e40c00b00634bf1ee9 (diff)
Enhance null dereference diagnostics by indicating what variable (if any) was dereferenced. Addresses <rdar://problem/7039161>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DereferenceChecker.cpp')
-rw-r--r--lib/Analysis/DereferenceChecker.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Analysis/DereferenceChecker.cpp b/lib/Analysis/DereferenceChecker.cpp
index 4c4091cbc2..4a9312377a 100644
--- a/lib/Analysis/DereferenceChecker.cpp
+++ b/lib/Analysis/DereferenceChecker.cpp
@@ -90,11 +90,31 @@ void DereferenceChecker::VisitLocation(CheckerContext &C, const Stmt *S,
// We know that 'location' cannot be non-null. This is what
// we call an "explicit" null dereference.
if (!BT_null)
- BT_null = new BuiltinBug("Null pointer dereference",
- "Dereference of null pointer");
+ BT_null = new BuiltinBug("Dereference of null pointer");
+
+ llvm::SmallString<100> buf;
+
+ switch (S->getStmtClass()) {
+ case Stmt::UnaryOperatorClass: {
+ const UnaryOperator *U = cast<UnaryOperator>(S);
+ const Expr *SU = U->getSubExpr()->IgnoreParens();
+ if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(SU)) {
+ if (const VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
+ llvm::raw_svector_ostream os(buf);
+ os << "Dereference of null pointer loaded from variable '"
+ << VD->getName() << '\'';
+ }
+ }
+ }
+ default:
+ break;
+ }
EnhancedBugReport *report =
- new EnhancedBugReport(*BT_null, BT_null->getDescription(), N);
+ new EnhancedBugReport(*BT_null,
+ buf.empty() ? BT_null->getDescription():buf.str(),
+ N);
+
report->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue,
bugreporter::GetDerefExpr(N));