- Add Sema::CurMethodDecl, in preparation for adding ObjcIvarRefExpr.
- Add ObjcInterfaceDecl::lookupInstanceVariable(), in prep for adding ivars.
- A couple renames in ObjcInterfaceDecl, while I was in the vicinity:-)
llvm-svn: 44015
While the diff is large, the idea is very simple. When we parse method definitions (in an @implementation), we need to add them incrementally (rather than wait until the @end).
Other details...
- Renamed Sema::ActOnAddMethodsToObjcDecl() to Sema::ActOnAtEnd(). The methods are now optional arguments.
- Removed Parser::AllImplMethods (a nice cleanup).
- Added location info to ObjcImplementationDecl (since we will need it very soon:-)
- Modified message.m test to no longer allow the bogus diagnostic.
llvm-svn: 43995
(1) serialize out top-level decls BEFORE serializing out translation unit
structures like ASTContext.
(2) deserialize out translation unit structures like ASTContext before
top-level decls by first skipping the decls in the bitstream, deserializing
ASTContext and friends, and then jumping back to the bitstream block with the
decls and then deserializing them.
Change (1) allows us to utilize the pointer-tracking system in the Serializer
to only serialize out metadata that is actually referenced by the ASTS.
Change (2) allows us to deserialize the metadata first as before, which
signficantly reduces the amount of pointer backpatching the deserializer
would have to do if the decls were deserialized first.
llvm-svn: 43974
Disable rewrite-tabs. This speeds up processing of the commentified huge
crazy testcase steve gave me from 20s to 6.6s in a release build.
llvm-svn: 43880
2) Fixed a regression in meta-data generation caused by removal of '_interface' prefix from synthesize class name.
3) Added stubs for @try/@catch/@finally statements.
llvm-svn: 43716
- Synthesize the funky cast for objc_msgSend(). For the basic case, it looks like...
((id (*)(id, SEL))(void *)objc_msgSend)(obj, sel);
The "void *" cast is needed to workaround a GCC "bandaid" (Chris says it has something to do with the inliner). Without the extra "void *" cast, we get spurious warnings/notes that look like...
xx.m:17: warning: function called through a non-compatible type
xx.m:17: note: if this code is reached, the program will abort
- Add prototypes for the ObjC functions we call, objc_msgSend/objc_getClass for now (don't depend on them being included).
llvm-svn: 43685
Make target info available to clang code generator. This is far from complete but this helps clang codegen module make progress.
At the moment target triplet and target description strings are hard coded in clang::TargetInfo
llvm-svn: 43572
I need to (finally) change the way Class/id/SEL/IMP are built-in...the current approach of doing it in the preprocessor is "broken". The other problem is Sema::GetObjcIdType/GetObjcSelType/GetObjcClassType, the hooks that initialize ASTContext lazily. These built-in types need to be done up front...
llvm-svn: 43557
Still to do:
- Chris will fix a bug in the rewriting engine for nested stmts. For example, the following:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
tranlates to:
NSAutoreleasePool * pool = objc_msgSend(objc_msgSend(objc_getClass("NSAutoreleasePool"), sel_getUid("alloc")), sel_getUid("init"))utoreleasePool"), sel_getUid("alloc")) init];
...which is correct, except there is garbage after sel_getUid("init"). This is because the rewriter isn't updating the extent of the containing message expression.
- Do the crazy cast thang.
llvm-svn: 43316
protocol meta-data (unlike what documentation says). 2) Include objc.h so,
we can compile the generated metadata with both gcc and clang.
llvm-svn: 43311
new split-header file configuration (Serialize.h and Deserialize.h)
now in place in the core LLVM repository.
Removed unneeded SerializeTrait specializations for enums in
TokenKinds.h
llvm-svn: 43306
we currently turn:
c = @encode(char *)[2] + 4;
into:
c = "foo"[2] + 4;
Right now the foo string is hard coded, but you can imagine a world
where it wouldn't be :)
llvm-svn: 43093
Silenced some VC++ warnings.
Had to rephrase a partial specialization of the IntrospectionTrait struct in SerializationTest.cpp, please review.
Added a compiler specific workaround in IdentifierTable.h. Is that the way to fix this kind of issues?
llvm-svn: 43074
serialization logic as well as driver code is now in
Driver/SerializationTest.cpp. The status of this code is that it
should be used by no clients.
Added --test-pickling option to driver to run the serialization code.
Modified IdentifierInfo and IdentifierTable to have friend classes
that permit object serialization. Such friendship may not be needed
in the final design.
llvm-svn: 43052
Rename SourceRange::Begin()/End() to getBegin()/getEnd() for
consistency with other code.
Start building the rewriter towards handling @encode.
llvm-svn: 43047
predefined macros. Previously, these were handled by the driver,
now they are handled by the preprocessor.
Some fallout of this:
1. Instead of preprocessing two buffers (the predefines, then the
main source file) we now start preprocessing the main source
file and inject the predefines as a "psuedo #include" from the
main source file.
2. #1 allows us to nuke the Lexer::IsMainFile flag and simplify
Preprocessor::isInPrimaryFile.
3. The driver doesn't have to know about standard #defines, the
preprocessor knows, which is nice for people wanting to define
their own drivers.
4. This allows us to put normal tokens in the predefine buffer,
for example a definition for __builtin_va_list that is
target-specific, and a typedef for id in objc.
llvm-svn: 42818
using "-parse-ast -verify".
Updated all test cases (using a sed script) that invoked -parse-ast-check to
now use -parse-ast -verify.
Fixed a bug where using "-verify" instead of "-parse-ast-check" would not
correctly create the DiagClient needed to accumulate diagnostics.
llvm-svn: 42365
ASTConsumer can also be verified using the diagnostics checker. From
the command line, users may activate diagnostic checking using the
"-verify" option. For example, "clang -verify -warn-dead-stores"
checks if the warnings flagged by the dead store checker match those
in the comments.
Note that we still have the option "-parse-ast-check" for backwards
comptability with existing test cases. This option is now equivalent to
"-parse-ast -verify".
llvm-svn: 42362
"CheckDiagnostics" (used for -parse-ast-check) to check the
diagnostics of any ASTConsumer.
Reimplemented CheckDiagnostics to use CheckASTConsumer instead.
Added driver option -warn-dead-stores-check, which checks the
diagnostics generated by the DeadStores checker. This is implemented
using CheckASTConsumer.111
llvm-svn: 42310
between forward and backward analyses, with trait classes being used
to implement the key differences in operations/functionality.
Converted the LiveVariables analysis to use the generic DataflowSolver. This,
along with removing some extra functionality that was not needed, reduced
the code for LiveVariables by over half.
Modified Driver code to handle the updated interface to LiveVariables.
Modified the DeadStores checker to handle the update interface to
LiveVariables.
Updated DataflowValues (generic ADT to store dataflow values) to also
store values for blocks. This is used by DeadStores. Updated some comments.
llvm-svn: 42293
"The ExpectedStr search was starting at the end of the comment string.
This patch starts the search at the beginning of the comment string.
After applying this patch, clang -parse-ast-check on negative test
case source files worked as expected."
llvm-svn: 42012
The previous naming scheme was confusing, since it resulted in both the Parser and Action modules having methods with the same name. In addition, the Action module never does any parsing...
llvm-svn: 41986
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.
Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.
llvm-svn: 41934
void func() {
int xx = xx; // incorrectly diagnosed 'xx' as an undeclared identifier.
}
This smallish bug resulted in a largish fix. Here are some highlights:
- Needed to make sure ParseDeclarator is called *before* parsing any
initializer. Removed the "Init" argument to ParseDeclarator.
- Added AddInitializerToDecl() to the Action & Sema classes.
In Sema, this hook is responsible for validating the initializer and
installing it into the respective decl.
- Moved several semantic checks from ParseDeclarator() to
FinalizeDeclaratorGroup(). Previously, this hook was only responsible for
reversing a list. Now it plays a much larger semantic role.
All of the above changes ended up simplifying ParseDeclarator(), which
is goodness...
llvm-svn: 41877
that refer to direct function calls.
Modified interface of LiveVariables to only track liveness of VarDecls.
This cleans up a bunch of edge cases, and removed the bug just mentioned.
llvm-svn: 41797
"CFGVisitor", which now handles all the boilerplate for iterating over
the function definitions in a translation unit and building the CFGs.
This logic was previously replicated for each driver option that used
CFGs.
The options -dump-cfg, -view-cfg, -check-dead-stores, and
-dump-live-variables now use this refactored code.
llvm-svn: 41779
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
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
(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
Added explicit "Exit" CFGBlock pointer to the source-level CFG.
Changed the construction of blocks with "return" statements to have the
return statement appear both as a statement in the list of statements for
a CFGBlock as well as appear as a control-flow terminator. Also removed
the implicit linearization of "return" so that the return value and the
return statement did not appear as separate statements in the block.
llvm-svn: 41323
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
preprocessor state, causing bogus diagnostics when the file is parsed for real. This
implements Misc/diag-checker.c. Thanks to Ted for noticing this.
llvm-svn: 41000
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
fileid/offset pair, it now contains a bit discriminating between
mapped locations and file locations. This separates the tables for
macros and files in SourceManager, and allows better separation of
concepts in the rest of the compiler. This allows us to have *many*
macro instantiations before running out of 'addressing space'.
This is also more efficient, because testing whether something is a
macro expansion is now a bit test instead of a table lookup (which
also used to require having a srcmgr around, now it doesn't).
This is fully functional, but there are several refinements and
optimizations left.
llvm-svn: 40103
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
- Chris noticed that if there were multiple warnings/errors expected
throughout the file and we were checking only one of them, then it
would go ahead and say that the whole file was okay. Fixed this by
adding a check for the line number as well as the string.
llvm-svn: 39689
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
- Created a base class (TextDiagnostics) for all text diagnostic classes.
Moved the "IgnoreDiagnostic" method up there, and created a method that
will format the diagnostic string, replacing %# with the appropriate
string. This is in preparation for adding a text diagnostic checker.
llvm-svn: 39650
Reviewed by: Chris Lattner
- Added a method "IgnoreDiagnostic" so that the diagnostic client can
tell the diagnostic object that it doesn't want to handle a particular
diagnostic message. In which case, it won't be counted as either a
diagnostic or error.
llvm-svn: 39641
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:
carbon.h looking good! Only 1 warning left...no parse errors!
This fixes 3 bugs...
- A couple tricky bugs with type canonicalization. Nested typedef's weren't being
handled properly. For example, the following didn't work:
typdef int __darwin_pid_t;
typedef __darwin_pid_t pid_t;
int getpgid(pid_t);
int getpgid(int);
- The storage class wasn't being preserved. As a result, Sema was complaining
about the following:
extern char *foo;
char *foo;
- various built-ins weren't registered...resulting in spurious warnings.
llvm-svn: 39357
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
of source code. For example:
$ clang INPUTS/carbon_h.c -arch i386 -arch ppc
prints:
...
/usr/lib/gcc/i686-apple-darwin8/4.0.1/include/mmintrin.h:51:3: note: use of a target-specific builtin function, source is not 'portable'
__builtin_ia32_emms ();
^
because carbon.h pulls in xmmintrin.h, and __builtin_ia32_emms isn't a builtin on ppc.
Though clang now supports target-specific builtins, the full table isn't implemented yet.
llvm-svn: 39328
*** 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
of having a loose collection of function pointers. This also allows clients to
maintain state, and reduces the size of the Preprocessor.h interface.
llvm-svn: 39203
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