diff options
author | Anna Zaks <ganna@apple.com> | 2011-09-15 01:08:34 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2011-09-15 01:08:34 +0000 |
commit | 3a769bd996470056b0d337c67f5339e596ea852f (patch) | |
tree | ca74f0176f1512aad0f2466e159f80acd5cc1f6a /clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp | |
parent | 4d9695a2b6c8bd2654e4f0c1628203f5e5b85a85 (diff) | |
download | bcm5719-llvm-3a769bd996470056b0d337c67f5339e596ea852f.tar.gz bcm5719-llvm-3a769bd996470056b0d337c67f5339e596ea852f.zip |
[analyzer] Refactor: make PathDiagnosticLocation responsible for validation of SourceLocations (commit 2 of ?):
- Modify all PathDiagnosticLocation constructors that take Stmt to also requre LocationContext.
- Add a constructor which should be used in case there is no valid statement/location (it will grab the location of the enclosing function).
llvm-svn: 139763
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index ac9b15e743d..8d53b2b3803 100644 --- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -156,23 +156,20 @@ PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N, static SourceLocation getValidSourceLocation(const Stmt* S, const LocationContext *LC) { + assert(LC); SourceLocation L = S->getLocStart(); // S might be a temporary statement that does not have a location in the // source code, so find an enclosing statement and use it's location. - if (!L.isValid() && LC) { - assert(LC); + if (!L.isValid()) { ParentMap & PM = LC->getParentMap(); - const Stmt *PS = S; while (!L.isValid()) { - PS = PM.getParent(PS); - L = PS->getLocStart(); + S = PM.getParent(S); + L = S->getLocStart(); } } - // TODO: either change the name or uncomment the assert. - //assert(L.isValid()); return L; } @@ -191,6 +188,10 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const { return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM)); } + if (!R.isValid()) + return FullSourceLoc(LC->getDecl()->getBodyRBrace(), + const_cast<SourceManager&>(*SM)); + return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(*SM)); } |