Commit Graph

129 Commits

Author SHA1 Message Date
Ted Kremenek fb5c46c740 Made driver flag --check-uninit-values more self-explanatory.
llvm-svn: 42062
2007-09-17 21:21:20 +00:00
Ted Kremenek 7e61e81bbf UninitialuzedValues now only tracks BlockVarDecls; obviating false positives with
globals and function parameters.

llvm-svn: 42055
2007-09-17 20:49:30 +00:00
Chris Lattner 7ea6ca70f5 switch the llvm emitter to ASTConsumer interface.
llvm-svn: 42013
2007-09-16 19:46:59 +00:00
Chris Lattner 254987c411 switch the various CFG-based stuff over to using ASTConsumer interface,
this eliminates their dependence on the preprocessor and eliminates some
duplicated code.

llvm-svn: 41993
2007-09-15 23:21:08 +00:00
Chris Lattner 09c39db0c4 convert ast printer and dumper ocver to ASTConsumer interface,
genericizing them and eliminating boilerplate code.

llvm-svn: 41992
2007-09-15 23:02:28 +00:00
Chris Lattner 75e0c8cf4c add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it.

llvm-svn: 41991
2007-09-15 22:56:56 +00:00
Ted Kremenek 6dc7b11d32 Added "Dead Stores", a flow-sensitive checker that checks for stores
to variables that are no longer live.  This analysis is built on top
of CFGs and the LiveVariables analysis.

changes to driver:
 added driver option "-check-dead-stores" to run the analysis

llvm-svn: 41754
2007-09-06 23:00:42 +00:00
Ted Kremenek 3f8ed2653c LiveVariables:
- Finished 99% of analysis logic.  Probably a few bugs.
 - Added querying functions to query liveness.
 - Added better pretty printing of liveness.
 - Added better bookkeeping of per-variable liveness information.
 - Added LiveVariablesAuditor interface, which allows "lazy" querying
   of intra-basic block liveness information.

Driver:
 - Minor cleanups involved in dumping liveness information.

llvm-svn: 41753
2007-09-06 21:26:58 +00:00
Ted Kremenek b56a990955 Added an early implementation of Live-Variables analysis built on
source-level CFGs.  This code may change significantly in the near
future as we explore different means to implement dataflow analyses.

Added a driver option, -dump-live-variables, to view the output of
live variable analysis.  This output is very ALPHA; it will be improved shortly.

llvm-svn: 41737
2007-09-06 00:17:54 +00:00
Ted Kremenek 4e5f99da6c Added GraphTraits to source-level CFGs (CFG and CFGBlock) to allow
(LLVM-provided) graph algorithms such as DFS and graph visualization
to work effortless on source-level CFGs.

Further cleanup on pretty printing of CFGs.  CFGBlock::dump and
CFGBlock::print now take the parent CFG as an argument.  This allows
CFGBlocks to print their own appropriate label indicating whether or
not they are the Entry/Exit/IndirectGotoBlock without the CFG::print
routine doing it instead.

Added Graphviz visualization for CFGs: CFG::viewCFG.  This employs the
GraphTraits just implemented.

Added "-view-cfg" mode the to clang driver.  This is identical to
"-dump-cfg" except that it calls Graphviz to visualize the CFGs
instead of dumping them to the terminal.

llvm-svn: 41580
2007-08-29 21:56:09 +00:00
Chris Lattner dd9a319158 Add isysroot support, patch by Keith Bauer
llvm-svn: 41455
2007-08-26 17:47:35 +00:00
Ted Kremenek 4aa1e8b3b8 Added CFG infrastructure (CFG.cpp and CFG.h) for clang ASTs.
Added builder code to translate ASTs to CFGs.  This currently supports
if, return, and non-control flow statements.

Added pretty-printer to debug CFGs.

Added a "-dump-cfg" option to the clang driver to dump CFGs for code
sent through the frontend.

llvm-svn: 41252
2007-08-21 21:42:03 +00:00
Chris Lattner cbe4f77c9e add a new AST dumper interface (E->dump()). This dumps out
the AST in a structural, non-pretty, form useful for understanding
the AST.  It isn't quite done yet, but is already somewhat useful.

For this example:

int test(short X, long long Y) {
  return X < ((100));
}

we get (with -parse-ast-dump):

