From: Ted Kremenek Date: Mon, 11 May 2009 21:42:34 +0000 (+0000) Subject: EdgeBuilder::cleanUpLocation() should used the PathDiagnosticLocation constructor... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9650cf3b08fcd66caae39bd5a1915c3eac735095;p=clang EdgeBuilder::cleanUpLocation() should used the PathDiagnosticLocation constructor for a single point, not a range. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71477 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index 661043a92d..5407cea4e2 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -777,36 +777,51 @@ class VISIBILITY_HIDDEN EdgeBuilder { PathDiagnosticLocation getContextLocation(const PathDiagnosticLocation &L); - PathDiagnosticLocation cleanUpLocation(const PathDiagnosticLocation &L) { + PathDiagnosticLocation cleanUpLocation(PathDiagnosticLocation L, + bool firstCharOnly = false) { if (const Stmt *S = L.asStmt()) { + const Stmt *Original = S; while (1) { // Adjust the location for some expressions that are best referenced // by one of their subexpressions. - if (const ParenExpr *PE = dyn_cast(S)) - S = PE->IgnoreParens(); - else if (const ConditionalOperator *CO = dyn_cast(S)) - S = CO->getCond(); - else if (const ChooseExpr *CE = dyn_cast(S)) - S = CE->getCond(); - else if (const BinaryOperator *BE = dyn_cast(S)) - S = BE->getLHS(); - else - break; + switch (S->getStmtClass()) { + default: + break; + case Stmt::ParenExprClass: + S = cast(S)->IgnoreParens(); + firstCharOnly = true; + continue; + case Stmt::ConditionalOperatorClass: + S = cast(S)->getCond(); + firstCharOnly = true; + continue; + case Stmt::ChooseExprClass: + S = cast(S)->getCond(); + firstCharOnly = true; + continue; + case Stmt::BinaryOperatorClass: + S = cast(S)->getLHS(); + firstCharOnly = true; + continue; + } + + break; } - return PathDiagnosticLocation(S, L.getManager()); + if (S != Original) + L = PathDiagnosticLocation(S, L.getManager()); } + if (firstCharOnly) + L = PathDiagnosticLocation(L.asLocation()); + return L; } void popLocation() { if (!CLocs.back().isDead() && CLocs.back().asLocation().isFileID()) { - PathDiagnosticLocation L = cleanUpLocation(CLocs.back()); - // For contexts, we only one the first character as the range. - L = PathDiagnosticLocation(L.asLocation(), L.getManager()); - rawAddEdge(L); + rawAddEdge( cleanUpLocation(CLocs.back(), true)); } CLocs.pop_back(); }