diff --git a/clang/include/clang/Analysis/PathDiagnostic.h b/clang/include/clang/Analysis/PathDiagnostic.h index f647be9d6dc9..1481e25bbdb0 100644 --- a/clang/include/clang/Analysis/PathDiagnostic.h +++ b/clang/include/clang/Analysis/PathDiagnostic.h @@ -67,7 +67,7 @@ public: FullSourceLoc asLocation() const; SourceRange asRange() const; - const Stmt *asStmt() const; + const Stmt *asStmt() const { return S ? S : 0; } }; class PathDiagnostic { diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp index 1441088e547e..dd9a0a8f4605 100644 --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -152,3 +152,18 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const { return FullSourceLoc(R.getBegin(), const_cast(SM)); } + +SourceRange PathDiagnosticLocation::asRange() const { + // Note that we want a 'switch' here so that the compiler can warn us in + // case we add more cases. + switch (K) { + case SingleLoc: + case Range: + break; + case Statement: + return S->getSourceRange(); + } + + return R; +} +