Commit Graph

1399 Commits

Author SHA1 Message Date
Chris Lattner c02c4abe5b Cache macro expander objects to avoid thrashing malloc in heavy expansion situations.
This doesn't significantly improve carbon.h, but it does speed up
INPUTS/macro_pounder_obj.c by 48%

llvm-svn: 39864
2007-07-15 00:25:26 +00:00
Chris Lattner 03928c7f9a Make parser scope cache be a member of the parser instead of a global,
which makes it multithread clean.

llvm-svn: 39863
2007-07-15 00:04:39 +00:00
Chris Lattner 564f478595 switch function-like macros from using a vector for their arguments to an
explicitly new'd array.  The array never mutates once created, so a vector
is overkill.

llvm-svn: 39862
2007-07-14 22:46:43 +00:00
Chris Lattner 819f2ef77b switch from using a vector to a smallvector for macro replacement tokens
This speeds up parsing carbon.h by 3.3% by avoiding some malloc traffic for 
small macros.

llvm-svn: 39861
2007-07-14 22:15:50 +00:00
Chris Lattner f40fe99118 expose an iterator interface to getReplacementTokens instead of the datastructure itself.
llvm-svn: 39860
2007-07-14 22:11:41 +00:00
Chris Lattner a3834341c5 split function-like and object-like macro body parsing to make the
code more obvious.

llvm-svn: 39859
2007-07-14 21:54:03 +00:00
Gabor Greif e97cd7e65c add FIXME and un-XFAIL test
llvm-svn: 39858
2007-07-14 20:05:18 +00:00
Bill Wendling 657a203adf Add missing directory
llvm-svn: 39853
2007-07-14 09:37:10 +00:00
Chris Lattner 4481b428db A significant refactoring of the type size stuff to also
compute type alignment.  This info is needed for struct layout.

llvm-svn: 39850
2007-07-14 01:29:45 +00:00
Chris Lattner 9d3b0e0001 Implement trivial integer initializers, like 'int X = 4;' for global
vars.  Approach suggested by Keith.

llvm-svn: 39849
2007-07-14 00:23:28 +00:00
Chris Lattner 6ee31f5df8 In "int X,Y;", compile both X and Y.
llvm-svn: 39848
2007-07-14 00:16:50 +00:00
Chris Lattner 027f21dd72 add a fixme
llvm-svn: 39847
2007-07-14 00:01:01 +00:00
Chris Lattner 666115c848 Improve char literal pretty printing, patch by Keith Bauer!
llvm-svn: 39846
2007-07-13 23:58:20 +00:00
Gabor Greif 03a0073b36 fix type of main, use !=
llvm-svn: 39842
2007-07-13 23:40:27 +00:00
Gabor Greif d4606aa36e implement _Complex * == and !=
llvm-svn: 39841
2007-07-13 23:33:18 +00:00
Steve Naroff b8ea4fb8db More changes related to implementing ImplicitCastExpr.
- Fixed a recent regression discovered by Keith Bauer (thanks!). 
The fix involved adding (back) two arguments to UsualArithmeticConversions.
Without the reference arguments, no unary conversions were being passed back
to the caller. This had the effect of turning off the UsualUnaryConversions.
- Refactored CheckAssignmentConstraints into 3 functions. CheckAssignmentConstraints,
CheckSingleAssignmentConstraints, and CheckCompoundAssignmentConstraints. 
- Changed the argument type of DefaultFunctionArrayConversion from QualType->Expr*&.
- Removed a bunch of casts in routines I was working on (cleanup).
- Fixed the visitor for ImplicitCastExpr (oops).

llvm-svn: 39840
2007-07-13 23:32:42 +00:00
Chris Lattner 355332d3f3 Use target info to decide the sizes of basic types.
llvm-svn: 39838
2007-07-13 22:27:08 +00:00
Chris Lattner 0523dc94c8 Add missing citation.
llvm-svn: 39837
2007-07-13 22:16:13 +00:00
Gabor Greif f7b1f667d4 a simple _Complex testcase
llvm-svn: 39836
2007-07-13 22:15:44 +00:00
Chris Lattner 983a8bbbb2 Move getSize() out of type, into ASTContext, where it has target info, and
where ASTContext can manage caches for struct layout, etc.

llvm-svn: 39835
2007-07-13 22:13:22 +00:00
Chris Lattner 35ed92817a Unspecified type specs default to int. This fixes a crash
on test/Sema/implicit-int.c

llvm-svn: 39833
2007-07-13 21:02:29 +00:00
Chris Lattner 2ce5dd4c98 remove some extraneous spaces, no functionality change.
llvm-svn: 39832
2007-07-13 21:01:17 +00:00
Chris Lattner 388cf760e2 implement codegen support for implicit casts.
llvm-svn: 39831
2007-07-13 20:25:53 +00:00
Chris Lattner 5c2f76b395 eliminate extraneous type, add accessors.
llvm-svn: 39830
2007-07-13 20:25:36 +00:00
Chris Lattner 91dacfec85 Check in these testcases.
llvm-svn: 39829
2007-07-13 20:18:44 +00:00
Chris Lattner effb7a350f new testcase that crashes the cfe due to implicit conversion fun
llvm-svn: 39826
2007-07-13 20:11:01 +00:00
Chris Lattner a5ba0cb772 silence a bogus gcc warning.
llvm-svn: 39824
2007-07-13 20:07:11 +00:00
Steve Naroff b66fb7465b Removed some superfluous code. The getType() method and associated
assert is now done in UsualUnaryConversions().

llvm-svn: 39818
2007-07-13 17:39:21 +00:00
Chris Lattner f9aba2c2b4 remove use of alloca.
llvm-svn: 39815
2007-07-13 17:10:38 +00:00
Steve Naroff 7a5af78270 Add (explicit) AST support for implicit casts. This should simplify the
code generator. Source translation tools can simply ignore this node.

