diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2016-11-23 13:10:07 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2016-11-23 13:10:07 +0000 |
| commit | 66039d39e1d1a0363b7a0616f093e031e7a42cb3 (patch) | |
| tree | e82c8d5722b15a26cd64b0e12b8b65641e8f2a20 | |
| parent | 8a3c49897f26525bfef41ec32603f3bc74d5c561 (diff) | |
| download | bcm5719-llvm-66039d39e1d1a0363b7a0616f093e031e7a42cb3.tar.gz bcm5719-llvm-66039d39e1d1a0363b7a0616f093e031e7a42cb3.zip | |
[clang-rename] Fix non-functional offset check.
Adding something to a SourceLocation will only produce an invalid
SourceLocation in edge cases (overflow or adding 0 to an invalid one).
Check that the offset is inside the file instead and add a test case to
verify that the error message works.
llvm-svn: 287758
| -rw-r--r-- | clang-tools-extra/clang-rename/USRFindingAction.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-rename/USRFindingAction.cpp b/clang-tools-extra/clang-rename/USRFindingAction.cpp index e04362b969e..8fd19667777 100644 --- a/clang-tools-extra/clang-rename/USRFindingAction.cpp +++ b/clang-tools-extra/clang-rename/USRFindingAction.cpp @@ -150,21 +150,20 @@ private: bool FindSymbol(ASTContext &Context, const SourceManager &SourceMgr, unsigned SymbolOffset, const std::string &QualifiedName) { DiagnosticsEngine &Engine = Context.getDiagnostics(); + const FileID MainFileID = SourceMgr.getMainFileID(); - const SourceLocation Point = - SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()) - .getLocWithOffset(SymbolOffset); - - if (!Point.isValid()) { + if (SymbolOffset >= SourceMgr.getFileIDSize(MainFileID)) { ErrorOccurred = true; unsigned InvalidOffset = Engine.getCustomDiagID( DiagnosticsEngine::Error, "SourceLocation in file %0 at offset %1 is invalid"); - Engine.Report(Point, InvalidOffset) << SourceMgr.getFilename(Point) - << SymbolOffset; + Engine.Report(SourceLocation(), InvalidOffset) + << SourceMgr.getFileEntryForID(MainFileID)->getName() << SymbolOffset; return false; } + const SourceLocation Point = SourceMgr.getLocForStartOfFile(MainFileID) + .getLocWithOffset(SymbolOffset); const NamedDecl *FoundDecl = QualifiedName.empty() ? getNamedDeclAt(Context, Point) : getNamedDeclFor(Context, QualifiedName); |

