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 | 6dc9c4814f40a2f4921245cb61aee25b8c418985 (patch) | |
tree | 555605d42602f4f86c2554be77b442aea54e85b1 /clang | |
parent | e8172d85f9fa6df413ffce29e2fde5b65503d32b (diff) | |
download | bcm5719-llvm-6dc9c4814f40a2f4921245cb61aee25b8c418985.tar.gz bcm5719-llvm-6dc9c4814f40a2f4921245cb61aee25b8c418985.zip |
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
llvm-svn: 208315
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticFrontendKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 13 | ||||
-rw-r--r-- | clang/test/Frontend/optimization-remark-line-directive.c | 15 |
3 files changed, 27 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index 674d6d6c42f..8fd77aef88b 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -37,6 +37,8 @@ def remark_fe_backend_optimization_remark : Remark<"%0">, CatBackend, def note_fe_backend_optimization_remark_missing_loc : Note<"use " "-gline-tables-only -gcolumn-info to track source location information " "for this optimization remark">; +def note_fe_backend_optimization_remark_invalid_loc : Note<"could " + "not determine the original source location for %0:%1:%2">; def err_fe_invalid_code_complete_file : Error< "cannot locate code-completion file %0">, DefaultFatal; diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 795b127e31c..b0c5fa12e65 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/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; } } diff --git a/clang/test/Frontend/optimization-remark-line-directive.c b/clang/test/Frontend/optimization-remark-line-directive.c new file mode 100644 index 00000000000..b4b1b923249 --- /dev/null +++ b/clang/test/Frontend/optimization-remark-line-directive.c @@ -0,0 +1,15 @@ +// This file tests -Rpass diagnostics together with #line +// directives. We cannot map #line directives back to +// a SourceLocation. + +// RUN: %clang -c %s -Rpass=inline -O0 -S -gmlt -o /dev/null 2> %t.err +// RUN: FileCheck < %t.err %s --check-prefix=INLINE-INVALID-LOC +// +int foo(int x, int y) __attribute__((always_inline)); +int foo(int x, int y) { return x + y; } + +#line 1230 "/bad/path/to/original.c" +int bar(int j) { return foo(j, j - 2); } + +// INLINE-INVALID-LOC: {{^remark: foo inlined into bar}} +// INLINE-INVALID-LOC: note: could not determine the original source location for /bad/path/to/original.c:1230:0 |