diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-13 01:08:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-13 01:08:23 +0000 |
commit | 44219f3e5872b82fcddffd29fbc7ee6314459686 (patch) | |
tree | 599e76e594aeb24b13cb1e178548d603d07eb36d /clang/lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | f0db0aed67db2846373a8cd7ee157c035ad9e637 (diff) | |
download | bcm5719-llvm-44219f3e5872b82fcddffd29fbc7ee6314459686.tar.gz bcm5719-llvm-44219f3e5872b82fcddffd29fbc7ee6314459686.zip |
implement a new -fprint-source-range-info option, which
defaults to off. When enabled, it emits range info along
with the file/line/col information for a diagnostic. This
allows tools that textually parse the output of clang to know
where the ranges are, even if they span multiple lines. For
example, with:
$ clang exprs.c -fprint-source-range-info
We now produce:
exprs.c:21:11:{21:12-21:13}: warning: use of unary operator that may be intended as compound assignment (+=)
var =+ 5; // expected-warning {{use of unary operator that may be intended as compound assignment (+=)}}
^~
exprs.c:22:11:{22:12-22:13}: warning: use of unary operator that may be intended as compound assignment (-=)
var =- 5; // expected-warning {{use of unary operator that may be intended as compound assignment (-=)}}
^~
exprs.c:36:13:{36:3-36:12}: error: assignment to cast is illegal, lvalue casts are not supported
(float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
~~~~~~~~~ ^
exprs.c:41:4:{41:3-41:4}: error: called object type 'int' is not a function or function pointer
X(); // expected-error {{called object type 'int' is not a function or function pointer}}
~^
exprs.c:45:15:{45:8-45:14}{45:17-45:24}: error: invalid operands to binary expression ('int *' and '_Complex float')
P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
~~~~~~ ^ ~~~~~~~
exprs.c:61:7:{61:16-61:22}: error: invalid application of '__alignof' to bitfield
R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
^ ~~~~~~
Note the range info after the column in the initial diagnostic.
This is obviously really annoying if you're not a tool parsing the
output of clang, which is why it is off by default.
llvm-svn: 66862
Diffstat (limited to 'clang/lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticPrinter.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp index 160b5cfae11..f1555dbff31 100644 --- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp @@ -261,6 +261,38 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, if (ShowColumn) if (unsigned ColNo = PLoc.getColumn()) OS << ColNo << ':'; + + if (PrintRangeInfo && Info.getNumRanges()) { + FileID CaretFileID = + SM.getFileID(SM.getInstantiationLoc(Info.getLocation())); + bool PrintedRange = false; + + for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i) { + SourceLocation B = Info.getRange(i).getBegin(); + SourceLocation E = Info.getRange(i).getEnd(); + std::pair<FileID, unsigned> BInfo=SM.getDecomposedInstantiationLoc(B); + + E = SM.getInstantiationLoc(E); + std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E); + + // If the start or end of the range is in another file, just discard + // it. + if (BInfo.first != CaretFileID || EInfo.first != CaretFileID) + continue; + + // Add in the length of the token, so that we cover multi-char tokens. + unsigned TokSize = Lexer::MeasureTokenLength(E, SM); + + OS << '{' << SM.getLineNumber(BInfo.first, BInfo.second) << ':' + << SM.getColumnNumber(BInfo.first, BInfo.second) << '-' + << SM.getLineNumber(EInfo.first, EInfo.second) << ':' + << (SM.getColumnNumber(EInfo.first, EInfo.second)+TokSize) << '}'; + PrintedRange = true; + } + + if (PrintedRange) + OS << ':'; + } OS << ' '; } } |