[cfe-commits] r47873 - in /cfe/trunk: Analysis/GRExprEngine.cpp Analysis/GRSimpleVals.cpp include/clang/Analysis/PathSensitive/GRExprEngine.h
Ted Kremenek
kremenek at apple.com
Mon Mar 3 16:42:54 PST 2008
Author: kremenek
Date: Mon Mar 3 18:42:54 2008
New Revision: 47873
URL: http://llvm.org/viewvc/llvm-project?rev=47873&view=rev
Log:
Enhanced pretty-printing of undefined-argument errors.
Modified:
cfe/trunk/Analysis/GRExprEngine.cpp
cfe/trunk/Analysis/GRSimpleVals.cpp
cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
Modified: cfe/trunk/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRExprEngine.cpp?rev=47873&r1=47872&r2=47873&view=diff
==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Mon Mar 3 18:42:54 2008
@@ -494,7 +494,7 @@
if (N) {
N->markAsSink();
- UndefArgs.insert(N);
+ UndefArgs[N] = CurrentArg;
}
continue;
Modified: cfe/trunk/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRSimpleVals.cpp?rev=47873&r1=47872&r2=47873&view=diff
==============================================================================
--- cfe/trunk/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/Analysis/GRSimpleVals.cpp Mon Mar 3 18:42:54 2008
@@ -23,6 +23,38 @@
namespace clang {
template <typename ITERATOR>
+static inline const PostStmt& GetLocation(ITERATOR I) {
+ return cast<PostStmt>((*I)->getLocation());
+}
+
+template <>
+static inline const PostStmt& GetLocation(GRExprEngine::undef_arg_iterator I) {
+ return cast<PostStmt>(I->first->getLocation());
+}
+
+template <typename ITERATOR>
+static void EmitDiag(Diagnostic& Diag, SourceManager& SrcMgr,
+ unsigned ErrorDiag, ITERATOR I) {
+
+ Expr* Exp = cast<Expr>(GetLocation(I).getStmt());
+ cast<Expr>(GetLocation(I).getStmt());
+ Diag.Report(FullSourceLoc(Exp->getExprLoc(), SrcMgr), ErrorDiag);
+}
+
+
+template <>
+static void EmitDiag(Diagnostic& Diag, SourceManager& SrcMgr,
+ unsigned ErrorDiag, GRExprEngine::undef_arg_iterator I) {
+
+ Expr* E1 = cast<Expr>(GetLocation(I).getStmt());
+ Expr* E2 = cast<Expr>(I->second);
+
+ SourceLocation Loc = E1->getExprLoc();
+ SourceRange R = E2->getSourceRange();
+ Diag.Report(FullSourceLoc(Loc, SrcMgr), ErrorDiag, 0, 0, &R, 1);
+}
+
+template <typename ITERATOR>
static void EmitWarning(Diagnostic& Diag, SourceManager& SrcMgr,
ITERATOR I, ITERATOR E, const char* msg) {
@@ -32,8 +64,7 @@
bool isFirst = true;
unsigned ErrorDiag;
- llvm::SmallPtrSet<void*,10> CachedErrors;
-
+ llvm::SmallPtrSet<void*,10> CachedErrors;
for (; I != E; ++I) {
@@ -46,18 +77,15 @@
// HACK: Cache the location of the error. Don't emit the same
// warning for the same error type that occurs at the same program
// location but along a different path.
- void* p = (*I)->getLocation().getRawData();
+ void* p = GetLocation(I).getRawData();
if (CachedErrors.count(p))
continue;
CachedErrors.insert(p);
}
-
- const PostStmt& L = cast<PostStmt>((*I)->getLocation());
- Expr* Exp = cast<Expr>(L.getStmt());
-
- Diag.Report(FullSourceLoc(Exp->getExprLoc(), SrcMgr), ErrorDiag);
+
+ EmitDiag(Diag, SrcMgr, ErrorDiag, I);
}
}
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=47873&r1=47872&r2=47873&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Mon Mar 3 18:42:54 2008
@@ -91,7 +91,7 @@
typedef llvm::SmallPtrSet<NodeTy*,2> UndefStoresTy;
typedef llvm::SmallPtrSet<NodeTy*,2> BadDerefTy;
typedef llvm::SmallPtrSet<NodeTy*,2> BadCallsTy;
- typedef llvm::SmallPtrSet<NodeTy*,2> UndefArgsTy;
+ typedef llvm::DenseMap<NodeTy*, Expr*> UndefArgsTy;
typedef llvm::SmallPtrSet<NodeTy*,2> BadDividesTy;
typedef llvm::SmallPtrSet<NodeTy*,2> NoReturnCallsTy;
typedef llvm::SmallPtrSet<NodeTy*,2> UndefResultsTy;
@@ -209,7 +209,8 @@
}
bool isUndefArg(const NodeTy* N) const {
- return N->isSink() && UndefArgs.count(const_cast<NodeTy*>(N)) != 0;
+ return N->isSink() &&
+ UndefArgs.find(const_cast<NodeTy*>(N)) != UndefArgs.end();
}
typedef BadDerefTy::iterator null_deref_iterator;
More information about the cfe-commits
mailing list