Commit Graph

76 Commits

Author SHA1 Message Date
Daniel Dunbar b2da933989 Sketch Driver Option classes.
llvm-svn: 65933
2009-03-03 05:55:11 +00:00
Daniel Dunbar 544ecd14b6 Stub out some structure for C++ driver.
llvm-svn: 65867
2009-03-02 19:59:07 +00:00
Daniel Dunbar 51adf5824e Rename lib/Driver (etc) to lib/Frontend in prep for the *actual*
driver taking lib/Driver.

llvm-svn: 65811
2009-03-02 06:16:29 +00:00
Douglas Gregor 87f95b0a6a Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:

  - Insert some new code (a text string) at a particular source
    location
  - Remove the code within a given range
  - Replace the code within a given range with some new code (a text
    string)

Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:

  template<int I> class B { };
  B<1000 >> 2> *b1;

we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:

test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
  B<1000 >> 2> *b1;
         ^
    (        )


Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.

In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.

This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).

llvm-svn: 65570
2009-02-26 21:00:50 +00:00
Chris Lattner d92f1bfa11 add c++ search path for GCC 4.2, PR3668, patch by Pawel Worach!
llvm-svn: 65462
2009-02-25 18:06:37 +00:00
Chris Lattner 464ceb4ec8 map source ranges through macro expansions. Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

(no ranges on the second diagnostics)

After:

t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                         ~~~ ^ ~~~

(ranges!)

llvm-svn: 65090
2009-02-20 00:25:28 +00:00
Chris Lattner 1973d84625 refactor, pass ranges down instead of the whole
DiagnosticInfo.

llvm-svn: 65088
2009-02-20 00:18:51 +00:00
Chris Lattner 06ef388a61 fix a bug introduced in my previous patch: moving clang headers to the
"after" group instead of the system group makes it so #include <limits.h>
picks up the *system* limits.h file before clang's.  This causes a failure
on linux and is definitely not what we want.

llvm-svn: 65026
2009-02-19 06:48:28 +00:00
Chris Lattner 45d26bd00d PR3614: "ignoring nonexistent directory" should print the -isysroot
mapped path, not the requested path.

llvm-svn: 65009
2009-02-19 04:48:57 +00:00
Ted Kremenek ea3a9e270c HTMLDiagnostics: Always display diagnostics *below* the line in question.
llvm-svn: 64959
2009-02-18 22:10:00 +00:00
Chris Lattner 24eb28bcf8 tidy up
llvm-svn: 64934
2009-02-18 18:50:45 +00:00
Chris Lattner 970f245439 stop searching GCC install directories for standard C headers (but
keep searching for C++ headers when in C++ mode).  In theory clang
should be able to find all of its own headers now.  If not, the
CPATH or C_INCLUDE_PATH environment variables can be specified to
add a include path.

llvm-svn: 64862
2009-02-18 00:25:15 +00:00
Ben Laurie 54a06ce437 Handle fatal errors.
llvm-svn: 64770
2009-02-17 17:32:22 +00:00
Chris Lattner 7b60a164b1 As an experimental hack, emit "instantiated from" information in
diagnostics.  I'm not sure I want to keep this, but hey, it's easy
and could be useful or something, even if guarded by a 
-fshow-me-tons-of-details option.  A silly example is:

#define A B
#define C A
#define D C

int y = D;

We now emit:

t.c:11:9: error: use of undeclared identifier 'B'
int y = D;
        ^
t.c:9:11: note: instantiated from:
#define D C
          ^
t.c:8:11: note: instantiated from:
#define C A
          ^
t.c:7:11: note: instantiated from:
#define A B
          ^

A more useful example is from tgmath:

t.c:4:9: error: no matching function for call to '__tg_acos'
 return acos(x);
        ^~~~~~~
/Users/sabre/llvm/Debug/Headers/tgmath-sofar.h:51:17: note: instantiated from:
#define acos(x) __tg_acos(x)
                ^
... candidate set follows ...

This does not yet print ranges in instantiation info, (e.g. highlighting the
range "__tg_acos(x)" in the last example), but that could be added if we 
decide this is a good idea :).

Thoughts and bug reports welcome!

llvm-svn: 64761
2009-02-17 08:44:50 +00:00
Chris Lattner 5abfe97bf1 sink a call to getInstantiationLoc to eliminate an assertion.
llvm-svn: 64755
2009-02-17 07:54:55 +00:00
Chris Lattner d22603cef0 break down EmitCaretDiagnostic to use more primitive calls.
llvm-svn: 64754
2009-02-17 07:51:53 +00:00
Chris Lattner 2cf68c1e96 split caret diagnostic printing out into its own function.
llvm-svn: 64751
2009-02-17 07:38:37 +00:00
Chris Lattner 11a2a433b2 simplify some code.
llvm-svn: 64750
2009-02-17 07:34:34 +00:00
Chris Lattner b42700f555 If a source range comes through a function-like macro expansion,
highlight the arguments to the macro as well as the identifier.