- Added a new Expr node, ImplicitCastExpr.
- Changed UsualUnaryConversions/UsualArithmeticConversions to take references 
to Expr *'s. This will allow these routines to instantiate the new AST node
and pass it back.
- Changed all clients of UsualUnary/UsualArithmetic (lot's of diff's).
- Changed some names in CheckConditionalOperands. Several variables where
only distinguished by their case (e.g. Cond, cond). Yuck (what was I thinking).
- Removed an old/crufty constructor in CastExpr (cleanup).

This check-in does not actually create the new AST node. I wanted to separate
the mechanical changes from the semantic changes. In addition, I need to 
coordinate with Chris, since the semantic change will break the code generator.

llvm-svn: 39814
2007-07-13 16:58:59 +00:00
Chris Lattner 7c9c5362ef check in the basic llvm license
llvm-svn: 39812
2007-07-13 15:47:47 +00:00
Gabor Greif 441b3d47be Solaris needs an included header for alloca
llvm-svn: 39797
2007-07-13 08:21:39 +00:00
Chris Lattner 6e9d9b350e "Codegen for Character Literals and Conditional Operator
Both in one patch, and the test case that Chris didn't commit last
time is in there too...

I'll split the patch up if somebody wants it split."

Patch by Keith Bauer.

llvm-svn: 39796
2007-07-13 05:18:11 +00:00
Chris Lattner d14bfa94a6 implement support for basic codegen of global variables with no initializers.
llvm-svn: 39795
2007-07-13 05:13:43 +00:00
Chris Lattner fc7634f2ab "Someone typed "PtrToInt" where they meant "IntToPtr".
I've added a tests/CodeGen directory, and a test for this case that
used to fail and now passes."

Patch by Keith Bauer

llvm-svn: 39794
2007-07-13 03:25:53 +00:00
Chris Lattner d2b88ab313 Implement codegen for + and - with pointers. Patch contributed by
Keith Bauer.

llvm-svn: 39793
2007-07-13 03:05:23 +00:00
Anton Korobeynikov b6719478b9 Workaround gcc 3.4.x bug
llvm-svn: 39792
2007-07-13 00:48:55 +00:00
Steve Naroff 1c8b7d36e6 Two changes...
- Teach all the integer/float predicates on Type about Vectors.
- Disallow bitwise compliment on float vectors. For example...

typedef float __attribute__(( vector_size(16) )) float4;

float4 float4_return()
{
    float4 xx;

    return ~xx;
}

...now emits the following diagnostic...

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang bug.c
bug.c:8:12: error: invalid argument type to unary expression 'float4'
    return ~xx;
           ^
1 diagnostic generated.

llvm-svn: 39791
2007-07-12 21:46:55 +00:00
Chris Lattner cf9be2d315 update tests
llvm-svn: 39786
2007-07-12 16:52:08 +00:00
Chris Lattner d1c161786f -pedantic no longer defaults to on.
llvm-svn: 39785
2007-07-12 16:49:27 +00:00
Chris Lattner 1e52eee112 update test
llvm-svn: 39784
2007-07-12 16:48:52 +00:00
Chris Lattner 113d1410ce don't pick up random stuff in .svn directories.
llvm-svn: 39783
2007-07-12 16:46:07 +00:00
Gabor Greif ffc337b1e1 add missing header
(needed on Solaris)

llvm-svn: 39781
2007-07-12 16:00:00 +00:00
Chris Lattner bd4de5df77 Fix "no newline at end of file" warnings. Patch contributed by
Benoit Boissinot!

llvm-svn: 39780
2007-07-12 15:43:07 +00:00
Chris Lattner 20c4ff2845 Improve portability to compilers where <cassert> is not implicitly
included.  Patch contributed by Benoit Boissinot!

llvm-svn: 39779
2007-07-12 15:32:57 +00:00
Chris Lattner 2705b37f02 Allow this to compile on compilers where <string>
doesn't imply <cassert>.

llvm-svn: 39778
2007-07-12 15:30:49 +00:00
Anton Korobeynikov b76cda05e7 Properly use local variable declaration inside a switch case
llvm-svn: 39777
2007-07-12 15:26:50 +00:00
Chris Lattner 10a4d43eae add missing specification for a default argument. I guess g++ 4.0 doesn't
notice this.

llvm-svn: 39776
2007-07-12 15:26:16 +00:00
Chris Lattner 07eb733ef8 Evaluate the initializer for automatic variables.
llvm-svn: 39771
2007-07-12 00:39:48 +00:00
Chris Lattner 79c57590a3 remember the initializer for a variable in the AST and teach the
pretty printer to print it.

llvm-svn: 39770
2007-07-12 00:36:32 +00:00
Chris Lattner dcca487cfa implement codegen support for pre/post inc/dec.
llvm-svn: 39765
2007-07-11 23:43:46 +00:00
Chris Lattner e399420b51 Fix a release build of clang.
llvm-svn: 39756
2007-07-11 21:50:45 +00:00
Chris Lattner 49ec4b6eba update this.
llvm-svn: 39746
2007-07-11 18:58:19 +00:00
Chris Lattner 28404cf449 Test commit
llvm-svn: 39738
2007-07-11 17:31:59 +00:00
Chris Lattner 63e92754d0 Convert .cvsignore files
llvm-svn: 39731
2007-07-11 06:43:45 +00:00
Steve Naroff 68b52f6df7 Bug #:
Submitted by:
Reviewed by:
Remove reference to Attr.h...

llvm-svn: 39730
2007-07-11 00:45:07 +00:00
Steve Naroff b207d6bed7 Bug #:
Submitted by:
Reviewed by:
Removed Attr.[h,cpp]...they didn't have any useful content.

When more (GCC) attributes are added, we might want to create a file
of this ilk. For now, it's better to remove them (to eliminate any confusion).

I also update the Xcode project file...