int test(short X, long long Y)
(CompoundStmt 0x2905ce0
  (ReturnStmt 0x2905cd0
    (BinaryOperator 0x2905cb0 '<'
      (ImplicitCastExpr 0x2905ca0
        (DeclRefExpr 0x2905c20 Decl='X' 0x2905bb0))
      (ParenExpr 0x2905c80
        (ParenExpr 0x2905c60
          (IntegerLiteral 0x2905c40 100))))))

llvm-svn: 40954
2007-08-08 22:51:59 +00:00
Chris Lattner d956fcac86 GCC doesn't set __STDC_VERSION__ usually. It never sets it in
C++ mode, even gnu C++ mode.

llvm-svn: 40408
2007-07-22 22:11:35 +00:00
Chris Lattner 6b4db176ea when running in -E mode on multiple files, there is no reason to accumulate
fileid's and macroid's across files.  Clearing between files keeps the tables
smaller and slightly speeds up compilation.

llvm-svn: 40383
2007-07-22 06:05:44 +00:00
Chris Lattner 833894bcac Return an exit code of 1 if errors occur, not an exit code equal to the # errors :)
llvm-svn: 40189
2007-07-21 05:40:53 +00:00
Chris Lattner 146762e7a4 At one point there were going to be lexer and parser tokens.
Since that point is now long gone, we should rename LexerToken to
Token, as it is the only kind of token we have.

llvm-svn: 40105
2007-07-20 16:59:19 +00:00
Chris Lattner 539007a78a Add support for C++'0x keywords, patch by Doug Gregor
llvm-svn: 39897
2007-07-16 04:18:29 +00:00
Steve Naroff 4ae0ac6a06 Bug #:
Submitted by:
Reviewed by:
- Finished semantic analysis for vectors, added some diagnostics.
- Added AST for vectors (instantiation, installation into the decl).
- Fixed bug in ParseArraySubscriptExpr()...this crasher was introduced by me
when we added the range support.
- Turned pedantic off by default. Since vectors are gcc extensions, having
pedantic on by default was annoying. Turning it off by default is  also
consistent with gcc (but this wasn't my primary motivation).
- Tweaked some comments and diagnostics.

Note: The type checking code is still under construction (for vectors). This
will be my next check-in.

llvm-svn: 39715
2007-07-06 23:09:18 +00:00
Chris Lattner 23e6353835 Eliminate almost all of the redundancy Bill introduced.
llvm-svn: 39704
2007-06-28 04:54:17 +00:00
Chris Lattner af74985d71 Add a hack to fix a really subtle memory lifetime bug Bill introduced with his
recent changes.  carbon.h now preprocesses just fine.

llvm-svn: 39701
2007-06-28 04:10:04 +00:00
Chris Lattner a092b149bf rename LLVMDiagChecker.* -> DiagChecker.*
llvm-svn: 39690
2007-06-27 17:24:55 +00:00
Bill Wendling 52b0a4e84e Submitted by: Bill Wendling
Removed unnecessary typedef.

llvm-svn: 39686
2007-06-27 07:24:11 +00:00
Bill Wendling 469211a295 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Added a new diagnostic client, TextDiagnosticBuffer. It buffers all
  reported diagnostics.
- Use the new diagnostic client to check that expected diagnostics are
  actually emitted. The way this is done is to put the expected
  diagnostic in a comment on the line you expect it to be emitted for.
  Like this:

    int X = A; // expected-warning {{blah}}

- Use -parse-ast-check to use this feature.

llvm-svn: 39678
2007-06-27 03:19:45 +00:00
Bill Wendling aec64c35f1 Submitted by: Bill Wendling
- Separate out the AST streamers from the clang.cpp file into their very
  own special files.

llvm-svn: 39676
2007-06-23 00:39:57 +00:00
Bill Wendling 26e1f8c05a Bug #:
Submitted by: Bill Wendling

- Convert std::cerr to using fprintf(stderr, ...) instead.

llvm-svn: 39675
2007-06-22 22:43:15 +00:00
Chris Lattner 23b7eb677d Finally bite the bullet and make the major change: split the clang namespace
out of the llvm namespace.  This makes the clang namespace be a sibling of
llvm instead of being a child.

The good thing about this is that it makes many things unambiguous.  The
bad things is that many things in the llvm namespace (notably data structures
like smallvector) now require an llvm:: qualifier.  IMO, libsystem and libsupport
should be split out of llvm into their own namespace in the future, which will fix
this issue.

llvm-svn: 39659
2007-06-15 23:05:46 +00:00
Bill Wendling 52d85bdd2b Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Refactor some code from main() and ProcessInputFile() so that it helps to
  decouple the initialization of the Preprocessor object from the
  diagnostic client.

llvm-svn: 39657
2007-06-15 21:20:00 +00:00
Bill Wendling da0c8a9641 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Make the counting of errors and diagnostic messages sane. Place them into the
  Diagnostic class instead of in the DiagnosticClient class.

llvm-svn: 39615
2007-06-08 19:17:38 +00:00
Bill Wendling 37b1ddecf6 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Separated out the diagnostic client from the clang driver. This is in
  preparation for creating a diagnostic client that will be used to check
  error and warning messages.

llvm-svn: 39603
2007-06-07 09:34:54 +00:00
Bill Wendling 4447083418 Submitted by: Bill Wendling
- Conjugate "diagnostic" correctly for 1 diagnostic.

llvm-svn: 39525
2007-05-30 02:38:09 +00:00
Chris Lattner e64a1b5275 Fix two bugs that fell out from a testcase steve noticed. for this testcase:
extern int pintFunc(int *, int *);

int test() {
  pintFunc(0,
           3);
}

We now print:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~  ^

instead of:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~

llvm-svn: 39516
2007-05-29 05:53:15 +00:00
Chris Lattner f97fe38cb5 Initial scaffolding for an -emit-llvm mode. This requires the LLVM VMCore
library to be built for the driver to link.

llvm-svn: 39495
2007-05-24 06:29:05 +00:00
Steve Naroff f84d11f9d7 Bug #:
Submitted by:
Reviewed by:
Added "global" statistics gathering for Decls/Stmts/Exprs.
Very useful for working with a single file. When we start compiling
multiple files, will need to enhance this to collect stats on a per-module
basis.

llvm-svn: 39485
2007-05-23 21:48:04 +00:00
Chris Lattner a8a2c82f55 Move ASTStreamer.h into "clang/Sema/ASTStreamer.h"
llvm-svn: 39478
2007-05-21 17:38:36 +00:00
Chris Lattner 5ab15f154d Steve pointed out that testcases like this (with a macro expansion):
#define friendlystruct fs

  struct A { int X; };

  void test2(struct A friendlystruct, int C) {
    return friendlystruct + (C     *40);
  }

were getting diagnosed like this:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~             ^ ~~~~~~~~~~~

The problem is that getCharacterData returns a pointer to the macro expansion,
not to the macro instantiation.  Instead, use getLogicalLoc to get a pointer
to the instatiation location, so we relex the macro id.  We now get:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

oooh ahh. :)

llvm-svn: 39465
2007-05-20 18:08:36 +00:00
Chris Lattner beeb9bc51d improve const correctness
llvm-svn: 39460
2007-05-19 08:07:42 +00:00
Chris Lattner ebd1b33477 Use the new source ranges tracking feature to highlight the important pieces
of a subexpression when emitting a diagnostic.  Consider this example:

struct A { int X; };

void test1(void *P, int C) {
  return ((C*40) + *P) / 42+P;
}

void test2(struct A friendlystruct, int C) {
  return (C     *40) + friendlystruct;
}

void test3(struct A friendlystruct, int C) {
  return friendlystruct + test2(friendlystruct
                               , C);
}


clang now produces this output:

t.c:4:18: error: invalid operands to binary expression ('int' and 'void')
  return ((C*40) + *P) / 42+P;
          ~~~~~~ ^ ~~

This shows the important pieces of a nested (and potentially very complex)
expression.


t.c:8:18: error: invalid operands to binary expression ('int' and 'struct A')
  return (C     *40) + friendlystruct;
         ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

This shows that tabs in source files (after the 'C') and multichar tokens
(friendlystruct) are handled correctly.



t.c:12:25: error: invalid operands to binary expression ('struct A' and 'void')
  return friendlystruct + test2(friendlystruct
         ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~

This shows how multiline ranges are printed.  Any part of the range that is
not on the same line as the carat is just ignored.  This also shows that
trailing spaces on the line aren't highlighted.

llvm-svn: 39459
2007-05-19 08:06:14 +00:00
Chris Lattner f8d3197831 Change the structure of the code that emits the ^ marker in a diagnostic,
but there is no functionality change yet.

llvm-svn: 39458
2007-05-19 07:25:55 +00:00
Steve Naroff 71ce2e061d Bug #:
Submitted by:
Reviewed by:
An important, but truly mind numbing change.

Added 6 flavors of Sema::Diag() that take 1 or two SourceRanges. Considered
adding 3 flavors (using default args), however this wasn't as clear.

Removed 2 flavors of Sema::Diag() that took LexerToken's (they weren't used).

Changed all the typechecking routines to pass the appropriate range(s).

Hacked the diagnostic machinery and driver to acccommodate the new data.

What's left? A FIXME in clang.c to use the ranges. Chris offered to do the
honors:-) Which includes taking us to the end of an identifier:-)

llvm-svn: 39456
2007-05-18 22:53:50 +00:00
Chris Lattner 3dc3d775fb Rename type::getAsString to getAsStringInternal. Add a new
QualType::getAsString() that returns a string, which is much easier
for clients to use.  Convert clients to use it.

llvm-svn: 39449
2007-05-16 18:07:12 +00:00
Chris Lattner 36982e4367 Add support for inserting up to 10 strings in a diagnostic, with %0, %1, %2,
etc.

llvm-svn: 39447
2007-05-16 17:49:37 +00:00
Steve Naroff 17f76e04d2 Bug #:
Submitted by:
Reviewed by:
Work on finishing up typechecking for simple assignments (=) and function
calls. Here is an overview:
- implemented type checking for function calls (in Sema::ParseCallExpr).
- refactored UsualAssignmentConversions to return the result of the conversion.
This enum will allow all clients to emit different diagnostics based on context.
- fixed bug in Expr::isLvalue()...it wasn't handling arrays properly. Also
changed the name to isModifiableLvalue, which is consistent with the function on QualType.
- Added 6 diagnostics (3 errors, 3 extensions).

llvm-svn: 39432
2007-05-03 21:03:48 +00:00
Chris Lattner 739e739b81 Remove the clang::SourceBuffer class, switch to the llvm::MemoryBuffer class.
llvm-svn: 39426
2007-04-29 07:12:06 +00:00
Chris Lattner ae7fdad1c5 Teach the driver to filter out warnings and notes that come from system headers.
Switch -pedantic back on by default.

llvm-svn: 39423
2007-04-28 07:23:46 +00:00
Steve Naroff 0af9120905 Bug #:
Submitted by:
Reviewed by:
- Disabled -pedantic for now (until it ignores system headers).
- Removed convertSignedWithGreaterRankThanUnsigned() and convertFloatingRankToComplexType().
The logic is now inlined in maxIntegerType and maxComplexType().
- Removed getIntegerRank/getFloatingRank from the private interface. These
are now really private helpers:-)
- Declare maxIntegerType/maxFloatingType static. maxComplexType const.
- Added an enum for the floating ranks.
- Several fixed to getIntegerRank: add Bool, Char, and a clause for enums.

llvm-svn: 39421
2007-04-27 21:51:21 +00:00
Steve Naroff e471889d53 Bug #:
Submitted by:
Reviewed by:
More typechecking, refactoring...
- Implemented the following routines...CheckAdditiveOperands,
CheckCommaOperands, CheckLogicalOperands.
- Added maxComplexType, maxFloatingType, & maxIntegerType to ASTContext.
Ranking helper functions moved to ASTContext as well (they are private:-)
- Simplified UsualArithmeticConversions using the new ASTContext hooks.
- Fixed isAssignmentOp()...is was preventing comma exprs from ever being created:-(
- Changed a GCC compat extension to truly be an extension (and turned extensions
on by default). This now produces a warning by default.

llvm-svn: 39418
2007-04-27 18:30:00 +00:00
Chris Lattner bb73acd560 Support both tiger and leopard. Yes, this code is a hack :)
llvm-svn: 39359
2007-03-19 19:06:33 +00:00
Steve Naroff 3273c22863 Bug #:
Submitted by:
Reviewed by:
This is a "small" checkin.  #include_next wasn't working properly on
Leopard. This is because the driver has some hard coded paths that
don't work on Leopard. The real fix is to derive them, however I don't
think we need to solve this now. At this point, anyone working on clang
should be able to use Leopard. This fix removed 11 errors processing
"carbon.h". The bug that bubbles up to the top is in MergeFunctionDecl().
As part of digging into this part of Sema, I rearranged some methods
(and changed the visibility).

llvm-svn: 39356
2007-03-14 21:52:03 +00:00
Steve Naroff 2c055d2b2b Go back to having the clang driver create ASTContext explicitly, passing
it to Sema/ASTStreamer (separating the lifetime of ASTContext from
the lifetime of Sema). One day it might be useful to consider creating
a context object implicitly if one isn't provided (using default arguments in
Sema's constructor). At this point, adding this convenience isn't necessary.

llvm-svn: 39346
2007-02-28 19:32:13 +00:00