Commit Graph

1761 Commits

Author SHA1 Message Date
Chris Lattner b620c34bb0 merge checkrelational and checkequality into CheckCompareOperands,
to merge duplicate code.

llvm-svn: 41410
2007-08-26 01:18:55 +00:00
Chris Lattner 1895e58c84 Cases like this:
char *C;
  C != ((void*)0);

Should not warn about incompatible pointer types.  Also, make sure to
insert an implicit conversion even if the operand is null.

llvm-svn: 41408
2007-08-26 01:10:14 +00:00
Chris Lattner 1bc6fac5c6 new testcase
llvm-svn: 41406
2007-08-25 21:57:08 +00:00
Chris Lattner 27f00282e9 The new correct compound assignment operators exposed a bug in codegen.
llvm-svn: 41405
2007-08-25 21:56:20 +00:00
Steve Naroff 46c72915f4 Surpress the UsualUnaryConversions for compound assignment operators. This change
eliminates the possibility that the left hand expression is an ImplicitCastExpr.
As a result, I removed the check for ImplicitCastExpr in Expr::isLvalue().

This results in the following AST's...

[dylan:~/llvm/tools/clang] admin% cat fix.c

short x; void test4(char c) { 
  x += c; 
  x = x + c;
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang fix.c -parse-ast-dump
Read top-level variable decl: 'x'

void test4(char c)
(CompoundStmt 0x2605d30
  (CompoundAssignOperator 0x2605c40 'short' '+='
    (DeclRefExpr 0x2605c00 'short' Decl='x' 0x2605a80)
    (DeclRefExpr 0x2605c20 'char' Decl='c' 0x2605bc0))
  (BinaryOperator 0x2605d10 'short' '='
    (DeclRefExpr 0x2605c60 'short' Decl='x' 0x2605a80)
    (ImplicitCastExpr 0x2605d00 'short'
      (BinaryOperator 0x2605ce0 'int' '+'
        (ImplicitCastExpr 0x2605cc0 'int'
          (DeclRefExpr 0x2605c80 'short' Decl='x' 0x2605a80))
        (ImplicitCastExpr 0x2605cd0 'int'
          (DeclRefExpr 0x2605ca0 'char' Decl='c' 0x2605bc0))))))

llvm-svn: 41404
2007-08-25 19:54:59 +00:00
Chris Lattner 479ed3aab8 read and ignore the body of a namespace.
llvm-svn: 41403
2007-08-25 18:15:16 +00:00
Steve Naroff e2562ff99d Change Expr::isLvalue() to properly deal with ImplicitCastExpr's.
This fixes the following bug...

t.c:1:31: error: expression is not assignable
short x; void foo(char c) { x += c; }

This case, among others are now captured in implicit-casts.c.

llvm-svn: 41402
2007-08-25 14:37:06 +00:00
Steve Naroff aac9415bfb Give CXXBoolLiteralExpr a type (all expressions need a valid type).
This fixes the following:

******************** TEST 'Parser/cxx-bool.cpp' FAILED! ********************
Command:
clang -fsyntax-only Parser/cxx-bool.cpp
Output:
SemaExpr.cpp:731: failed assertion `!t.isNull() && "DefaultFunctionArrayConversion - missing type"'
Output/cxx-bool.cpp.out.script: line 1: 22697 Abort trap              clang -fsyntax-only Parser/cxx-bool.cpp

llvm-svn: 41401
2007-08-25 14:02:58 +00:00
Chris Lattner a5235173bc refactor enough of the top-level parsing logic to parse and
ignore 'namespace foo {}'

llvm-svn: 41400
2007-08-25 06:57:03 +00:00
Chris Lattner 66b67efa61 C++ explicitly allows an empty source file.
llvm-svn: 41399
2007-08-25 05:47:03 +00:00
Chris Lattner e33fbdb898 Fix the test/Sema/format-strings.c regression. This code should be refactored.
llvm-svn: 41398
2007-08-25 05:36:18 +00:00
Chris Lattner 6d5922fd66 reenable this.
llvm-svn: 41397
2007-08-25 05:31:19 +00:00
Chris Lattner 9449fd7bc3 Fix the regression on test/Sema/cfstring.c
llvm-svn: 41396
2007-08-25 05:30:33 +00:00
Chris Lattner a206358bb6 test the parser only, not sema.
llvm-svn: 41395
2007-08-25 05:26:51 +00:00
Chris Lattner 8692811955 Split the ASTNode out for compound assignments out from binary operators. Now
they show up in dumps etc.

llvm-svn: 41393
2007-08-25 02:00:02 +00:00
Chris Lattner d8c9fc5ed8 fix off-by-one error
llvm-svn: 41392
2007-08-25 01:55:00 +00:00
Chris Lattner e7d0864aed Fix clang -parse-ast-dump carbon.c
llvm-svn: 41391
2007-08-25 01:49:16 +00:00
Chris Lattner 4d15a0dbc0 rename sNames -> StmtClassInfo. Make lookups constant time.
llvm-svn: 41390
2007-08-25 01:42:24 +00:00
Steve Naroff 0c1c7ed5e6 This modest change insures ImplicitCastExpr's get generated for all "assignments",
while includes init decls, assignment exprs, call exprs, and return statements.

Here are a few examples with the correct AST's...

[dylan:~/llvm/tools/clang] admin% cat impcomp.c

_Complex double X;
void test2(int c) {
  X = 5;
}
void foo() {
  int i;
  double d = i;
  double _Complex a = 5;

  test2(a);
  a = 5;
  d = i;
}


[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang impcomp.c -parse-ast-dump
Read top-level variable decl: 'X'

void test2(int c)
(CompoundStmt 0x2605ce0
  (BinaryOperator 0x2605cc0 '_Complex double' '='
    (DeclRefExpr 0x2605c70 '_Complex double' Decl='X' 0x2605af0)
    (ImplicitCastExpr 0x2605cb0 '_Complex double'
      (IntegerLiteral 0x2605c90 'int' 5))))


void foo()
(CompoundStmt 0x2606030
  (DeclStmt 0x2605bd0
    0x2605d90 "int i")
  (DeclStmt 0x2605e20
    0x2605de0 "double d =
      (ImplicitCastExpr 0x2605e10 'double'
        (DeclRefExpr 0x2605dc0 'int' Decl='i' 0x2605d90))")
  (DeclStmt 0x2605e90
    0x2605e50 "_Complex double a =
      (ImplicitCastExpr 0x2605e80 '_Complex double'
        (IntegerLiteral 0x2605e30 'int' 5))")
  (CallExpr 0x2605f20 'void'
    (ImplicitCastExpr 0x2605f00 'void (*)(int)'
      (DeclRefExpr 0x2605ea0 'void (int)' Decl='test2' 0x2605c00))
    (ImplicitCastExpr 0x2605f10 'int'
      (DeclRefExpr 0x2605ec0 '_Complex double' Decl='a' 0x2605e50)))
  (BinaryOperator 0x2605fa0 '_Complex double' '='
    (DeclRefExpr 0x2605f50 '_Complex double' Decl='a' 0x2605e50)
    (ImplicitCastExpr 0x2605f90 '_Complex double'
      (IntegerLiteral 0x2605f70 'int' 5)))
  (BinaryOperator 0x2606010 'double' '='
    (DeclRefExpr 0x2605fc0 'double' Decl='d' 0x2605de0)
    (ImplicitCastExpr 0x2606000 'double'
      (DeclRefExpr 0x2605fe0 'int' Decl='i' 0x2605d90))))

llvm-svn: 41379
2007-08-24 22:33:52 +00:00
Chris Lattner 74ed76bb0e remove a dead argument
llvm-svn: 41377
2007-08-24 21:41:10 +00:00
Chris Lattner 9f0ad96b3e implement codegen for real/imag. TODO: imag of non-complex.
llvm-svn: 41376
2007-08-24 21:20:17 +00:00
Chris Lattner 30b5dd0b79 Implement sema support for __real/__imag nodes.
llvm-svn: 41375
2007-08-24 21:16:53 +00:00
Ted Kremenek 066dd939c0 Added child_begin/child_end to all subclasses of Stmt in Stmt.h. All
concrete subclasses of Stmt are now required to implement 
child_begin/child_end.

llvm-svn: 41374
2007-08-24 21:09:09 +00:00
Chris Lattner 3d966d6556 Teach emit-llvm for scalars to properly handle compound assignment
operators in all their glory :)

llvm-svn: 41373
2007-08-24 21:00:35 +00:00
Ted Kremenek 485b13f397 Added ExprCXX.cpp
llvm-svn: 41370
2007-08-24 20:24:16 +00:00
Ted Kremenek e3a0c14614 Implementation of child_begin/child_end for C++ expressions.
llvm-svn: 41369
2007-08-24 20:21:10 +00:00
Ted Kremenek acc4903b3e Implemented child_begin/child_end for our current set of C++ expressions.
llvm-svn: 41368
2007-08-24 20:20:38 +00:00
Ted Kremenek 23702b6afb Finished adding child_begin/child_end to all subclasses of Stmt in Expr.h.
llvm-svn: 41366
2007-08-24 20:06:47 +00:00
Steve Naroff be4c4d14c3 Surpress ImplicitCastExprs for compound assignment expressions. For compound assignments,
it is o.k. for the LHS and RHS to have different types. Converting the type can cause
errors like the one Chris noticed (below).

This change required a fair number of diffs (since there is a lot of shared code
between single and compound assignments). This makes the API's look a bit uglier,
however I couldn't think of a better way to do it (without duplicating code).

Fix the following (incorrect) error:

int A;
long long B;

void foo() {
  A /= B;
}

$ clang ~/scalar.c -emit-llvm
/Users/sabre/scalar.c:6:5: error: expression is not assignable
  A /= B;
  ~ ^

Now it works properly...

[dylan:~/llvm/tools/clang] admin% cat compound.c
int A;
long long B;

void foo() {
  A /= B;
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang compound.c -parse-ast-dump
Read top-level variable decl: 'A'
Read top-level variable decl: 'B'

void foo()
(CompoundStmt 0x2605c40
  (BinaryOperator 0x2605c20 'int' '/=' ComputeTy='long long'
    (DeclRefExpr 0x2605be0 'int' Decl='A' 0x2605a80)
    (DeclRefExpr 0x2605c00 'long long' Decl='B' 0x2605ab0)))

llvm-svn: 41364
2007-08-24 19:07:16 +00:00
Ted Kremenek 85e92ec6ff Began implementing "child iterator" interface for Stmts and Exprs. Each
subclass of Stmt will implement child_begin() and child_end(), which will
be used to iterate over all the children (subexpressions/substatements) of
a Stmt object.  This will provide for easy traversal over the AST, which
is useful for a variety of purposes.

None of the interfaces to subclasses of Stmt will be changed (other than
adding the child_begin and child_end methods).

The only caveat is that the implementation of subclasses of Stmt will require
colocating all substatements (subexpressions) in an array.  This is because
we define child_iterator as Stmt**.  All accessor methods to subexpressions
will need to be altered to reflect this new implementation.

This patch includes the typedefs for child_iterator, as well the implementation
for child_begin/child_end for the primary expressions and some postfix
expressions.

llvm-svn: 41363
2007-08-24 18:13:47 +00:00
Steve Naroff 9d13917cff Make sure we get extension diagnostics for GCC's complex extensions.
Now we emit the following when -pedantic-errors is enabled...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -pedantic-errors
complex.c:4:3: error: ISO C does not support '++'/'--' on complex integer types
  ++x;
  ^ ~
complex.c:9:7: error: ISO C does not support '~' for complex conjugation
  X = ~Y;
      ^
complex.c:10:7: error: ISO C does not support '~' for complex conjugation
  x = ~y;
      ^

llvm-svn: 41362
2007-08-24 17:20:07 +00:00
Chris Lattner 100198f3f7 print the computation type for compound assignment operators in dumps.
llvm-svn: 41361
2007-08-24 16:24:49 +00:00
Chris Lattner 2da04b3322 completely refactor codegen of scalar expressions out into its own CGExprScalar.cpp file.
This patch temporarily breaks compound assignment operators, but greatly simplifies many
things.

llvm-svn: 41355
2007-08-24 05:35:26 +00:00
Chris Lattner 11e0de5193 rename two files.
llvm-svn: 41350
2007-08-24 02:22:53 +00:00
Chris Lattner db0d60d5b5 implement codegen of builtin_choose_expr for complex.
llvm-svn: 41349
2007-08-24 02:18:47 +00:00
Chris Lattner 8ad56707ea stub out complex -> bool conversion.
llvm-svn: 41347
2007-08-24 00:01:20 +00:00
Chris Lattner afd455c0cf make this harder
llvm-svn: 41346
2007-08-23 23:49:47 +00:00
Chris Lattner 0b984995b7 implement complex subtraction
llvm-svn: 41345
2007-08-23 23:46:33 +00:00
Chris Lattner 08b15df766 implement passing of complex and aggregates through call args.
llvm-svn: 41344
2007-08-23 23:43:33 +00:00
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