llvm-svn: 39729
2007-07-11 00:42:37 +00:00
Steve Naroff e728ba3504 Bug #:
Submitted by:
Reviewed by:
Two vector fixes:

- Sema::CheckAssignmentConstraints() needs to compare the canonical type.
- Expr::isLvalue() needs to disallow subscripting into a vector returned by a function. This
follows the rules for struct returns (in C, at least...C++ is another story:-)

Here is an example...

float4 float4_return()
{
    float4 xx;

    return xx;
}
void add_float4_void_return(float4 *a, float4 *b, float4 *result)
{
    float f;
    float4_return()[1] = f; // now illegal
}

llvm-svn: 39728
2007-07-10 22:20:04 +00:00
Chris Lattner c14236b8ae implement codegen support for the "default argument promotions" (C99 6.5.2.2p6).
Not having this prevented promoting float arguments to double when passed
into printf, for example.

llvm-svn: 39727
2007-07-10 22:18:37 +00:00
Chris Lattner 11eef2eb9c remove obsolete comment.
llvm-svn: 39726
2007-07-10 22:18:03 +00:00
Chris Lattner a779b3df28 implement codegen support for rvalue-only vector subscripts, such as:
float4 test(void);
float test2() {
  return test()[1];
}

llvm-svn: 39725
2007-07-10 21:58:36 +00:00
Chris Lattner 08c4b9ffec Add support for codegen'ing vector subscripts, at least when they are lvalues.
llvm-svn: 39724
2007-07-10 21:17:59 +00:00
Steve Naroff b29cdd543f Bug #:
Submitted by:
Reviewed by:
Support the following...

1. Type checking and codegen support for V[i] on vectors. Hacked
Sema::ParseArraySubscriptExpr().

2. Unary bitwise complement ("~") on vectors. Hacked Sema::ParseUnaryOp().

llvm-svn: 39723
2007-07-10 18:23:31 +00:00
Chris Lattner 436806ad05 In code like this:
typedef float float4 __attribute__((vector_size (16)));
void addFloat4(float4 a, float4 b) {
    float4 temp;
}

make sure to add 'temp' to the stmt tree as a declstmt.

llvm-svn: 39722
2007-07-10 05:03:31 +00:00
Chris Lattner 50d4abd24c Add support for vector formal arguments.
llvm-svn: 39721
2007-07-10 00:28:12 +00:00
Chris Lattner 6eea886b9e implement support for llvm codegen of vectors. That was much easier than
I expected :)

llvm-svn: 39720
2007-07-10 00:23:39 +00:00
Steve Naroff 97b9e91eb7 Bug #:
Submitted by:
Reviewed by:
Added primitive support for 32-bit floating point literals.

llvm-svn: 39719
2007-07-09 23:53:58 +00:00
Chris Lattner 2ada32ed7d implement codegen support for FP literals
llvm-svn: 39718
2007-07-09 23:03:16 +00:00
Steve Naroff 84ff4b44b0 Bug #:
Submitted by:
Reviewed by:
Typechecking support for vectors...

- Added CheckVectorOperands(). Called from CheckAdditionOperands,
CheckMultiplyDivideOperands, CheckSubstractionOperands, and CheckBitwiseOperands.
- Added diagnostic for converting vector values of different size.
- Modified Type::isArithmeticType to include vectors.

Sould be ready for Chris to add code generation. I will continue testing/refining.

llvm-svn: 39717
2007-07-09 21:31:10 +00:00
Steve Naroff 4dddb6194b Bug #:
Submitted by:
Reviewed by:
Fix a bozo bug in HandleDeclAttribute...only install a new type when appropriate.
Also changed setType/setUnderlyingType to return void.

