Commit Graph

60 Commits

Author SHA1 Message Date
Benjamin Kramer d408de6a2e Make compares unsigned. The expression can't become negative anyways.
Silences a sign compare warning on 32 bit archs.

llvm-svn: 180110
2013-04-23 14:42:47 +00:00
Ted Kremenek 90d7fa12d0 Fix buffer underrun (invalid read) triggered during diagnostic rendering. The test would overflow when computing '0 - 1'.
I don't have a good testcase for this that does not depend on system headers.
It did not trigger with preprocessed output, and I had trouble reducing the example.

Fixes <rdar://problem/13324594>.

Thanks to Michael Greiner for reporting this issue.

llvm-svn: 177201
2013-03-15 23:09:37 +00:00
Jordan Rose a7d03840e6 Excise <cctype> from Clang (except clang-tblgen) in favor of CharInfo.h.
Nearly all of these changes are one-to-one replacements; the few that
aren't have to do with custom identifier validation.

llvm-svn: 174768
2013-02-08 22:30:41 +00:00
NAKAMURA Takumi 0120178909 TextDiagnostic.cpp: Suppress a warning to use ptrdiff_t on i686-clang. [-Wsign-compare]
llvm-svn: 174353
2013-02-05 07:37:07 +00:00
Jordan Rose c40b0fab06 Diagnostics: Clarify name of line-length-limiting constant in r173976.
Thanks, Sean.

llvm-svn: 173981
2013-01-30 22:14:15 +00:00
Jordan Rose 2da0d1cfd3 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
2013-01-30 21:41:07 +00:00
Dmitri Gribenko 9feeef40f5 Move UTF conversion routines from clang/lib/Basic to llvm/lib/Support
This is required to use them in TableGen.

llvm-svn: 173924
2013-01-30 12:06:08 +00:00
Douglas Gregor dfc9430bc7 Be defensive when printing module import locations; the diagnostic printer needs to be robust
llvm-svn: 170466
2012-12-18 23:02:07 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00
Benjamin Kramer 2a812288c7 Make helper classes anonymous. Make helper functions static instead of private members so the anonymous class doesn't leak out.
No functionality change.

llvm-svn: 169099
2012-12-01 20:58:01 +00:00
Douglas Gregor 22103e3416 When we're emitting a diagnostic with a source location in an imported
module, provide a module import stack similar to what we would get for
an include stack, e.g.,

In module 'DependsOnModule' imported from build-fail-notes.m:4:
In module 'Module' imported from DependsOnModule.framework/Headers/DependsOnModule.h:1:
Inputs/Module.framework/Headers/Module.h:15:12: note: previous definition is here
@interface Module

<rdar://problem/12696425>

llvm-svn: 169042
2012-11-30 21:58:49 +00:00
Douglas Gregor af8f02634b When an error occurs while building a module on demand, provide "While
building module 'Foo' imported from..." notes (the same we we provide
"In file included from..." notes) in the diagnostic, so that we know
how this module got included in the first place. This is part of
<rdar://problem/12696425>.

llvm-svn: 169021
2012-11-30 18:38:50 +00:00
Seth Cantrell 40f87b1d53 only truncate source lines in text diagnostics when
the ellipsis is shorter than the text it replaces

llvm-svn: 167364
2012-11-03 23:56:43 +00:00
Seth Cantrell 6292e5b8e5 don't step into the middle of multibyte sequences
llvm-svn: 167361
2012-11-03 21:21:17 +00:00
Seth Cantrell d38c708dc1 fix bug in SourceColumnMap::startOfPreviousColumn
llvm-svn: 167360
2012-11-03 21:21:14 +00:00
Eli Friedman 34ff0ea522 Add a proper algorithm to compute accurate source ranges for diagnostics with
caret locations and source ranges in macros.  Makes ranges more accurate
in some cases, and fixes an assertion failure.

Fixes <rdar://problem/12472249>.

llvm-svn: 167353
2012-11-03 03:36:51 +00:00
Seth Cantrell ee2effd264 remove duplicate data array
llvm-svn: 167007
2012-10-30 06:13:52 +00:00
Seth Cantrell 2939416871 fix calculation of end pointer
llvm-svn: 167006
2012-10-30 06:13:50 +00:00
Douglas Gregor 7959178eb0 Use a .def file for most of the diagnostic options.
llvm-svn: 166520
2012-10-23 23:11:23 +00:00
Douglas Gregor 811db4eac4 Make DiagnosticOptions intrusively reference-counted, and make sure
the various stakeholders bump up the reference count. In particular,
the diagnostics engine now keeps the DiagnosticOptions object alive.

llvm-svn: 166508
2012-10-23 22:26:28 +00:00
Benjamin Kramer fce09f139c Emit diagnostics in chunks even when we're trying to print colored template diffs.
char-by-char is really slow on an unbuffered stream.

llvm-svn: 166218
2012-10-18 20:09:54 +00:00
Sylvestre Ledru 33b5baf189 Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164766
llvm-svn: 164769
2012-09-27 10:16:10 +00:00
Sylvestre Ledru a876013dc9 Fix a typo 'iff' => 'if'
llvm-svn: 164766
2012-09-27 09:57:10 +00:00
Richard Smith fab4b1a40c Make TextDiagnostic more robust against SourceLocations which point into the
middle of UTF-8 characters, and avoid walking to such positions when adjusting
column ranges for display. Fixes a couple of hangs when rendering diagnostics.

llvm-svn: 163820
2012-09-13 18:37:50 +00:00
Joerg Sonnenberger 42cf26883e Add missing cctype includes.
llvm-svn: 161660
2012-08-10 10:58:18 +00:00
Benjamin Kramer 90653a1920 Remove unused variables.
llvm-svn: 161483
2012-08-08 09:26:28 +00:00
Sylvestre Ledru 830885ca64 Fix a typo (the the => the)
llvm-svn: 160622
2012-07-23 08:59:39 +00:00
Jordan Rose 9dd82c1d94 Re-apply r160319 "Don't crash when emitting fixits following Unicode chars"
This time, make sure we don't try to print fixits with newline characters,
since they don't have a valid column width, and they don't look good anyway.

PR13417 (and originally <rdar://problem/11877454>)

llvm-svn: 160561
2012-07-20 18:50:51 +00:00
Nico Weber cd8a546b6c Revert r160319, it caused PR13417. Add a test for PR13417.
llvm-svn: 160542
2012-07-20 06:44:52 +00:00
Jordan Rose fb12a53d5d Don't crash when emitting fixits following Unicode characters.
This code is very sensitive to the difference between "columns" as printed
and "bytes" (SourceManager columns). All variables are now named explicitly
and our assumptions are (hopefully) documented as both comment and assertion.

Whether parseable fixits should use byte offsets or Unicode character counts
is pending discussion on the mailing list; currently the implementation uses
bytes (and has no problems on lines containing multibyte characters).
This has been added to the user manual.

<rdar://problem/11877454>

llvm-svn: 160319
2012-07-16 20:52:12 +00:00
Benjamin Kramer 29f90e804d PR13312: Don't crash when printing a fixit that ends in a unicode character.
llvm-svn: 160112
2012-07-12 08:20:49 +00:00
Richard Trieu a71f0de454 When applying a template diff highlighting to a diagnostic message, remember
to reapply the bold formatting when needed.

llvm-svn: 159386
2012-06-28 22:39:03 +00:00
David Blaikie 9e55d74074 Fix template type diffing coloring (r159216) when forcing color output to a file (not a terminal)
Reviewed (over the shoulder) by Richard Trieu.

llvm-svn: 159381
2012-06-28 21:46:07 +00:00
Richard Trieu 9184423984 Add template type diffing to Clang. This feature will provide a better
comparison between two templated types when they both appear in a diagnostic.
Type elision will remove indentical template arguments, which can be disabled
with -fno-elide-type.  Cyan highlighting is applied to the differing types.

For more formatting, -fdiagnostic-show-template-tree will output the template
type as an indented text tree, with differences appearing inline. Template
tree works with or without type elision.

llvm-svn: 159216
2012-06-26 18:18:47 +00:00
James Dennett f347d93d12 Documentation cleanup: escape \ characters in Doxygen comments as needed.
llvm-svn: 158968
2012-06-22 05:33:23 +00:00
Jordan Rose b5a94f45d2 If fixits appear to overlap, move the second one over in the output.
This occurs when you have two insertions and the first one is so long that the
second fixit's column is before the first fixit ends. The edits themselves
don't actually overlap, but our command-line preview does.

llvm-svn: 158229
2012-06-08 21:14:19 +00:00
Seth Cantrell 14340ca173 ensure value passed to is space is representable as unsigned char
if the value isn't an unsigned char or EOF behavior is undefined
(and on Windows there's an assertion)

llvm-svn: 157445
2012-05-25 00:03:29 +00:00
Seth Cantrell ac6fb8f9f6 fix Bug 12924
http://llvm.org/bugs/show_bug.cgi?id=12924

This issue was that the source location was pointing to a
non-printable character and so CaretEnd was pointing one
_column_ past the caret but not one _character_ past the
caret. So the conversion between column and byte locations
wasn't working (because the conversion is only valid from
the first column or byte of a character).

llvm-svn: 157372
2012-05-24 05:14:44 +00:00
Argyrios Kyrtzidis b16ff5d1ce Fix an assertion hit when the serialized diagnostics writer receive a diagnostic
from the frontend when the location is invalid and the SourceManager null.

Instead of keeping the SourceManager object in DiagnosticRenderer, propagate it
to the calls accordingly (as reference when it is expected to not be null, or pointer
when it may be null).
This effectively makes DiagnosticRenderer not tied to a specific SourceManager,
removing a hack from TextDiagnosticPrinter.

rdar://11386874

llvm-svn: 156536
2012-05-10 05:03:45 +00:00
Benjamin Kramer 556ab5ee90 Make some helper functions static.
llvm-svn: 155914
2012-05-01 14:34:11 +00:00
Nico Weber 35131221e7 Revert r154981, because it caused PR12674.
Add a test for PR12674.

llvm-svn: 155666
2012-04-26 21:39:46 +00:00
Matt Beaumont-Gay 69e227b7b1 Suppress -Wunused-variable warning in -Asserts build
llvm-svn: 155011
2012-04-18 17:25:16 +00:00
Seth Cantrell 01d61b0ae4 fix display of source lines with null characters
llvm-svn: 154981
2012-04-18 02:44:48 +00:00
Seth Cantrell 99e2fa87f8 Nicer display of unprintable source, and fix caret display for non-ascii text
Unprintable source in diagnostics is transformed to a printable form and then
displayed with reversed colors if possible. Unprintable characters are
displayed as <U+NNNN> while bytes that do not represent valid characters are
shown as <XX>.

Column adjustments to diagnostic carets, highlighted ranges, and fixups are
made both for characters escaped as above and for characters which are
printable but take up more than a single column.

llvm-svn: 154980
2012-04-18 02:44:46 +00:00
Seth Cantrell 14dc87fccc Revert "Nicer display of unprintable source, and fix caret display for non-ascii text"
This reverts commit e9a3b76ba589a8a884e978273beaed0d97cf9861.

Revert "fix display of source lines with null characters"

This reverts commit 70712b276e40bbe11e5063dfc7e82ce3209929cd.

llvm-svn: 154950
2012-04-17 20:59:59 +00:00
Seth Cantrell f504f99c7d fix display of source lines with null characters
llvm-svn: 154947
2012-04-17 20:06:06 +00:00
Seth Cantrell fae205811e Nicer display of unprintable source, and fix caret display for non-ascii text
Unprintable source in diagnostics is transformed to a printable form and then
displayed with reversed colors if possible. Unprintable characters are
displayed as <U+NNNN> while bytes that do not represent valid characters are
shown as <XX>.

Column adjustments to diagnostic carets, highlighted ranges, and fixups are
made both for characters escaped as above and for characters which are
printable but take up more than a single column.

llvm-svn: 154946
2012-04-17 20:06:03 +00:00
Ted Kremenek 0964cca5d5 Refactor DiagnosticRenderer and SDiagsRenderer to have some functionality
pulled into DiagnosticNoteRenderer, and common DiagnosticRenderer that
assumes that all custom diagnostic messages are notes.  Also extend
DiagnosticRenderer to work with StoredDiagnostics in preparation for
subsequent changes.

llvm-svn: 150455
2012-02-14 02:46:00 +00:00
Dylan Noblesmith 2c1dd2716a Basic: import SmallString<> into clang namespace
(I was going to fix the TODO about DenseMap too, but
that would break self-host right now. See PR11922.)

llvm-svn: 149799
2012-02-05 02:13:05 +00:00
Ted Kremenek c4bbd8531e Refactor 'TextDiagnostic' to have a parent class 'DiagnosticRenderer' which handles
the policy of how diagnostics are lowered/rendered, while TextDiagnostic handles
the actual pretty-printing.

This is a first part of reworking SerializedDiagnosticPrinter to use the same
inclusion-stack/macro-expansion logic as TextDiagnostic.

llvm-svn: 146819
2011-12-17 05:26:04 +00:00