Before:

t.c:3:9: error: no matching function for call to '__tg_acos'; candidates are:
 return acos(x);
        ^~~~

after:

t.c:3:9: error: no matching function for call to '__tg_acos'; candidates are:
 return acos(x);
        ^~~~~~~

llvm-svn: 64743
2009-02-17 05:19:10 +00:00
Chris Lattner 24c911e25a use some references to simplify code.
llvm-svn: 64063
2009-02-08 01:00:10 +00:00
Chris Lattner bf20a9a57d Genericize the existing logic for removing duplicate header dirs to apply
the "system dirs win over user dirs" logic to framework and headermap
search locations as well as normal directories.  This means that
clang t.m -F/System/Library/Frameworks  will treat /System/Library/Frameworks
as a system directory not a user directory.  If you use -v, the difference is:

Before:
ignoring nonexistent directory "/usr/libdata/gcc41"
ignoring duplicate framework "/System/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:

After:
ignoring nonexistent directory "/usr/libdata/gcc41"
ignoring duplicate directory "/System/Library/Frameworks"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:

This fixes rdar://6566429.

llvm-svn: 64060
2009-02-08 00:55:22 +00:00
Chris Lattner b05f49e7fd handle fatal errors, rely on warnings to point out missing cases.
llvm-svn: 63913
2009-02-06 03:57:44 +00:00
Torok Edwin c6853c1531 Add Debian gcc 4.3 header search directories.
llvm-svn: 63872
2009-02-05 18:12:45 +00:00
Chris Lattner 88ea93e6b4 lower the interface to getLineNumber like we did for
getColumnNumber.  This fixes a FIXME in 
SourceManager::getPresumedLoc because we now just decompose
the sloc once.

llvm-svn: 63701
2009-02-04 01:06:56 +00:00
Chris Lattner e4ad417664 make SM::getColumnNumber take a predecomposed FileID/offset, which
makes it clear to clients that they have to pick an instantiation
or spelling location before calling it and allows optimization based
on that.

llvm-svn: 63698
2009-02-04 00:55:58 +00:00
Ted Kremenek e9aee88eed Clean up indentation.
llvm-svn: 63551
2009-02-02 21:45:32 +00:00
Chris Lattner 1958677ccf " Attached is a patch for TextDiagnosticPrinter that adds an optional
parameter that allows users to omit the printing of the source
location on a diagnostic. So basically it would omit the "abc.c:5:1: "
at the beginning of the line."

Patch by Alexei Svitkine!

llvm-svn: 63396
2009-01-30 17:41:53 +00:00
Ted Kremenek 5241832d1d Fix TextDiagnosticPrinter::HandleDiagnostic to handle invalid FullSourceLocs that do not have a SourceManager.
llvm-svn: 63230
2009-01-28 20:47:47 +00:00
Chris Lattner f1ca7d3e02 Introduce a new PresumedLoc class to represent the concept of a location
as reported to the user and as manipulated by #line.  This is what __FILE__,
__INCLUDE_LEVEL__, diagnostics and other things should follow (but not 
dependency generation!).  

This patch also includes several cleanups along the way: 

- SourceLocation now has a dump method, and several other places 
  that did similar things now use it.
- I cleaned up some code in AnalysisConsumer, but it should probably be
  simplified further now that NamedDecl is better.
- TextDiagnosticPrinter is now simplified and cleaned up a bit.

This patch is a prerequisite for #line, but does not actually provide 
any #line functionality.

llvm-svn: 63098
2009-01-27 07:57:44 +00:00
Ted Kremenek a3f462e49a PathDiagnostics:
- Add the distinction between the 'bug type' and the 'bug description'

HTMLDiagnostics:
- Output the bug type field as HTML comments

scan-build:
- Use the bug type field instead of the bug description for the HTML table.
- Radar filing now automatically picks up the bug description in the title (addresses <rdar://problem/6265970>)

llvm-svn: 63084
2009-01-27 01:53:39 +00:00
Ted Kremenek 099243aa9e When using -analyzer-output-plist always output a plist file even if it contains no error reports.
llvm-svn: 62871
2009-01-23 20:06:20 +00:00
Ted Kremenek 13747167ca Static Analyzer: When generating plists for errors reports, generate one plist file per translation unit that contains all of the diagnostics.
llvm-svn: 62647
2009-01-21 00:42:24 +00:00
Chris Lattner cbc35ecb04 Rename SourceManager::getCanonicalFileID -> getFileID. There is
no longer such thing as a non-canonical FileID.

llvm-svn: 62499
2009-01-19 07:46:45 +00:00
Chris Lattner 71dc14b9f0 Rename SourceLocation::getFileID to getChunkID, because it returns
the chunk ID not the file ID.  This exposes problems in 
TextDiagnosticPrinter where it should have been using the canonical
file ID but wasn't.  Fix these along the way.

llvm-svn: 62427
2009-01-17 08:45:21 +00:00
Chris Lattner d32480d3db this massive patch introduces a simple new abstraction: it makes
"FileID" a concept that is now enforced by the compiler's type checker
instead of yet-another-random-unsigned floating around.

This is an important distinction from the "FileID" currently tracked by
SourceLocation.  *That* FileID may refer to the start of a file or to a
chunk within it.  The new FileID *only* refers to the file (and its 
#include stack and eventually #line data), it cannot refer to a chunk.

FileID is a completely opaque datatype to all clients, only SourceManager
is allowed to poke and prod it.

llvm-svn: 62407
2009-01-17 06:22:33 +00:00
Chris Lattner 48a8c57936 eliminate FullSourceLoc::getLocation() now that FullSourceLoc
*is* the location.  This eliminates some weird X.getLocation().getLocation()'s.

llvm-svn: 62376
2009-01-16 23:06:35 +00:00
Chris Lattner fcc0a5a3f7 elimiante FullSourceLoc::getCanonicalFileID
llvm-svn: 62374
2009-01-16 22:59:51 +00:00
Chris Lattner 671689a440 an instantiation loc is always a file loc.
llvm-svn: 62370
2009-01-16 22:53:27 +00:00
Chris Lattner 8a42586c54 more SourceLocation lexicon change: instead of referring to the
"logical" location, refer to the "instantiation" location.

llvm-svn: 62316
2009-01-16 07:36:28 +00:00
Zhongxing Xu 4c1661102e Add Fedora 10 GCC paths.
llvm-svn: 61429
2008-12-25 09:28:01 +00:00
Nuno Lopes cbab7f6b29 add missing gentoo c++ include paths
llvm-svn: 60655
2008-12-07 12:11:37 +00:00
Eli Friedman 79ceb0947b Minor update to CMake build system.
llvm-svn: 60269
2008-11-30 01:46:21 +00:00
Zhongxing Xu 2d311e8354 Add license comments.
llvm-svn: 60144
2008-11-27 02:19:10 +00:00
Zhongxing Xu 16e3f0e03f Add support for pluggable components of static analyzer.
- Creator function pointers are saved in ManagerRegistry.
 - The Register* class is used to notify ManagerRegistry new module is 
   available.
 - AnalysisManager queries ManagerRegistry for configurable module. Then it
   passes them to GRExprEngine, in turn to GRStateManager.

llvm-svn: 60143
2008-11-27 01:55:08 +00:00
Chris Lattner bd414e34c2 remove a dead enum
llvm-svn: 59879
2008-11-22 20:47:38 +00:00
Chris Lattner 327984f4c4 switch TextDiagnosticPrinter to raw_ostream.
llvm-svn: 59597
2008-11-19 06:56:25 +00:00
Chris Lattner 23be067407 rewrite FormatDiagnostic to be less gross and a lot more efficient.
This also makes it illegal to have bare '%'s in diagnostics.  If you
want a % in a diagnostic, use %%.

llvm-svn: 59596
2008-11-19 06:51:40 +00:00
Chris Lattner 8488c8297c This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed.  In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a 
ton of random stuff.  This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.

In addition to introducing DiagnosticInfo, this also substantially changes how 
Diagnostic::Report works.  Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and 
ID) and returns a fresh DiagnosticInfo *by value*.  The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator.  When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information.  This is a somewhat tricky dance, but it means that the 
accumulated DiagnosticInfo is allowed to keep pointers to other expression 
temporaries without those pointers getting invalidated.

This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema.  For example, instead of calling:

  Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
       SourceRange(BuiltinLoc, RParenLoc));

We will soon be able to just do:

  Diag(BuiltinLoc, diag::err_overload_no_match)
      << typeNames << SourceRange(BuiltinLoc, RParenLoc));

This scales better to support arbitrary types being passed in (not just 
strings) in a type-safe way.  Go operator overloading?!

llvm-svn: 59502
2008-11-18 07:04:44 +00:00
Chris Lattner 16ba91396a Change the diagnostics interface to take an array of pointers to
strings instead of array of strings.  This reduces string copying
in some not-very-important cases, but paves the way for future 
improvements.

llvm-svn: 59494
2008-11-18 04:56:44 +00:00
Daniel Dunbar f3502dbc14 [LLVM up] Update for raw_fd_ostream change. This fixes a FIXME that
the Backend output should be done in binary mode.
 - I'd appreciate it if someone who has a Windows build could verify
   this.

llvm-svn: 59221
2008-11-13 05:09:21 +00:00