From 3ebc5057acc577c5d184449ecb42f4c13b042301 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 23 Apr 2009 16:44:22 +0000 Subject: [PATCH] BugReporter (extensive diagnostics): Recursively adjust the referred expression when popping location contexts. llvm-svn: 69898 --- clang/lib/Analysis/BugReporter.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/clang/lib/Analysis/BugReporter.cpp b/clang/lib/Analysis/BugReporter.cpp index e0b1b6540f10..b64182e2f355 100644 --- a/clang/lib/Analysis/BugReporter.cpp +++ b/clang/lib/Analysis/BugReporter.cpp @@ -790,18 +790,22 @@ class VISIBILITY_HIDDEN EdgeBuilder { PathDiagnosticLocation L = CLocs.back(); if (L.asLocation().isFileID()) { - if (const Stmt *S = L.asStmt()) { - // Adjust the location for some expressions that are best referenced - // by one of their subexpressions. - if (const ConditionalOperator *CO = dyn_cast(S)) - S = CO->getCond(); - else if (const ChooseExpr *CE = dyn_cast(S)) - S = CE->getCond(); - - // Ignore parentheses. - if (const ParenExpr *PE = dyn_cast(S)) - S = PE->IgnoreParens(); - + if (const Stmt *S = L.asStmt()) { + 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; + } + L = PathDiagnosticLocation(S, L.getManager()); }