Diagnostics: if a line is longer than 4096 characters, don't print it.
Specifically, don't print snippets, caret diagnostics, or ranges for lines over 4096 characters. We copy the line around a few times in our diagnostics machinery, and we have to print a caret line that's just as long. This uses a lot of memory just to create a poor user experience as we print out a line much too long for anyone to read...or spend extra energy trying to fit it to -fmessage-length. <rdar://problem/13106850> llvm-svn: 173976
This commit is contained in:
parent
6f18ae1ec8
commit
2da0d1cfd3
|
@ -1096,18 +1096,26 @@ void TextDiagnostic::emitSnippetAndCaret(
|
||||||
|
|
||||||
unsigned LineNo = SM.getLineNumber(FID, FileOffset);
|
unsigned LineNo = SM.getLineNumber(FID, FileOffset);
|
||||||
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
|
unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
|
||||||
|
|
||||||
|
// Arbitrarily stop showing snippets when the line is too long.
|
||||||
|
static const unsigned MaxLineLength = 4096;
|
||||||
|
if (ColNo > MaxLineLength)
|
||||||
|
return;
|
||||||
|
|
||||||
// Rewind from the current position to the start of the line.
|
// Rewind from the current position to the start of the line.
|
||||||
const char *TokPtr = BufStart+FileOffset;
|
const char *TokPtr = BufStart+FileOffset;
|
||||||
const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based.
|
const char *LineStart = TokPtr-ColNo+1; // Column # is 1-based.
|
||||||
|
|
||||||
|
|
||||||
// Compute the line end. Scan forward from the error position to the end of
|
// Compute the line end. Scan forward from the error position to the end of
|
||||||
// the line.
|
// the line.
|
||||||
const char *LineEnd = TokPtr;
|
const char *LineEnd = TokPtr;
|
||||||
while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
|
while (*LineEnd != '\n' && *LineEnd != '\r' && *LineEnd != '\0')
|
||||||
++LineEnd;
|
++LineEnd;
|
||||||
|
|
||||||
|
// Arbitrarily stop showing snippets when the line is too long.
|
||||||
|
if (LineEnd - LineStart > MaxLineLength)
|
||||||
|
return;
|
||||||
|
|
||||||
// Copy the line of code into an std::string for ease of manipulation.
|
// Copy the line of code into an std::string for ease of manipulation.
|
||||||
std::string SourceLine(LineStart, LineEnd);
|
std::string SourceLine(LineStart, LineEnd);
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue