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
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
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
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
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
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
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
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
#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
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
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
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
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
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
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
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
the prerocessor will be available via ASTContext).
- Removed the public data member "PP" in ASTContext.
- Changed ASTContext's contructor to take TargetInfo/IdentifierTable explicitly.
- Implicitly create an ASTContext in Sema's constructor. This simplifies
the clients job (and makes ASTContext more private).
--As a side effect, added a "PrintStats" hook to Sema.
To support this level of encapsulation, ASTContext is always dynamically
allocated (by Sema). Previously, ASTContext was being allocated on the
stack. I don't believe this should be a performance issue (since ASTContext
is fairly course grain and tied to the lifetime of Sema currently).
llvm-svn: 39345
*** AST Context Stats:
30594 types total.
19 builtin types
3929 pointer types
308 array types
18883 function types with proto
8 function types with no proto
2988 typename (typedef) types
4459 tagged types
1476 struct types
80 union types
0 class types
2903 enum types
83298 slow type lookups
Next up, making type canonicalization not trivially silly.
llvm-svn: 39305
declarations through the asm streamer. For a testcase like:
int G;
int H, I, *J;
int func() {}
'clang -parse-print-ast' prints:
Read top-level decl: G
Read top-level decl: H
Read top-level decl: I
Read top-level decl: J
Read top-level decl: func
llvm-svn: 38992
right number of newlines between tokens when needed. This reduces the
delta of the gcc -E output from 12198 differences to 6764. It still needs
to emit filenames on #line directives, track filename switches, and track
entry/exit of include files.
llvm-svn: 38559
Now, instead of keeping a pointer to the start of the token in memory, we keep the
start of the token as a SourceLocation node. This means that each LexerToken knows
the full include stack it was created with, and means that the LexerToken isn't
reliant on a "CurLexer" member to be around (lexer tokens would previously go out of
scope when their lexers were deallocated).
This simplifies several things, and forces good cleanup elsewhere. Now the
Preprocessor is the one that knows how to dump tokens/macros and is the one that
knows how to get the spelling of a token (it has all the context).
llvm-svn: 38551