Chris Lattner
247ef955bc
in the truncation case, make sure to propagate the sign correctly, this
...
fixes an assertion on:
void f (int z) { switch (z) { case ~0ULL: case -1: return; } }
testcase from Neil.
llvm-svn: 41343
2007-08-23 22:08:35 +00:00
Steve Naroff
8ddb23a6c5
Support '~' for complex conjugation. This is a GCC extension.
...
This following now compiles without error...
_Complex unsigned X, Y;
_Complex double x, y;
void test2(int c) {
X = ~Y;
x = ~y;
}
llvm-svn: 41341
2007-08-23 22:06:40 +00:00
Chris Lattner
7b939cf606
fix a bug where we would type 0ULL as unsigned instead of unsigned long long
...
llvm-svn: 41340
2007-08-23 21:58:08 +00:00
Chris Lattner
e5b60445e7
Pretty print as:
...
"case sizeof x:"
instead of:
"case sizeofx:"
llvm-svn: 41339
2007-08-23 21:46:40 +00:00
Chris Lattner
9568880c3e
sizeof(x) doesn't require x to be an i-c-e for sizeof to be an i-c-e. Thanks to Neil for pointing this out.
...
llvm-svn: 41338
2007-08-23 21:42:50 +00:00
Ted Kremenek
9aae513318
No functionality change. Moved visitor methods for CFGBuilder out-of-line
...
from the class declaration. This enables a nice view of what visitor methods
have been implemented.
llvm-svn: 41337
2007-08-23 21:42:29 +00:00
Chris Lattner
1aaab49a3e
add support for codegen of calls returning complex.
...
llvm-svn: 41336
2007-08-23 21:38:16 +00:00
Steve Naroff
9e1e551c01
Remove a FIXME, allowing ++/-- on Complex types (a GCC extension).
...
Now, the following test case succeeds...
_Complex double x, y;
void test2(int c) {
++x;
}
llvm-svn: 41335
2007-08-23 21:37:33 +00:00
Ted Kremenek
04cca64f8c
moved CFGBuilder into an anonymous namespace
...
llvm-svn: 41334
2007-08-23 21:26:19 +00:00
Steve Naroff
4e1f80d255
- Cleanup "hack" comment and fix typos.
...
- Use getLang().ObjC2 when appropriate.
llvm-svn: 41333
2007-08-23 19:56:30 +00:00
Ted Kremenek
879d8e1f77
Added support for switch, default, and case statements in source-level CFGs.
...
llvm-svn: 41332
2007-08-23 18:43:24 +00:00
Chris Lattner
67998451c7
finish off switch case overlap checking, adding support for
...
verifying case ranges.
llvm-svn: 41331
2007-08-23 18:29:20 +00:00
Steve Naroff
7c34817902
Add helper functions Token::isObjCAtKeyword() and Token::getObjCKeywordID().
...
Convert all clients to the new cleaner, more robust API.
llvm-svn: 41330
2007-08-23 18:16:40 +00:00
Ted Kremenek
13fdfe99cd
Refactored "getSubStmt" and "SubStmt" from the CaseStmt and DefaultStmt
...
class to their common parent class SwitchCase.
llvm-svn: 41329
2007-08-23 18:04:38 +00:00
Chris Lattner
f81460f99c
detect and diagnose empty case ranges:
...
switch.c:16:8: warning: empty case range specified
case 100 ... 99: ; // expected-warning {{empty case range}}
^~~~~~~~~~
llvm-svn: 41328
2007-08-23 17:48:14 +00:00
Ted Kremenek
9ee3bcf81c
For gotos, breaks, and continues where we cannot find a target successor
...
block (because we are creating a CFG from an incomplete AST) we now
(gracefully) have a block ending with such statements not have any successors
instead of firing an assertion.
llvm-svn: 41327
2007-08-23 17:29:58 +00:00
Ted Kremenek
9443f5b1e0
Added support for do..while loops in CFG construction.
...
llvm-svn: 41325
2007-08-23 17:15:32 +00:00
Ted Kremenek
07b5b52cd0
Modified CFG to have explicit "Exit" pointer for exit block. This should
...
have been committed with my previous patch.
llvm-svn: 41324
2007-08-23 16:51:52 +00:00
Ted Kremenek
889073f785
Renamed "CFG::BuildCFG" to "CFG::buildCFG" to have more consistent capitalization.
...
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
2007-08-23 16:51:22 +00:00
Anders Carlsson
cb8f832c26
As suggested by Chris, use MatchRHSPunctuation instead of manually looking for a right parenthesis when parsing @encode() and @protocol().
...
llvm-svn: 41321
2007-08-23 15:31:37 +00:00
Anders Carlsson
e01493d47b
Parse ObjC @protocol expressions.
...
llvm-svn: 41320
2007-08-23 15:25:28 +00:00
Chris Lattner
fcb920d32b
fix a segfault in cases where there are no cases.
...
llvm-svn: 41317
2007-08-23 14:29:07 +00:00
Chris Lattner
10cb5e520f
report duplicate case values. TODO: report duplicate/overlapping ranges.
...
llvm-svn: 41315
2007-08-23 06:23:56 +00:00
Chris Lattner
725c6a4279
this test is passing, though it is generating bogus code at the moment.
...
llvm-svn: 41314
2007-08-23 05:47:53 +00:00
Chris Lattner
fc1c44ac7d
start checking case values of switch stmts more closely. Emit overflow
...
warnings when converting case values to the expression type.
llvm-svn: 41313
2007-08-23 05:46:52 +00:00
Chris Lattner
53e5a38684
Update to match the API from LLVM mainline.
...
llvm-svn: 41312
2007-08-23 05:22:10 +00:00
Chris Lattner
7d75c0d9b6
run .m files as tests
...
llvm-svn: 41308
2007-08-23 01:09:45 +00:00
Chris Lattner
c4e7a66036
Test that cocoa parses with -parse-noop. In the future
...
(when ready) this test should change to test -fsyntax-only.
llvm-svn: 41307
2007-08-23 01:08:54 +00:00
Steve Naroff
7e901fdf86
With this commit, we now successfully parse "Cocoa.h"!
...
llvm-svn: 41303
2007-08-22 23:18:22 +00:00
Ted Kremenek
0a6ec03884
Fixed bugs in source-level CFG construction for "for" and "while" loops
...
where break targets weren't being set and restored properly. Also
cleaned up CFGBuilder code for "for" and "while" to use less reliance
on globals and to have clearer semantics.
llvm-svn: 41302
2007-08-22 22:35:28 +00:00
Steve Naroff
c6e96bfef3
Fix a misleading comment...
...
llvm-svn: 41301
2007-08-22 22:19:13 +00:00
Steve Naroff
0b6a01a449
Add support for parsing protocols.
...
Now we can parse quite a bit of "Foundation.h" (a couple bugs remain).
llvm-svn: 41300
2007-08-22 22:17:26 +00:00
Ted Kremenek
e1810dee74
Added support for "break" statements in source-level ASTs.
...
Some comment cleanups.
llvm-svn: 41299
2007-08-22 21:51:58 +00:00
Ted Kremenek
1aebee0a4d
Added support for "continue" statements in source-level CFGs
...
Cleaned up some code for "for" and "while" loops by making their
implementations more symmetrical (and added a few comments).
llvm-svn: 41298
2007-08-22 21:36:54 +00:00
Ted Kremenek
1c65be13cc
Added preliminary support for while loops within source-level CFGs.
...
Adjusted printing of source-level CFGs to account that the entry block
may not be the first block in the list of blocks a CFG object maintains.
llvm-svn: 41294
2007-08-22 21:05:42 +00:00
Ted Kremenek
88dea224c1
Added explicit pointer within class CFG to the Entry block.
...
Before we assumed that the first block in the list of blocks was the entry
block, but this has posed hurdles during CFG construction.
llvm-svn: 41293
2007-08-22 21:03:50 +00:00
Steve Naroff
f1bc45b1d1
Finish up method prototype parsing.
...
Next step...starting installing class names into the type namespace (so we can start parsing Cocoa headers).
llvm-svn: 41283
2007-08-22 18:35:33 +00:00
Ted Kremenek
7e776b1d9c
Added CFG support for: for loops
...
In CFG dumper, refactored the code to print block terminators into a
StmtVisitor.
Added the method "FinishBlock" to CFGBuilder to do the reversal of statements
in a block instead of calling "reverseStmts" for a block directly. This
was necessary to fix a bug in how blocks with labels were being processed
(some cases would cause the statements to be reversed twice). FinishBlock
detects blocks that start with labels and doesn't do a second reversal.
llvm-svn: 41281
2007-08-22 18:22:34 +00:00
Steve Naroff
99264b4b04
Add support for parsing method prototypes (and other stuff required by @interface).
...
Still need to finish Parser::ParseObjCMethodDecl(). Before I do, I need to do a minor
refactoring of ParseDeclarationOrFunctionDefinition(), to disallow function definitions.
At the moment, @inteface allows function defs (which is incorrect).
llvm-svn: 41275
2007-08-22 16:35:03 +00:00
Ted Kremenek
de979aeff3
Changed data structure recording the CFG blocks that need to be backpatched
...
to labeled blocks from a list to a vector.
llvm-svn: 41274
2007-08-22 15:40:58 +00:00
Anders Carlsson
c5a81ebb1f
Parse @encode expressions.
...
llvm-svn: 41273
2007-08-22 15:14:15 +00:00
Chris Lattner
f265939ebc
update todo markers
...
llvm-svn: 41267
2007-08-22 06:06:56 +00:00
Chris Lattner
8f44d20d69
optimize scope push/pop to avoid work in the common case.
...
llvm-svn: 41265
2007-08-22 05:33:11 +00:00
Chris Lattner
8fb2625b40
Fix the scoping issue Neil pointed out for the rest of
...
the selection statements and iteration statements. Add
spec citations.
llvm-svn: 41264
2007-08-22 05:28:50 +00:00
Chris Lattner
37e54f454a
Fix a nasty C99 scope issue that Neil pointed out (for ifs)
...
This fixes test/Parser/control-scope.c
llvm-svn: 41263
2007-08-22 05:16:28 +00:00
Ted Kremenek
8a63218855
Added CFG support for gotos and labels.
...
Modified CFG so that getEntry(), getExit(), front() and back() return
CFGBlock& instead of CFGBlock*.
llvm-svn: 41258
2007-08-21 23:26:17 +00:00
Chris Lattner
cb1ffbc12e
add some fixme's, implement complex struct members.
...
llvm-svn: 41256
2007-08-21 22:33:41 +00:00
Chris Lattner
d34c999b67
implement codegen for --/++
...
llvm-svn: 41255
2007-08-21 22:25:29 +00:00
Ted Kremenek
1b8ac851d1
Converted CFGBuilder to use StmtVisitor instead of doing a switch
...
dispatch to walk the AST.
llvm-svn: 41254
2007-08-21 22:06:14 +00:00
Chris Lattner
ce8f75bd5b
add cfg.h/cfg.cpp to the xcode project at Ted's request.
...
llvm-svn: 41253
2007-08-21 21:44:59 +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
Steve Naroff
00433d3d37
Implement parsing for objc instance variables.
...
Next step, method...
llvm-svn: 41251
2007-08-21 21:17:12 +00:00
Chris Lattner
875a519ca6
implement __extension__ and unary~ for complex.
...
llvm-svn: 41249
2007-08-21 20:41:44 +00:00
Ted Kremenek
76c4ac2363
Added reverse iterators for the body of CompountStmt. These are useful for
...
CFG construction (among other potential uses).
llvm-svn: 41248
2007-08-21 20:29:50 +00:00
Chris Lattner
ad4569eacb
implement codegen for complex unary +/-
...
llvm-svn: 41247
2007-08-21 20:08:23 +00:00
Anders Carlsson
77621351dd
Don't remove the grammar construct, just the TODO.
...
llvm-svn: 41245
2007-08-21 19:18:49 +00:00
Chris Lattner
d614e7a553
minor nicities.
...
llvm-svn: 41244
2007-08-21 18:51:13 +00:00
Chris Lattner
43ba25187b
Tweak error recovery for missing semicolon after decl. For this:
...
void foo() {
int x
if (x) {
}
}
We now emit:
a.c:5:3: error: parse error
if (x) {
^
1 diagnostic generated.
instead of:
a.c:5:3: error: parse error
if (x) {
^
a.c:9:1: error: expected '}'
^
2 diagnostics generated.
llvm-svn: 41243
2007-08-21 18:36:18 +00:00
Chris Lattner
592d757c92
add unary operator support to the stmtvisitor
...
llvm-svn: 41242
2007-08-21 18:18:25 +00:00
Anders Carlsson
4f803dc6d3
Remove objc-string-literal since it's been implemented now.
...
llvm-svn: 41241
2007-08-21 18:14:25 +00:00
Chris Lattner
a0733a777b
implement support for complex subscripts.
...
llvm-svn: 41240
2007-08-21 18:03:58 +00:00
Chris Lattner
e0e54120b2
allow support for volatile lvalues even though it's still not right.
...
llvm-svn: 41239
2007-08-21 18:02:02 +00:00
Anders Carlsson
76f4a902d7
Implement parsing and code generation of Objective-C string literals.
...
llvm-svn: 41238
2007-08-21 17:43:55 +00:00
Chris Lattner
2dc2af3515
add a new builder ivar.
...
llvm-svn: 41237
2007-08-21 17:39:38 +00:00
Chris Lattner
4b0e7873f6
move EmitLoadOfComplex/EmitStoreOfComplex into ComplexExprEmitter.
...
llvm-svn: 41236
2007-08-21 17:28:34 +00:00
Chris Lattner
3cf417b369
implement comma for complex.
...
llvm-svn: 41235
2007-08-21 17:15:50 +00:00
Chris Lattner
64be48fede
and/or/xor are invalid for complex, even integer complex apparently.
...
llvm-svn: 41234
2007-08-21 17:12:50 +00:00
Chris Lattner
bf1bd0dcc7
simplify code slightly
...
llvm-svn: 41233
2007-08-21 17:03:38 +00:00
Chris Lattner
755a5a9933
add sema support for complex integer types
...
llvm-svn: 41232
2007-08-21 17:02:28 +00:00
Chris Lattner
96d7256d62
reimplement support for complex comparisons, add support for integer complex compares.
...
llvm-svn: 41231
2007-08-21 16:57:55 +00:00
Chris Lattner
f78c30f75d
add getAsComplexType() for consistency
...
llvm-svn: 41229
2007-08-21 16:54:08 +00:00
Chris Lattner
18444b9660
Add the comparisons and logical binops to the visitor.
...
llvm-svn: 41227
2007-08-21 16:38:51 +00:00
Chris Lattner
6ce75dff4d
reimplement complex mul
...
llvm-svn: 41226
2007-08-21 16:34:16 +00:00
Chris Lattner
85e9b4336a
add a testcase I forgot to check in long ago
...
llvm-svn: 41219
2007-08-21 05:56:30 +00:00
Chris Lattner
b01cc9d49a
update some comments.
...
llvm-svn: 41218
2007-08-21 05:54:53 +00:00
Chris Lattner
cbfc73b26c
Split complex arithmetic codegen out from aggregate codegen.
...
This means that we get rid of tons of intermediate allocas. For
example:
void foo(double _Complex a, double _Complex b) {
a = b+a+a;
}
this used to have 4 temporary allocas, now it has zero of them.
This also simplifies the individual visitor methods because they
now can all operate on real/imag pairs instead of having to
load/store all over the place.
llvm-svn: 41217
2007-08-21 05:54:00 +00:00
Chris Lattner
926792f726
simplify this a bit to remove indirection
...
llvm-svn: 41216
2007-08-21 05:02:10 +00:00
Chris Lattner
835635d85a
reimplement addition of complex numbers.
...
llvm-svn: 41215
2007-08-21 04:59:27 +00:00
Chris Lattner
cd9fb2401d
Add the ability to visit binary operators without having to
...
match on binop then explicitly switching again.
llvm-svn: 41214
2007-08-21 04:43:17 +00:00
Chris Lattner
4758b40df0
switch aggregate expr codegen to use a visitor to localize most of the nasty
...
details in its own file.
llvm-svn: 41213
2007-08-21 04:25:47 +00:00
Chris Lattner
ae963ae217
Now that the visitor is defined in one place, it is nice and easy to allow clients
...
to have visitors that return non-void.
llvm-svn: 41212
2007-08-21 04:06:29 +00:00
Chris Lattner
62249a6299
Switch StmtVisitor from using dynamic to static dispatch. This makes it
...
significantly faster and actually reduces the amount of code in the system.
This also allows for future visitor changes.
llvm-svn: 41211
2007-08-21 04:04:25 +00:00
Chris Lattner
91b9a4c8c3
we now correctly emit:
...
unused-expr.c:8:6: warning: comparison of distinct pointer types ('int volatile *' and 'int *')
VP == P;
~~ ^ ~
llvm-svn: 41210
2007-08-21 01:19:46 +00:00
Anders Carlsson
b04ea61b79
Implement code generation for constant CFStrings.
...
llvm-svn: 41206
2007-08-21 00:21:21 +00:00
Chris Lattner
76ba849ed3
Fix array->pointer decay. This unbreaks test/CodeGen/array.c
...
llvm-svn: 41202
2007-08-20 22:37:10 +00:00
Steve Naroff
9717080968
Added Parser::ParseStructDeclaration() as a result of refactoring Parser::ParseStructUnionBody().
...
Motivation: Objective-C can now share this rule. It also makes Parser::ParseStructUnionBody()
a bit smaller/cleaner..
llvm-svn: 41201
2007-08-20 22:28:22 +00:00
Steve Naroff
1eb1ad6c36
Start parsing ObjC classes/categories!
...
Next step, refactor Parser::ParseStructUnionBody() so that struct declarations can
be shared with Objective-C (for declaring instance variables).
llvm-svn: 41200
2007-08-20 21:31:48 +00:00
Anders Carlsson
1d8e521022
Add support for code generation of builtins.
...
llvm-svn: 41188
2007-08-20 18:05:56 +00:00
Ted Kremenek
9fcbb10e86
Added test cases for the return-stack-address checker to test support
...
for the following C++ casts: static_cast, reinterpret_cast, and const_cast.
llvm-svn: 41181
2007-08-20 16:28:05 +00:00
Ted Kremenek
c81614d5d1
Modified ArraySubscriptExpr to have accessors getLHS and getRHS in addition
...
to getBase and getIdx. getBase and getIdx now return a "normalized" view
of the expression (e.g., always "A[4]" instead of possibly "4[A]"). getLHS
and getRHS return the expressions with syntactic fidelity to the original
source code.
Also modified client code of ArraySubscriptExpr, including the AST dumper
and pretty printer, the return-stack value checker, and the LLVM code
generator.
llvm-svn: 41180
2007-08-20 16:18:38 +00:00
Ted Kremenek
8b8215a048
Fixed bug in VarDecl::hasAutoStorage: function parameters implicitly have
...
auto storage, but this routine would incorrectly return false.
llvm-svn: 41162
2007-08-18 04:59:12 +00:00
Ted Kremenek
cb173fc7d0
Added extra test case to check proper handling of archaic array indexing: 4[A]
...
llvm-svn: 41147
2007-08-17 22:17:23 +00:00
Anders Carlsson
f087c0c1c6
Add preliminary support for converting struct types.
...
llvm-svn: 41145
2007-08-17 22:00:32 +00:00
Ted Kremenek
cff94fa201
Added extra semantic checking to do basic detection of
...
"return of stack addresses." ParseReturnStmt now calls CheckReturnStackAddr
to determine if the expression in the return statement evaluates to an
address of a stack variable. If so, we issue a warning.
llvm-svn: 41141
2007-08-17 16:46:58 +00:00
Anders Carlsson
a3a9c43837
Return true in case of error, which is what other functions do.
...
llvm-svn: 41140
2007-08-17 15:44:17 +00:00
Anders Carlsson
98f0790fab
Add initial support for constant CFStrings.
...
llvm-svn: 41136
2007-08-17 05:31:46 +00:00
Steve Naroff
cdee44c12a
Fixed Sema::CheckEqualityOperands() and Sema::CheckRelationalOperands() to deal more
...
thoughtfully with incompatible pointers. This includes:
- Emit a diagnostic when two pointers aren't compatible!
- Promote one of the pointers/integers so we maintain the invariant expected by the
code generator (i.e. that the left/right types match).
- Upgrade the pointer/integer comparison diagnostic to include the types.
llvm-svn: 41127
2007-08-16 21:48:38 +00:00
Ted Kremenek
248d5b277c
Added a comment to ArraySubscriptExpr to note that the expressions like
...
"A[4]" are equivalent to "4[A]", and that a test that the expression
returned by "getBase()" has a pointer type is required to resolve which
subexpression is the "true" base expression of the array index.
llvm-svn: 41113
2007-08-15 22:33:19 +00:00
Ted Kremenek
85786be8e1
Added the following utility methods to VarDecl that provide
...
canonicalized queries of a variable's storage:
hasAutoStorage - Does a variable have (implicit) auto storage?
hasStaticStorage - Does a variable have (implicit) static storage?
hasLocalStorage - Is the variable a non-static local variable?
hasGlobalStorage - Is the variable a global variable or a static
local variable?
Additional comments documenting these functions are included in the
source.
llvm-svn: 41092
2007-08-15 00:03:46 +00:00
Ted Kremenek
c48affb81f
Removed dead variable "hadError" in ParseReturnStmt.
...
llvm-svn: 41079
2007-08-14 18:14:14 +00:00
Ted Kremenek
e68f1aad65
Added support for additional format string checking for the printf
...
family of functions. Previous functionality only included checking to
see if the format string was a string literal. Now we check parse the
format string (if it is a literal) and perform the following checks:
(1) Warn if: number conversions (e.g. "%d") != number data arguments.
(2) Warn about missing format strings (e.g., "printf()").
(3) Warn if the format string is not a string literal.
(4) Warn about the use se of '%n' conversion. This conversion is
discouraged for security reasons.
(5) Warn about malformed conversions. For example '%;', '%v'; these
are not valid.
(6) Warn about empty format strings; e.g. printf(""). Although these
can be optimized away by the compiler, they can be indicative of
broken programmer logic. We may need to add additional support to
see when such cases occur within macro expansion to avoid false
positives.
(7) Warn if the string literal is wide; e.g. L"%d".
(8) Warn if we detect a '\0' character WITHIN the format string.
Test cases are included.
llvm-svn: 41076
2007-08-14 17:39:48 +00:00
Ted Kremenek
86aeed9236
Added documentation to StringLiteral noting that the strings returned by
...
getStrData() are not null-terminated, and the lengths of these strings should
be determined using getByteLength().
llvm-svn: 41055
2007-08-13 22:26:47 +00:00
Chris Lattner
afada9b077
xfail this for now.
...
llvm-svn: 41015
2007-08-11 00:05:07 +00:00
Chris Lattner
6278e6ac30
start splitting out aggregate value computation from EmitExpr into EmitAggExpr.
...
aggregate value and scalar expression computation are very different, this
gets them away from each other. This causes a temporary regression on some
complex number examples.
llvm-svn: 41014
2007-08-11 00:04:45 +00:00
Chris Lattner
11472debe9
make sure to add a newline at the end of the dump
...
llvm-svn: 41011
2007-08-10 21:51:12 +00:00
Ted Kremenek
56c864e3fd
Added "id_idx" parameter to CheckPrintfArguments. This will be used
...
by CheckPrintfArguments to determine if a given printf function
accepts a va_arg argument.
llvm-svn: 41008
2007-08-10 21:21:05 +00:00
Ted Kremenek
cfc9419dd4
Moved id_asprintf before id_vsnprintf in the enum used for indexing
...
KnownFunctionIDs. This allows us to test for a printf-like function
that accepts a va_arg argument using a range comparison.
llvm-svn: 41006
2007-08-10 21:13:51 +00:00
Chris Lattner
cccc311110
add support for a top-level __extension__ marker, implementing a todo.
...
llvm-svn: 41004
2007-08-10 20:57:02 +00:00
Chris Lattner
b87b1b36ee
initial support for checking format strings, patch by Ted Kremenek:
...
"I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf"). Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral."
llvm-svn: 41003
2007-08-10 20:18:51 +00:00
Chris Lattner
d79671fdf2
New file, just a placeholder for now.
...
llvm-svn: 41002
2007-08-10 20:13:28 +00:00
Chris Lattner
ac9823bc5d
Build ASTs before relexing the file. This avoids having comment finding mutate the
...
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
2007-08-10 18:27:41 +00:00
Steve Naroff
47fea35e48
Make sure the arithmetic conversion are done for relation and equality operators.
...
This fixes the following...
eypedef short S;
int test(S X, long long Y) {
return X < Y;
}
Before...
(CompoundStmt 0x2905d00
(ReturnStmt 0x2905cf0
(BinaryOperator 0x2905cd0 'int' '<'
(ImplicitCastExpr 0x2905cc0 'int'
(DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20))
(DeclRefExpr 0x2905ca0 'long long' Decl='Y' 0x2905c50))))
After...
(CompoundStmt 0x2b05c30
(ReturnStmt 0x2b05c20
(BinaryOperator 0x2b05c00 'int' '<'
(ImplicitCastExpr 0x2b05bf0 'long long'
(DeclRefExpr 0x2b05bb0 'S':'short' Decl='X' 0x2b05b50))
(DeclRefExpr 0x2b05bd0 'long long' Decl='Y' 0x2b05b80))))
llvm-svn: 40999
2007-08-10 18:26:40 +00:00
Chris Lattner
213ef35a89
fix this test to pass.
...
llvm-svn: 40996
2007-08-10 17:18:58 +00:00
Chris Lattner
8eab8ff127
fix a codegen bug handling ocuvector element exprs.
...
llvm-svn: 40995
2007-08-10 17:10:08 +00:00
Chris Lattner
e9a91ae4ea
make this harder
...
llvm-svn: 40994
2007-08-10 17:02:59 +00:00
Chris Lattner
90d9120453
implement initial codegen for aggregate return functions. This implements
...
codegen for:
_Complex double bar(int);
void test(_Complex double*);
void test2(int c) {
_Complex double X;
X = bar(1);
test(&X);
}
llvm-svn: 40993
2007-08-10 17:02:28 +00:00
Chris Lattner
02697701d9
Fix a bug handling function -> pointer decay and avoid emitting a noop
...
bitcast.
llvm-svn: 40992
2007-08-10 16:33:59 +00:00
Chris Lattner
8f184b12fc
implement dumper support for declstmt's. The dumper is now "done".
...
llvm-svn: 40969
2007-08-09 18:03:18 +00:00
Chris Lattner
db3b3ff74b
implement dumper support for the rest of expressions.
...
llvm-svn: 40968
2007-08-09 17:35:30 +00:00
Chris Lattner
3f5e4680fb
move a switch to common code.
...
llvm-svn: 40967
2007-08-09 17:34:19 +00:00
Chris Lattner
22c46b5851
minor fixes
...
llvm-svn: 40966
2007-08-09 17:33:55 +00:00
Chris Lattner
66dfa4b40c
dump strings with escapes and other stuff in them nicely.
...
llvm-svn: 40964
2007-08-09 17:14:24 +00:00
Chris Lattner
599e47e6ff
minor cleanups
...
llvm-svn: 40963
2007-08-09 17:01:07 +00:00
Chris Lattner
7b20dc769a
__attribute__ starts a declspec.
...
llvm-svn: 40962
2007-08-09 16:40:21 +00:00
Chris Lattner
273a1ea2e8
add dumping support for some new nodes
...
llvm-svn: 40959
2007-08-09 01:04:32 +00:00
Chris Lattner
9bcd9156b9
Dump out types for expressions, and handle typedefs nicely.
...
This allows us to dump:
typedef short S;
int test(S X, long long Y) {
return X < ((100));
}
as:
typedef short S;
int test(S X, long long Y)
(CompoundStmt 0x2905d40
(ReturnStmt 0x2905d30
(BinaryOperator 0x2905d10 'int' '<'
(ImplicitCastExpr 0x2905d00 'int'
(DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20))
(ParenExpr 0x2905ce0 'int'
(ParenExpr 0x2905cc0 'int'
(IntegerLiteral 0x2905ca0 'int' 100))))))
llvm-svn: 40956
2007-08-09 00:36:22 +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
Steve Naroff
12b0447bc6
Finish implementing __builtin_classify_type()...
...
llvm-svn: 40951
2007-08-08 22:15:55 +00:00
Chris Lattner
87f4836184
now that implicit conversions are explicit, we can eliminate
...
EmitUsualArithmeticConversions.
llvm-svn: 40931
2007-08-08 17:49:18 +00:00
Steve Naroff
4bc57c0de7
Add support for __builtin_classify_type(). This builtin function isn't "public", however
...
it is used by "tgmath.h" (so we need to support it). It might also come in handy when
developing the overloaded function macros for OpenCU.
Next check-in will make this an integer constant expression...
llvm-svn: 40930
2007-08-08 17:48:34 +00:00
Chris Lattner
5ebb2fed89
now that implicit conversions are explicit, we can eliminate
...
EmitExprWithUsualUnaryConversions.
llvm-svn: 40929
2007-08-08 17:43:05 +00:00
Steve Naroff
773df5cf30
Move the function/array conversion for ParmVarDecl's from Sema::ParseIdentifierExpr()
...
to Sema::ParseParamDeclarator(). After discussing this with Chris, we decided this
approach has more immediate benefit (though we loose some information in the AST).
The comment below should describe more (if interested).
llvm-svn: 40907
2007-08-07 22:44:21 +00:00
Chris Lattner
d402939b40
add some helpers
...
llvm-svn: 40901
2007-08-07 17:33:34 +00:00
Steve Naroff
04e8bc8e35
Remove a space from "typeof" printing. It was causing the following error...
...
[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check typeof.c
Warnings expected but not seen:
Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *'
Warnings seen but not expected:
Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *'
Also corrected a typo from my previous commit.
llvm-svn: 40832
2007-08-05 03:24:45 +00:00
Steve Naroff
8a4cf97aa9
Make sure the good old "function/array conversion" is done to function parameters.
...
This resulted in the following error...
[dylan:clang/test/Parser] admin% cat parmvardecl_conversion.c
// RUN: clang -parse-ast-check %s
void f (int p[]) { p++; }
[dylan:clang/test/Parser] admin% clang -parse-ast-check parmvardecl_conversion.c
Errors seen but not expected:
Line 3: cannot modify value of type 'int []'
With this fix, the test case above succeeds.
llvm-svn: 40831
2007-08-05 02:16:31 +00:00
Chris Lattner
81a9688e93
Implement codegen for __builtin_choose_expr. For example:
...
struct X { int A; };
void foo() {
struct X s;
int i;
i = __builtin_choose_expr(0, s, i);
}
compiles to:
%tmp = load i32* %i ; <i32> [#uses=1]
store i32 %tmp, i32* %i
wow :)
llvm-svn: 40801
2007-08-04 00:20:15 +00:00
Chris Lattner
374b06a080
the sse intrinsics are missing, leading to errors.
...
llvm-svn: 40800
2007-08-04 00:19:10 +00:00
Chris Lattner
2f48d5e2ed
fix hang in testsuite
...
llvm-svn: 40799
2007-08-04 00:18:28 +00:00
Chris Lattner
c9a15cabdc
fix constness issues.
...
llvm-svn: 40798
2007-08-04 00:14:36 +00:00
Steve Naroff
0104731e62
Restrict vector component access (using "." and "[]") to variables.
...
Chris suggested this, since it simplifies the code generator.
If this features is needed (and we don't think it is), we can revisit.
The following test case now produces an error.
[dylan:~/llvm/tools/clang] admin% cat t.c
typedef __attribute__(( ocu_vector_type(4) )) float float4;
static void test() {
float4 vec4;
vec4.rg.g;
vec4.rg[1];
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c
t.c:8:12: error: vector component access limited to variables
vec4.rg.g;
^~
t.c:9:12: error: vector component access limited to variables
vec4.rg[1];
^~~
2 diagnostics generated.
llvm-svn: 40795
2007-08-03 22:40:33 +00:00
Steve Naroff
9efdabc565
Implement __builtin_choose_expr.
...
llvm-svn: 40794
2007-08-03 21:21:27 +00:00
Steve Naroff
7d451d614c
Add a test case to validate code gen for typeof/builtin_types_compatible.
...
This test case currently generates the following unexpected warnings (when compared with gcc).
[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check builtin_types_compatible.c
Warnings seen but not expected:
Line 28: expression result unused
Line 29: expression result unused
Line 30: expression result unused
Line 31: expression result unused
Line 32: expression result unused
Line 33: expression result unused
llvm-svn: 40789
2007-08-03 18:38:22 +00:00
Chris Lattner
4048005ad8
implement codegen support for __builtin_types_compatible_p
...
llvm-svn: 40788
2007-08-03 17:51:03 +00:00
Chris Lattner
477ac778ed
fix a buggy comment I added
...
llvm-svn: 40787
2007-08-03 17:47:51 +00:00
Chris Lattner
d268a7a268
Rename AddrLabel and OCUVectorComponent -> AddrLabelExpr and OCUVectorElementExpr respectively. This is for consistency with other expr nodes end with *Expr.
...
llvm-svn: 40785
2007-08-03 17:31:20 +00:00
Chris Lattner
b20b94de3a
testcase for vector element access stuff.
...
llvm-svn: 40783
2007-08-03 16:42:43 +00:00
Chris Lattner
3a44aa7461
implement codegen for multidest ocuvector expressions, like:
...
vec2.yx = vec2; // reverse
llvm-svn: 40782
2007-08-03 16:37:04 +00:00
Chris Lattner
41d480e4d8
add codegen support for storing into a single-element ocu lvalue, such as:
...
vec2.x = f;
llvm-svn: 40781
2007-08-03 16:28:33 +00:00
Chris Lattner
40ff701674
refactor handling of ocuvector lvalue->rvalue codegen into its own method.
...
llvm-svn: 40780
2007-08-03 16:18:34 +00:00
Chris Lattner
fb837dccac
In the common case where we are shuffling a vector, emit an
...
llvm vector shuffle instead of a bunch of insert/extract operations.
For: vec4 = vec4.yyyy; // splat
Emit:
%tmp1 = shufflevector <4 x float> %tmp, <4 x float> undef, <4 x i32> < i32 1, i32 1, i32 1, i32 1 >
instead of:
%tmp1 = extractelement <4 x float> %tmp, i32 1
%tmp2 = insertelement <4 x float> undef, float %tmp1, i32 0
%tmp3 = extractelement <4 x float> %tmp, i32 1
%tmp4 = insertelement <4 x float> %tmp2, float %tmp3, i32 1
%tmp5 = extractelement <4 x float> %tmp, i32 1
%tmp6 = insertelement <4 x float> %tmp4, float %tmp5, i32 2
%tmp7 = extractelement <4 x float> %tmp, i32 1
%tmp8 = insertelement <4 x float> %tmp6, float %tmp7, i32 3
llvm-svn: 40779
2007-08-03 16:09:33 +00:00
Chris Lattner
177bd450e0
add OCUVectorComponent::getNumComponents()
...
llvm-svn: 40778
2007-08-03 16:00:20 +00:00
Chris Lattner
a1036f9155
Add support for scalar-returning element accesses like V.x
...
llvm-svn: 40777
2007-08-03 15:52:31 +00:00
Chris Lattner
73ab9b3c14
implement lvalue to rvalue conversion for ocuvector components. We can now compile stuff
...
like this:
typedef __attribute__(( ocu_vector_type(4) )) float float4;
float4 test1(float4 V) {
return V.wzyx+V;
}
to:
_test1:
pshufd $27, %xmm0, %xmm1
addps %xmm0, %xmm1
movaps %xmm1, %xmm0
ret
and:
_test1:
mfspr r2, 256
oris r3, r2, 4096
mtspr 256, r3
li r3, lo16(LCPI1_0)
lis r4, ha16(LCPI1_0)
lvx v3, r4, r3
vperm v3, v2, v2, v3
vaddfp v2, v3, v2
mtspr 256, r2
blr
llvm-svn: 40771
2007-08-03 00:16:29 +00:00
Chris Lattner
9e751cae27
add support for codegen of an OCUVectorComponent as an lvalue.
...
We can now codegen:
vec4.xy;
as nothing!
llvm-svn: 40769
2007-08-02 23:37:31 +00:00
Chris Lattner
885b4959b6
Add support for encoding a OCUVectorComponent into a single integer.
...
llvm-svn: 40768
2007-08-02 23:36:59 +00:00
Chris Lattner
30709dc432
oops, this is the real fix.
...
llvm-svn: 40766
2007-08-02 22:41:43 +00:00
Chris Lattner
7aa350019a
update test
...
llvm-svn: 40765
2007-08-02 22:36:03 +00:00
Chris Lattner
7e152dbb1f
rename some helpers, have them return the idx of the field being accessed.
...
llvm-svn: 40764
2007-08-02 22:33:49 +00:00
Chris Lattner
f1cb1c8d70
Use static methods, which don't require an instance of OCUVectorType
...
llvm-svn: 40763
2007-08-02 22:20:00 +00:00
Chris Lattner
585afabddd
mark some methods static, don't consider a vector to be an ocuvector
...
llvm-svn: 40762
2007-08-02 22:19:39 +00:00
Chris Lattner
acbd22aaec
silence some warnings.
...
llvm-svn: 40761
2007-08-02 21:50:34 +00:00
Chris Lattner
680918a6fc
Minor comment improvements.
...
llvm-svn: 40760
2007-08-02 21:47:28 +00:00
Chris Lattner
181b01bcfd
make sure we don't lose the ability to parse carbon.h
...
llvm-svn: 40759
2007-08-02 21:40:29 +00:00
Reid Spencer
3d5386d545
Hyphenate a word, to check auto-update feature. Third times the charm!
...
llvm-svn: 40734
2007-08-02 09:58:41 +00:00
Reid Spencer
1d32b07d28
Expand a contraction to test auto-update on commit.
...
llvm-svn: 40733
2007-08-02 09:54:52 +00:00
Reid Spencer
28f1c63015
Test auto-update with minor grammaro fix.
...
llvm-svn: 40732
2007-08-02 09:50:49 +00:00
Chris Lattner
6a340b4351
Fix a bug in my previous commit
...
llvm-svn: 40719
2007-08-02 04:22:39 +00:00
Chris Lattner
016f19a37d
switch a fixme to an assert.
...
llvm-svn: 40717
2007-08-02 04:14:33 +00:00
Steve Naroff
a5645cbea9
Tweak to Expr::isIntegerConstantExpr...make sure the result is appropriately size for TypesCompatibleExpr's.
...
llvm-svn: 40716
2007-08-02 04:09:23 +00:00
Chris Lattner
04e3d20a51
Increase the macro id cache to look up several recent entries, not just the last one.
...
This is important in insane cases like the one dannyb sent me recently:
#define F0(a) void a(){}
#define F1(a) F0(a##0) F0(a##1) F0(a##2) F0(a##3) F0(a##4) F0(a##5) F0(a##6) F0(a##7)
#define F2(a) F1(a##0) F1(a##1) F1(a##2) F1(a##3) F1(a##4) F1(a##5) F1(a##6) F1(a##7)
#define F3(a) F2(a##0) F2(a##1) F2(a##2) F2(a##3) F2(a##4) F2(a##5) F2(a##6) F2(a##7)
#define F4(a) F3(a##0) F3(a##1) F3(a##2) F3(a##3) F3(a##4) F3(a##5) F3(a##6) F3(a##7)
#define F5(a) F4(a##0) F4(a##1) F4(a##2) F4(a##3) F4(a##4) F4(a##5) F4(a##6) F4(a##7)
#define F6(a) F5(a##0) F5(a##1) F5(a##2) F5(a##3) F5(a##4) F5(a##5) F5(a##6) F5(a##7)
F6(f)
cpp is great. :)
llvm-svn: 40715
2007-08-02 03:55:37 +00:00
Steve Naroff
4bd2f71cc7
Tidy up Parser::ParseTypeofSpecifier()...implement FIXME and minor restructure.
...
llvm-svn: 40713
2007-08-02 02:53:48 +00:00
Steve Naroff
ade1649e57
Add a couple const modifiers.
...
llvm-svn: 40708
2007-08-02 00:19:14 +00:00
Steve Naroff
b3deb2e112
Hack Expr::isConstantExpr() to allow for __builtin_types_compatible_p.
...
llvm-svn: 40705
2007-08-02 00:13:27 +00:00
Steve Naroff
788d864d6c
- Finish hooking up support for __builtin_types_compatible_p().
...
- Fix type printing code for recently added TypeOfExpr/TypeOfType.
llvm-svn: 40700
2007-08-01 23:45:51 +00:00
Steve Naroff
7886467b35
Add AST/Sema support for __builtin_types_compatible_p (a GNU extension).
...
Todo...still need to call the action from the parser...
llvm-svn: 40693
2007-08-01 22:05:33 +00:00
Steve Naroff
a773cd5d15
Add comments to getTypeOfExpr/getTypeOfType.
...
Also add instances of TypeOfExpr/TypeOfType to the Types vector (so we can keep track of them).
llvm-svn: 40677
2007-08-01 18:02:17 +00:00
Steve Naroff
236becbbc3
Two typeof() related changes...
...
- Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr().
- Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal
for error diagnostics (since it's more natural to display the expressions type).
One "random" (or at least delayed:-) change...
- Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now
off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will
emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn
this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes
an issue, we can revisit.
llvm-svn: 40676
2007-08-01 17:20:42 +00:00
Chris Lattner
7b9f04eb19
update this to build with LLVM ToT
...
llvm-svn: 40665
2007-08-01 06:24:52 +00:00
Chris Lattner
bf2f38693e
Print floating point literal values better.
...
llvm-svn: 40659
2007-08-01 00:23:58 +00:00
Steve Naroff
872da803b2
Tighten up Parser::ParseTypeofSpecifier().
...
Add some more tests to typeof.c. Also added a couple of missing "expect" attributes that caused the test to fail.
llvm-svn: 40656
2007-07-31 23:56:32 +00:00
Chris Lattner
0fd893e643
remove more explicit accesses to the canonical type pointer.
...
llvm-svn: 40653
2007-07-31 21:33:24 +00:00
Chris Lattner
e5a6cbd457
simplify some type checking code, don't explicitly access
...
canonical types.
llvm-svn: 40652
2007-07-31 21:27:01 +00:00
Chris Lattner
0ddc7ba2e5
move trivial type predicates inline.
...
llvm-svn: 40651
2007-07-31 21:13:58 +00:00
Chris Lattner
4197796f65
split the rest of the type predicates into pure predicates:
...
there is now an isXXXType and a getAsXXXType
llvm-svn: 40646
2007-07-31 19:29:30 +00:00
Chris Lattner
ba32aed8a9
add internals manual to project
...
llvm-svn: 40645
2007-07-31 18:57:09 +00:00
Chris Lattner
5070523a07
Owen pointed out that this made no sense :)
...
llvm-svn: 40644
2007-07-31 18:54:50 +00:00
Chris Lattner
ea23d287b5
add two missing files to the xcode project.
...
llvm-svn: 40643
2007-07-31 18:43:04 +00:00
Chris Lattner
cd1d086b5a
rename isReferenceType to follow the new scheme.
...
llvm-svn: 40640
2007-07-31 16:56:34 +00:00
Chris Lattner
c996b176e8
make isPointerType() a pure predicate, rename the
...
existing one to getAsPointerType()
llvm-svn: 40639
2007-07-31 16:53:04 +00:00
Chris Lattner
578611857d
update name
...
llvm-svn: 40637
2007-07-31 16:50:51 +00:00
Steve Naroff
ad373bdcfe
Add parsing and AST support for GNU "typeof".
...
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.
llvm-svn: 40631
2007-07-31 12:34:36 +00:00
Chris Lattner
49820d63dc
Oops, I committed the wrong file before. This expands the description of
...
type.
llvm-svn: 40620
2007-07-31 06:37:39 +00:00
Chris Lattner
c6684bc0c5
Add a start at a clang internals manual, documenting some
...
of the more subtle and interesting classes.
llvm-svn: 40615
2007-07-31 05:42:17 +00:00
Chris Lattner
bcb22a9c8d
add a link
...
llvm-svn: 40614
2007-07-31 04:52:37 +00:00
Chris Lattner
fedeaa3045
Don't use canonical type for sema here. In
...
void func() {
typedef int foo;
foo *Y;
**Y; // error
}
we now get:
indirection requires pointer operand ('foo' invalid)
instead of:
indirection requires pointer operand ('int' invalid)
llvm-svn: 40597
2007-07-30 18:53:26 +00:00
Steve Naroff
2dc379a7ae
Upgrade a comment...
...
llvm-svn: 40585
2007-07-30 03:52:55 +00:00
Steve Naroff
0d595ca0bb
Finish up semantic analysis for vector components.
...
llvm-svn: 40584
2007-07-30 03:29:09 +00:00
Steve Naroff
ddf5a1d7a6
Implement pretty diagnostics when doing on-the-fly vector sizing (for vector component access).
...
For example, before this commit, the following diagnostics would be emitted...
ocu.c:49:12: error: incompatible types assigning 'float __attribute__((ocu_vector_type(3)))' to 'float4'
vec4_2 = vec4.rgb; // shorten
~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float __attribute__((ocu_vector_type(2)))' to 'float'
f = vec2.xx; // shorten
~ ^ ~~~~~~~
Now, the diagnostics look as you would expect...
ocu.c:49:12: error: incompatible types assigning 'float3' to 'float4'
vec4_2 = vec4.rgb; // shorten
~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float2' to 'float'
f = vec2.xx; // shorten
~ ^ ~~~~~~~
llvm-svn: 40579
2007-07-29 16:33:31 +00:00
Steve Naroff
f7a5da17d9
Added a new expression, OCUVectorComponent.
...
llvm-svn: 40577
2007-07-28 23:10:27 +00:00
Steve Naroff
f8fd09e22b
Implement syntax/semantic analysis for OCU Vector Components.
...
Next step, AST support...
llvm-svn: 40568
2007-07-27 22:15:19 +00:00