llvm-svn: 39716
2007-07-09 18:55:26 +00:00
Steve Naroff 4ae0ac6a06 Bug #:
Submitted by:
Reviewed by:
- Finished semantic analysis for vectors, added some diagnostics.
- Added AST for vectors (instantiation, installation into the decl).
- Fixed bug in ParseArraySubscriptExpr()...this crasher was introduced by me
when we added the range support.
- Turned pedantic off by default. Since vectors are gcc extensions, having
pedantic on by default was annoying. Turning it off by default is  also
consistent with gcc (but this wasn't my primary motivation).
- Tweaked some comments and diagnostics.

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

llvm-svn: 39715
2007-07-06 23:09:18 +00:00
Bill Wendling a69300375b Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Fix for C++ casting operators failing during parsing. Deriving the C++ cast
  expressions from CastExpr was the wrong way to go. Its constructor creates
  null QualTypes in one of its constructors. This doesn't work well with how
  the C++ casting expression class wanted to do things. Derive just from Expr
  instead.

llvm-svn: 39714
2007-06-29 18:21:34 +00:00
Chris Lattner 47c247e7bf add codegen support for <<= and >>=.
llvm-svn: 39713
2007-06-29 17:26:27 +00:00
Chris Lattner b25a94383a Implement the rest of the compound assignment operators, except shifts.
llvm-svn: 39712
2007-06-29 17:03:06 +00:00
Chris Lattner cd215f00ee refactor some code, implement -=
llvm-svn: 39711
2007-06-29 16:52:55 +00:00
Chris Lattner 9369a563b4 Rename ArithAssignBinaryOperator -> CompoundAssignOperator, implement
codegen support for +=.

llvm-svn: 39710
2007-06-29 16:31:29 +00:00
Bill Wendling 772996ab44 Submitted by: Bill Wendling
- The && at the end was causing this to fail. Removed.

llvm-svn: 39709
2007-06-29 09:54:25 +00:00
Chris Lattner bdf3f73eeb fix this test to work with the checker.
llvm-svn: 39708
2007-06-28 05:49:50 +00:00
Chris Lattner 11f49640ef Clients should only get read-only access to diagnostic info.
llvm-svn: 39707
2007-06-28 05:18:35 +00:00
Chris Lattner 318a9d7663 pick more logical names for routines.
llvm-svn: 39706
2007-06-28 05:17:33 +00:00
Chris Lattner 0d21046a7e Remove dead code.
llvm-svn: 39705
2007-06-28 05:10:07 +00:00
Chris Lattner 23e6353835 Eliminate almost all of the redundancy Bill introduced.
llvm-svn: 39704
2007-06-28 04:54:17 +00:00
Chris Lattner 08f0e0a001 add an accessor
llvm-svn: 39703
2007-06-28 04:53:50 +00:00
Chris Lattner ea035b5fb8 remove diagchecker.h, add more missing files.
llvm-svn: 39702
2007-06-28 04:42:53 +00:00
Chris Lattner af74985d71 Add a hack to fix a really subtle memory lifetime bug Bill introduced with his
recent changes.  carbon.h now preprocesses just fine.

llvm-svn: 39701
2007-06-28 04:10:04 +00:00
Chris Lattner 256c21b78a Record the intermediate computation type for compound assignments in the AST.
For example, for:

int test(short S, long L) {
  return S /= L;
}

record that the division is done as a long, even though the result type is
short.

llvm-svn: 39700
2007-06-28 03:53:10 +00:00
Bill Wendling 81217d6ff6 Submitted by: Bill Wendling
Update with -parse-ast-check.

llvm-svn: 39699
2007-06-28 00:54:14 +00:00
Bill Wendling f476d025f8 Submitted by: Bill Wendling
Missing support for LLVM casting operators.

llvm-svn: 39698
2007-06-28 00:46:14 +00:00
Bill Wendling 5c9dde08e7 Submitted by: Bill Wendling
Small cleanup. No need to assign to a variable before returning.

llvm-svn: 39697
2007-06-28 00:45:30 +00:00
Bill Wendling 52b4b73442 Submitted by: Bill Wendling
Fixed checking to coincide with the correct lines.

llvm-svn: 39696
2007-06-27 18:18:03 +00:00
Bill Wendling 764b90ad4e Submitted by: Bill Wendling
- Revert use of -parse-ast-check.

llvm-svn: 39695
2007-06-27 18:13:04 +00:00
Chris Lattner 69e70e506a fix codegen of void return functions
llvm-svn: 39694
2007-06-27 18:10:00 +00:00
Chris Lattner c8c3dadaa0 fix codegen of void-returning functions
llvm-svn: 39693
2007-06-27 18:08:49 +00:00
Chris Lattner c2d8163bcd tersify output
llvm-svn: 39692
2007-06-27 17:26:23 +00:00
Chris Lattner 76148a9ded add diag checker to xcode proj
llvm-svn: 39691
2007-06-27 17:25:13 +00:00
Chris Lattner a092b149bf rename LLVMDiagChecker.* -> DiagChecker.*
llvm-svn: 39690
2007-06-27 17:24:55 +00:00
Bill Wendling a5b3bb11df Submitted by: Bill Wendling
- 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
2007-06-27 07:43:27 +00:00
Bill Wendling 87e46687d9 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

Split up lines to have only one expected output per line. Restored some
checks.

llvm-svn: 39688
2007-06-27 07:31:17 +00:00
Bill Wendling fdddfc115e Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Reverted some checks because they're checking the preprocessor output.

llvm-svn: 39687
2007-06-27 07:26:41 +00:00
Bill Wendling 52b0a4e84e Submitted by: Bill Wendling
Removed unnecessary typedef.

llvm-svn: 39686
2007-06-27 07:24:11 +00:00
Chris Lattner 9b3b9a1922 add a method to get more precise arrow positioning for expressions. Rename
some ivars to more obvious names, eliminating some comments.

llvm-svn: 39685
2007-06-27 06:08:24 +00:00
Chris Lattner a44d116835 implement the rest of Expr::hasLocalSideEffect
llvm-svn: 39684
2007-06-27 05:58:59 +00:00
Chris Lattner c4c8e2546b New testcase for unused expression analysis
llvm-svn: 39683
2007-06-27 05:58:33 +00:00
Chris Lattner 1ec5f563c7 First cut at warning about expressions whose results are ignored. For example,
this produces:

warn.c:4:3: warning: expression result unused
  X == Y;
  ^~~~~~
warn.c:5:3: warning: expression result unused
  (void)X;
  ^~~~~~~
warn.c:11:3: warning: expression result unused
  A == foo(1, 2);
  ^~~~~~~~~~~~~~
warn.c:13:3: warning: expression result unused
  foo(1,2)+foo(4,3);
  ^~~~~~~~~~~~~~~~~

llvm-svn: 39682
2007-06-27 05:38:08 +00:00
Bill Wendling eb2def66be Submitted by: Bill Wendling
- Converted to use the -parse-ast-check flag.

llvm-svn: 39681
2007-06-27 04:30:12 +00:00
Bill Wendling ff1d2c81ba Submitted by: Bill Wendling
- Convert to using the -parse-ast-check method to check warnings and
  errors.

llvm-svn: 39680
2007-06-27 04:07:44 +00:00
Bill Wendling 97d4146c5a Submitted by: Bill Wendling
- Shouldn't increment the iterator but a copy of it.

llvm-svn: 39679
2007-06-27 04:06:59 +00:00
Bill Wendling 469211a295 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

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

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

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

llvm-svn: 39678
2007-06-27 03:19:45 +00:00
Chris Lattner cd68f64551 Start bringing the exprstmt hook back.
llvm-svn: 39677
2007-06-27 01:06:29 +00:00
Bill Wendling aec64c35f1 Submitted by: Bill Wendling
- Separate out the AST streamers from the clang.cpp file into their very
  own special files.

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

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

llvm-svn: 39675
2007-06-22 22:43:15 +00:00
Chris Lattner 54fb19efaa implement support for struct and complex returns.
llvm-svn: 39674
2007-06-22 22:02:34 +00:00
Chris Lattner e9a6453ded add some infrastructure for codegen'ing complex numbers. implement addition
of complex.  We now produce optimal code for:

void test(_Complex float *Y) {
  *Y = *Y + *Y;
}

$ clang -emit-llvm cg.c | llvm-as | opt -std-compile-opts | llc -march=x86-64
...
_test:
        movss (%rdi), %xmm0
        addss %xmm0, %xmm0
        movss 4(%rdi), %xmm1
        movss %xmm0, (%rdi)
        addss %xmm1, %xmm1
        movss %xmm1, 4(%rdi)
        ret

llvm-svn: 39673
2007-06-22 21:44:33 +00:00
Chris Lattner c6395936ae Split complex types out from being members of BuiltinType to being their own
types.

llvm-svn: 39672
2007-06-22 20:56:16 +00:00
Chris Lattner f033c147c9 remove location tracking for target info
llvm-svn: 39671
2007-06-22 19:05:19 +00:00
Chris Lattner 0fb8465981 Don't forget to set this
llvm-svn: 39670
2007-06-22 18:57:44 +00:00
Chris Lattner 09153c0a8c Build enough support for aggregates to be able to compile this:
void test(int A, _Complex float Y) {
  _Complex float X;
  X = X;

}

llvm-svn: 39669
2007-06-22 18:48:09 +00:00
Chris Lattner 3e3a1e9cda implement lowering of complex types
llvm-svn: 39668
2007-06-22 18:15:26 +00:00
Chris Lattner f39b03d98b fix naming of aggregate arguments.
llvm-svn: 39667
2007-06-22 18:15:16 +00:00
Chris Lattner 1fde0b345b implement codegen of the relational operations
One major FIXME though.

llvm-svn: 39666
2007-06-20 18:30:55 +00:00
Chris Lattner 273c63d450 Implement the equality operators for simple types
llvm-svn: 39665
2007-06-20 18:02:30 +00:00
Chris Lattner e1e93a5e5d assert, don't crash, on int[]
llvm-svn: 39664
2007-06-20 17:12:11 +00:00
Chris Lattner b6984c4854 Hook up global function and variable handling. We can now compile:
int X, bar(int,int,int);
short Y;

double foo() {
  return bar(X, Y, 3);
}

into:

@X = external global i32                ; <i32*> [#uses=1]
@Y = external global i16                ; <i16*> [#uses=1]

define double @foo() {
entry:
        %tmp = load i32* @X             ; <i32> [#uses=1]
        %tmp1 = load i16* @Y            ; <i16> [#uses=1]
        %promote = sext i16 %tmp1 to i32                ; <i32> [#uses=1]
        %call = tail call i32 @bar( i32 %tmp, i32 %promote, i32 3 )             ; <i32> [#uses=1]
        %conv = sitofp i32 %call to double              ; <double> [#uses=1]
        ret double %conv
}

declare i32 @bar(i32, i32, i32)

llvm-svn: 39663
2007-06-20 04:44:43 +00:00
Chris Lattner b3fef07a30 add new files to xcode project
llvm-svn: 39662
2007-06-16 00:17:33 +00:00
Chris Lattner 2ccb73bc8b Refactor CodeGenTypes out to CodeGenModule so it can be used for functions
and globals.

llvm-svn: 39661
2007-06-16 00:16:26 +00:00
Chris Lattner 2052bc8107 Split type analysis out to its own file, now the integer constant expr evaluation
is ready.

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

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

llvm-svn: 39659
2007-06-15 23:05:46 +00:00
Chris Lattner 2b228c95aa implement codegen of calls. We can now compile:
double foo( int (*FP)(int, int, int)) {
  return FP(1, 2, 3);
}

to:

define double @foo(i32 (i32, i32, i32)* %FP) {
entry:
        %call = tail call i32 %FP( i32 1, i32 2, i32 3 )
        %conv = sitofp i32 %call to double
        ret double %conv
}

llvm-svn: 39658
2007-06-15 21:34:29 +00:00
Bill Wendling 52d85bdd2b Submitted by: Bill Wendling
Reviewed by: Chris Lattner

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

llvm-svn: 39657
2007-06-15 21:20:00 +00:00
Chris Lattner d760e468aa Don't generate code for prototypes
llvm-svn: 39656
2007-06-15 21:16:23 +00:00
Chris Lattner b48238188e Fix a nasty bug which caused infinite recursion
llvm-svn: 39655
2007-06-15 21:04:38 +00:00
Steve Naroff 75c1723b3c Bug #:
Submitted by:
Reviewed by:
Fix CheckRelationalOperands/CheckEqualityOperands to deal with null pointer
constants. The new logic also deals (more) correctly for non-pointer/integer
operands.

llvm-svn: 39654
2007-06-13 21:41:08 +00:00
Chris Lattner cf98efa73b Implement implicit conversions in return stmts.
llvm-svn: 39653
2007-06-13 20:50:31 +00:00
Chris Lattner 53621a535d Implement support for formal arguments. We can now compile this:
int test(int X, short Y, float Z) {
  return (int)(X*Y+Z);
}

to:

define i32 @test(i32 %X, i16 %Y, float %Z) {
entry:
        %promote = sext i16 %Y to i32           ; <i32> [#uses=1]
        %mul = mul i32 %promote, %X             ; <i32> [#uses=1]
        %promote3 = sitofp i32 %mul to float            ; <float> [#uses=1]
        %add = add float %promote3, %Z          ; <float> [#uses=1]
        %conv = fptosi float %add to i32                ; <i32> [#uses=1]
        ret i32 %conv
}

with:

$ clang -emit-llvm t.c | llvm-as | opt -std-compile-opts | llvm-dis

llvm-svn: 39652
2007-06-13 20:44:40 +00:00
Chris Lattner 23cff88741 Update the xcode project for bill
llvm-svn: 39651
2007-06-13 20:14:12 +00:00
Bill Wendling 478b88638f Submitted by: Bill Wendling
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
2007-06-13 17:45:37 +00:00
Steve Naroff d6fbee81df Bug #:
Submitted by:
Reviewed by:
Fixed typechecking bugs wrt UsualUnaryConversions. Includes two distinct fixes:

#1: Call UsualUnaryConversions in CheckRelationalOperands/CheckEqualityOperands.
#2: UsualArithmeticConversions arguments are now output parameters. This insures
the implicit conversion is seen by clients (and fixes bugs in CheckAdditionOperands
and CheckSubtractionOperands when doing pointer arithmetic).
~

llvm-svn: 39649
2007-06-13 15:42:33 +00:00
Chris Lattner c0a38dd38f Pretty print if/else/elseif chains nicer, like this:
void printutf8(unsigned int X) {
  if (X <= 127)
    printf("%c", (char)X);
  else if (X <= 2047)
    printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
  else if (X <= 65535)
    printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
  else
    printf("UNKNOWN %d\n", X);

instead of:

  if (X <= 127)
    printf("%c", (char)X);
  else
    if (X <= 2047)
      printf("%d %d ", 128 + 64 + (X >> 6), 128 + (X & ((1 << 6) - 1)));
    else
      if (X <= 65535)
        printf("%c%c%c", 128 + 64 + 32 + (X >> 12), 128 + ((X >> 6) & 63), 128 + (X & 63));
      else
        printf("UNKNOWN %d\n", X);

llvm-svn: 39648
2007-06-11 22:26:23 +00:00
Chris Lattner d4a20ad752 Wording fix for a diagnostic, suggested by bill
llvm-svn: 39647
2007-06-11 20:54:56 +00:00
Chris Lattner f99b3f5ec2 Emit codegen of enum literals.
llvm-svn: 39646
2007-06-11 03:52:52 +00:00
Chris Lattner 9fba02845b Enums are integer constant exprs, return their values.
llvm-svn: 39645
2007-06-11 03:47:05 +00:00
Chris Lattner 4ef40013d7 Implement capturing of enum values and chaining of enums together.
llvm-svn: 39644
2007-06-11 01:28:17 +00:00
Steve Naroff a8fd973aa0 Bug #:
Submitted by:
Reviewed by:
Implement semantic analysis for vector_size attribute!
We now produce the following diagnostics...

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang vector.c
vector.c:2:29: error: attribute requires precisely 1 argument
typedef int __attribute__(( vector_size )) tVecp;
                            ^
vector.c:7:32: error: attribute requires precisely 1 argument
extern int foo __attribute__(( vector_size ));
                               ^
vector.c:8:34: error: attribute requires precisely 1 argument
extern float bar __attribute__(( vector_size(16,18) ));
                                 ^
vector.c:11:34: error: vector_size requires integer constant (attribute ignored)
extern char foo2 __attribute__(( vector_size(16.2) ));
                                 ^           ~~~~
vector.c:21:47: error: invalid vector type 'struct s'
struct s { int a; } structVar __attribute__(( vector_size(16) ));

llvm-svn: 39643
2007-06-11 00:35:03 +00:00
Chris Lattner 843c592e28 GCC accepts code like this as an extension:
static int seminal(from, to)
{
}

llvm-svn: 39642
2007-06-10 23:40:34 +00:00
Bill Wendling 314ae547a1 Submitted by: Bill Wendling
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
2007-06-10 04:13:42 +00:00
Steve Naroff 0f05a7ae7a Bug #:
Submitted by:
Reviewed by:
Changed the name of DeclSpec.AddAttribute and Declarator.AddAttribute to
AddAttributes(). Also added some (much needed) comments. While documenting,
realized I could simplify & tighten up Declarator.AddAttributes...

llvm-svn: 39640
2007-06-09 23:38:17 +00:00
Steve Naroff 5b6afadf81 Bug #:
Submitted by:
Reviewed by:
Add initialization and memory management for AttributeList.
Added a big FIXME comment for handling expressions (which are currently leaked).

llvm-svn: 39639
2007-06-09 14:13:39 +00:00
Chris Lattner 3f4b6e3623 Fix lexing octal escapes like:
void foo() {
"\0";
}

llvm-svn: 39638
2007-06-09 06:20:47 +00:00
Chris Lattner b2dd241b15 fix a crash parsing spass
llvm-svn: 39637
2007-06-09 06:16:32 +00:00
Chris Lattner ff591e24eb Don't warn about escaped newlines in // comments if the next line is also
a // comment, this reduces noise in the llvm testsuite.

llvm-svn: 39636
2007-06-09 06:07:22 +00:00
Chris Lattner 736ed5dfb8 accept __extension__, update todo list.
llvm-svn: 39635
2007-06-09 05:59:07 +00:00
Chris Lattner 6d9b49ae64 add another example
llvm-svn: 39634
2007-06-09 05:56:19 +00:00
Chris Lattner 0c7e82de07 Accept horrible code like this:
2005-10-18-VariableSizedElementCrash.c:5:41: warning: expected ';' at end of declaration list
  struct bar {foo f1; int f2:3; int f3:4} *p = (struct bar *) pi;
                                        ^

llvm-svn: 39633
2007-06-09 05:54:40 +00:00
Chris Lattner 36e46a219b Add support for a little extension. ISO C does not allow extra ;'s in structs,
e.g.:

struct A {
  ;
  int X;;
  const;
};

llvm-svn: 39632
2007-06-09 05:49:55 +00:00
Steve Naroff 9507c79698 Bug #:
Submitted by:
Reviewed by:
Incorporate some feedback from Chris.
Fixed a crasher, added an assert.

llvm-svn: 39631
2007-06-09 05:31:51 +00:00
Steve Naroff 6d26a892d4 Bug #:
Submitted by:
Reviewed by:
Move Attr.h to the correct group in the Xcode project file...

llvm-svn: 39630
2007-06-09 03:59:22 +00:00
Steve Naroff 06f0f8c414 Bug #:
Submitted by:
Reviewed by:
Lot's of attribute scaffolding.
Modernized ParseArraySubscriptExpr...call DefaultFunctionArrayConversion (which
simplified the logic considerably) and upgrade Diags to use the range support.

llvm-svn: 39629
2007-06-09 03:47:54 +00:00
Steve Naroff b309644a35 Bug #:
Submitted by:
Reviewed by:
Lot's of attribute scaffolding.
Modernized ParseArraySubscriptExpr...call DefaultFunctionArrayConversion (which
simplified the logic considerably) and upgrade Diags to use the range support.

llvm-svn: 39628
2007-06-09 03:47:53 +00:00
Steve Naroff 29ca72ae02 Bug #:
Submitted by:
Reviewed by:
Add new file AttributeList.h

llvm-svn: 39627
2007-06-09 03:40:25 +00:00
Steve Naroff b8371e1e6a Bug #:
Submitted by:
Reviewed by:
Add AttributeList.cpp (for "raw" attributes).

llvm-svn: 39626
2007-06-09 03:39:29 +00:00
Chris Lattner 45bb914249 Convert argument types over, which works for trivial scalars.
llvm-svn: 39625
2007-06-09 02:28:57 +00:00
Chris Lattner 1ad38f8fee codegen all declarators in a declstmt, allowing us to successfully codegen
stuff like:

void test() {
  int *X, Y, *Z[14];

  X[Y] = 4;
}

llvm-svn: 39624
2007-06-09 01:20:56 +00:00
Chris Lattner 776fac8703 Finally break down and chain together decls that are defined with common declspecs,
like: int X, Y, Z;

This is required for the code gen to get to all of the declarations in a
DeclStmt, and should simplify some other code.

llvm-svn: 39623
2007-06-09 00:53:06 +00:00
Chris Lattner d9d2fb1420 Implement array subscripts for non-vla types.
llvm-svn: 39622
2007-06-08 23:31:14 +00:00
Chris Lattner de12ae2fd7 Add support for binary literals:
http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html#Binary-constants

llvm-svn: 39621
2007-06-08 22:42:30 +00:00
Chris Lattner 8655428238 factor casts together, add a case for __extension__
llvm-svn: 39620
2007-06-08 22:32:33 +00:00
Chris Lattner d0f76515f7 add missing case
llvm-svn: 39619
2007-06-08 22:16:53 +00:00
Chris Lattner 901ae1faf2 fix assertion on out-of-range shift
llvm-svn: 39618
2007-06-08 21:54:26 +00:00
Chris Lattner 4cd73fd380 Fix bugs in isIntegerConstantExpr handling character and enum literals
llvm-svn: 39617
2007-06-08 21:51:02 +00:00
Bill Wendling 344b92e993 Submitted by: Bill Wendling
- Say! why don't we increment the NumDiagnostics variable too?

llvm-svn: 39616
2007-06-08 19:21:50 +00:00
Bill Wendling da0c8a9641 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

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

llvm-svn: 39615
2007-06-08 19:17:38 +00:00
Chris Lattner 7cf04d1653 we correctly reject array of void now
llvm-svn: 39614
2007-06-08 18:15:09 +00:00
Chris Lattner 5a1a0250f8 this testcase has errors, we expect clang to reject it
llvm-svn: 39613
2007-06-08 18:14:27 +00:00
Chris Lattner 7a89360402 This testcase bus errors because semantics analysis of these operators isn't implemented.
llvm-svn: 39612
2007-06-08 18:13:24 +00:00
Chris Lattner c84413e0a8 Diagnostics coming from a memory buffer (e.g. pragmas) don't have a
corresponding file buffer, don't dereference null pointers.  This
fixes a regression on test/Preprocessor/_Pragma-syshdr.c

llvm-svn: 39611
2007-06-08 18:11:33 +00:00
Chris Lattner 1abbd417be implement a fixme, fixing test/Sema/i-c-e1.c
llvm-svn: 39610
2007-06-08 17:58:43 +00:00
Chris Lattner 43312241ea new testcase
llvm-svn: 39609
2007-06-08 17:58:14 +00:00
Chris Lattner e9a7da1d55 Make make check work again.
llvm-svn: 39608
2007-06-08 17:57:13 +00:00
Chris Lattner e8b2724017 Fix a bug steve noticed where we warned that __attribute is an extension,
but where we didn't warn about __attribute__.

llvm-svn: 39607
2007-06-08 17:27:55 +00:00
Chris Lattner 2c1720681f add a new text file for low-prio QOI todos
llvm-svn: 39606
2007-06-08 17:15:31 +00:00
Chris Lattner 328fa5c913 Emit better diagnostics for out of range digits:
diag.c:1:9: error: invalid digit '8' in octal constant
int x = 000080;
        ^
diag.c:2:9: error: invalid digit 'A' in decimal constant
int z = 1000080ABC;
        ^

instead of:

diag.c:1:9: error: invalid suffix '80' on integer constant
int x = 000080;
        ^
diag.c:2:9: error: invalid suffix 'ABC' on integer constant
int z = 1000080ABC;
        ^

llvm-svn: 39605
2007-06-08 17:12:06 +00:00
Bill Wendling c2b867ac4f Submitted by: Bill Wendling
- Renamed file guard.

llvm-svn: 39604
2007-06-07 18:58:07 +00:00
Bill Wendling 37b1ddecf6 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

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

llvm-svn: 39603
2007-06-07 09:34:54 +00:00
Steve Naroff 98d153c730 Bug #:
Submitted by:
Reviewed by:

Fixed a bug in the parser's handling of attributes on pointer declarators.

For example, the following code was producing a syntax error...

int *__attribute(()) foo;

attrib.c:10:25: error: expected identifier or '('
int *__attribute(()) foo;
                        ^
Changed Parser::ParseTypeQualifierListOpt to not consume the token following
an attribute declaration.

Also added LexerToken::getName() convenience method...useful when tracking
down errors like this.

llvm-svn: 39602
2007-06-06 23:19:11 +00:00
Steve Naroff 98cf3e95ce Bug #:
Submitted by:
Reviewed by:

The following code illustrates a bug in the semantic analysis for assignments:

int func() {
  int *P;
  char *x;
  P = x; // type of this assignment expression should be "int *", NOT "char *".
}

While the type checking/diagnostics are correct, the type of the assignment
expression is incorrect (which shows up during code gen).  With the fix,
the llvm code looks correct...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cast.c -emit-llvm
cast.c:4:5: warning: incompatible pointer types assigning 'char *' to 'int *'
  P = x; // type of assignment expression is "int *", NOT "char *".
  ~ ^ ~
; ModuleID = 'foo'

define i32 @func() {
entry:
        %P = alloca i32*                ; <i32**> [#uses=1]
        %x = alloca i8*         ; <i8**> [#uses=1]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
        %tmp = load i8** %x             ; <i8*> [#uses=1]
        %conv = bitcast i8* %tmp to i32*                ; <i32*> [#uses=1]
        store i32* %conv, i32** %P
        ret i32 undef
}

Even though the fix was simple, I decided to rename/refactor the surrounding code
to make a clearer distinction between constraint checking and conversion.

- Renamed AssignmentConversionResult -> AssignmentCheckResult.
- Renamed UsualAssignmentConversions -> CheckAssignmentConstraints.
- Changed the return type of CheckAssignmentConstraints and CheckPointerTypesForAssignment
from QualType -> AssignmentCheckResult. These routines no longer take a reference to the result (obviously).
- Changed CheckAssignmentOperands to return the correct type (with spec annotations).

llvm-svn: 39601
2007-06-06 18:38:38 +00:00
Chris Lattner 2e550fea6a When parsing an expr in stmt context, make sure to consume the semicolon
after the expr along with the expr.  If we don't do this, the semicolon
gets parsed as a nullstmt, which makes the generated AST very strange.

llvm-svn: 39600
2007-06-06 05:26:32 +00:00
Chris Lattner 3d01e4eacb On bogus code like this:
int *P2;
  P2(1, 2, 3);

  register short X;
  X();

emit:

ds.c:10:3: error: called object is not a function or function pointer
  P2(1, 2, 3);
  ^~~~~~~~~~~
ds.c:13:3: error: called object is not a function or function pointer
  X();
  ^~~

instead of aborting.

llvm-svn: 39599
2007-06-06 05:14:05 +00:00
Chris Lattner 3343f81a25 Fix semantic analysis of calls on stuff like:
int func() {
 int (*FP)();
 FP();
 (*****FP)();
}

llvm-svn: 39598
2007-06-06 05:05:41 +00:00
Chris Lattner 4347e369b4 implement codegen of string literals.
llvm-svn: 39597
2007-06-06 04:54:52 +00:00
Chris Lattner 83b484b3be implement the real int/fp conversions
llvm-svn: 39596
2007-06-06 04:39:08 +00:00
Chris Lattner cf106ab42a implement support for casts to/from pointers.
llvm-svn: 39595
2007-06-06 04:05:39 +00:00
Chris Lattner 6563712933 xcode randomly changed the project, who knows what this does
llvm-svn: 39594
2007-06-05 20:53:44 +00:00
Chris Lattner 8394d795c3 implement codegen of a bunch more loop constructs and most expressions
llvm-svn: 39593
2007-06-05 20:53:16 +00:00
Chris Lattner fdc195af7e Various improvements to the tree printer, including printing decls in for stmts prettier etc
llvm-svn: 39592
2007-06-05 20:52:47 +00:00
Chris Lattner 1d411a826e add some fixme's for incorrect sema
llvm-svn: 39591
2007-06-05 20:52:21 +00:00
Chris Lattner 6d26a03d12 rename forstmt accessors, add const accessors
llvm-svn: 39590
2007-06-05 20:51:37 +00:00
Steve Naroff 6d9de3dd74 Bug #:
Submitted by:
Reviewed by:
Touch up a couple comments (one was incorrect/out-of-date).

llvm-svn: 39589
2007-06-05 19:14:28 +00:00
Chris Lattner 66cfa8ad81 add another fixme
llvm-svn: 39588
2007-06-05 06:40:31 +00:00
Chris Lattner 6046e008aa Rename Sema::isConstantArrayType -> VerifyConstantArrayType. Make sure to
check canonical types in a few places.  Tighten up VerifyConstantArrayType
to diagnose more errors, now that we can evaluate i-c-e's.  Add some fixmes
about poor diagnostics.

We now correctly typecheck this example:

void s(void) {
  typedef int a[(int) +1.0];
  static a b;    // invalid, static VLA

  static int c[(int) +1.0];  // invalid, static VLA
}

void t(void) {
  typedef int a[(int)1.0];
  static a b;    // valid, constant size
}

void u() {
  static int X[-1];
  static int Y[0];
}

producing:

static-vla.c:3:12: error: variable length array declared outside of any function
  static a b;    // invalid, static VLA
           ^
static-vla.c:5:14: error: variable length array declared outside of any function
  static int c[(int) +1.0];  // invalid, static VLA
             ^ ~~~~~~~~~~
static-vla.c:15:14: error: array size is negative
  static int X[-1];
             ^ ~~
static-vla.c:16:14: warning: zero size arrays are an extension
  static int Y[0];
             ^ ~

llvm-svn: 39587
2007-06-05 06:39:23 +00:00
Chris Lattner 3e4dabe4bf simplify Type::isConstantSizeType based on knowledge that it is only called
on complete types.

llvm-svn: 39586
2007-06-05 06:02:48 +00:00