diff options
| author | Diego Novillo <dnovillo@google.com> | 2014-05-08 13:49:54 +0000 |
|---|---|---|
| committer | Diego Novillo <dnovillo@google.com> | 2014-05-08 13:49:54 +0000 |
| commit | 459bb10b61a5492e2840993d73905b97ca3375ed (patch) | |
| tree | ca4f8340390202f8dd051c6962b9f08919fa44fb /lib/CodeGen/CodeGenAction.cpp | |
| parent | c52c190c1e790317e6448902fbf08511fb6c1789 (diff) | |
| download | clang-459bb10b61a5492e2840993d73905b97ca3375ed.tar.gz clang-459bb10b61a5492e2840993d73905b97ca3375ed.tar.bz2 clang-459bb10b61a5492e2840993d73905b97ca3375ed.tar.xz | |
Fix segmentation fault when mixing -Rpass with #line.
Summary:
When using #line directives, FileManager::getFile() will return a nil
entry. This triggers an assert in translateFileLineCol().
This patch handles nil FileEntry instances by emitting a note that the
location could not be translated back to a SourceLocation. I don't
really like this solution, but we are translating presumed locations,
so some information has already been lost.
Reviewers: rsmith
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3625
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208315 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenAction.cpp')
| -rw-r--r-- | lib/CodeGen/CodeGenAction.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 795b127e31..b0c5fa12e6 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -396,13 +396,13 @@ void BackendConsumer::OptimizationRemarkHandler( unsigned Line, Column; D.getLocation(&Filename, &Line, &Column); SourceLocation Loc; - if (Line > 0) { + const FileEntry *FE = FileMgr.getFile(Filename); + if (FE && Line > 0) { // If -gcolumn-info was not used, Column will be 0. This upsets the // source manager, so if Column is not set, set it to 1. if (Column == 0) Column = 1; - Loc = SourceMgr.translateFileLineCol(FileMgr.getFile(Filename), Line, - Column); + Loc = SourceMgr.translateFileLineCol(FE, Line, Column); } Diags.Report(Loc, diag::remark_fe_backend_optimization_remark) << AddFlagValue(D.getPassName()) << D.getMsg().str(); @@ -415,6 +415,13 @@ void BackendConsumer::OptimizationRemarkHandler( // -Rpass is used. !srcloc annotations need to be emitted in // approximately the same spots as !dbg nodes. Diags.Report(diag::note_fe_backend_optimization_remark_missing_loc); + else if (Loc.isInvalid()) + // If we were not able to translate the file:line:col information + // back to a SourceLocation, at least emit a note stating that + // we could not translate this location. This can happen in the + // case of #line directives. + Diags.Report(diag::note_fe_backend_optimization_remark_invalid_loc) + << Filename << Line << Column; } } |
