Commit Graph

1399 Commits

Author SHA1 Message Date
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
Chris Lattner e0da5dc8f2 Change Expr::isIntegerConstantExpr in two ways:
1. Compute and return the value of the i-c-e if the expression is one.
  2. Use this computation to correctly track whether subexprs are being
     evaluated, and use this to guide diagnostics appropriately.

This allows us to correctly handle all the cases in:

void bar() {
  int foo();
  switch (1) {
  case 1 ? 0 : foo():    // bad
  case 0 ? 0 : foo():    // bad

  case 0 ? 1/0 : 14 :  // ok
  case 1 ? 1/0 : 14 :  // bad
    ;
  }

  switch (1) {
  case 1 ? 2: (2, 3): // ok
  case 0 ? 2: (2, 3): // invalid comma.
    ;
  }
}

This code has numerous todo items.  Specifically, we need to:
  1. Pass in target info, so we know the size of the integers we are producing.
  2. Model type sizes and alignments correctly, so we can eval sizeof/alignof
  3. Handle promotions (need to talk to steve about this).
  4. Return an enum that can be used to better diagnose problems with i-c-e's.
     instead of just saying "this isn't valid" we should be able to say why.
  5. Various other miscellanea, like handling enums and character literals
     properly.

llvm-svn: 39585
2007-06-05 05:58:31 +00:00
Chris Lattner 1f4479e770 Nothing currently wants to know if something is a constantexpr. Simplify
isConstantExpr into just isIntegerConstantExpr in preparation for other
changes.

llvm-svn: 39584
2007-06-05 04:15:44 +00:00
Chris Lattner ab0b2df469 fix two checks that should be integer-constant-exprs not just c-e's.
llvm-svn: 39583
2007-06-05 04:12:06 +00:00
Chris Lattner 946aa31f02 implement codegen of while stmts and lvalue evaluation of paren exprs :)
llvm-svn: 39582
2007-06-05 03:59:43 +00:00
Steve Naroff 71b59a9a29 Bug #:
Submitted by:
Reviewed by:
Fixed an "impurity" in the typechecking code (to more closely model the
C99 spec)...

- Added function Sema::DefaultFunctionArrayConversion(). This is called
by UsualUnaryConversions(). It is also called from several contexts that
don't call for integer promotions (logical negation for expressions, and
while/if/do/for conditions in statements). It is also used in
UsualAssignmentConversions (which is cleaner than the check I was using
before).

- Changed the name from UsualUnaryConversion->UsualUnaryConversions.

- Added comments to the header.

Since several contexts don't call for integer
promotions,

llvm-svn: 39581
2007-06-04 22:22:31 +00:00
Steve Naroff c27f89ebb3 Bug #:
Submitted by:
Reviewed by:
Apply UsualUnaryConversion() to statement conditions that expect scalars.
UsualUnaryConversion() converts function/arrays to pointers.

This fixes the following...

int func() {
  int A[10];
  while (A) {
  }
  if (A) ;
  for (; A; ) ;
}

llvm-svn: 39580
2007-06-03 18:23:48 +00:00
Bill Wendling cbf4709c03 Add const/volatile badness
llvm-svn: 39579
2007-06-03 09:02:28 +00:00
Chris Lattner 64453e63ea fix a predicate I just broke
llvm-svn: 39578
2007-06-03 07:27:29 +00:00
Chris Lattner b16f455e8c Type::isSignedInteger() and isUnsignedInteger() did not properly account for
'char', which varies based on the target.

Instead of spreading target knowledge throughout the compiler, bifurcate char
into Char_S and Char_U, and have ASTContext create the right one based on the
target, when it starts up.

llvm-svn: 39577
2007-06-03 07:25:34 +00:00
Chris Lattner cf25024828 Implement EmitUsualArithmeticConversions, so we can add shorts to floats and
ints to long long etc.  For int to longlong, we now get:

        %tmp = load i64* %F             ; <i64> [#uses=1]
        %tmp1 = load i32* %D            ; <i32> [#uses=1]
        %promote = sext i32 %tmp1 to i64                ; <i64> [#uses=1]
        %tmp2 = add i64 %tmp, %promote          ; <i64> [#uses=0]

llvm-svn: 39576
2007-06-03 02:02:44 +00:00
Chris Lattner 35e287bed1 eliminate unneeded cast
llvm-svn: 39575
2007-06-03 01:44:43 +00:00
Chris Lattner 0c46c5d55a Fix a fixme, produce diagnostics like this:
ds.c:11:16: error: case label does not reduce to an integer constant
  case 0 ? 0 : foo():
       ~~~~~~~~^~~~~

llvm-svn: 39574
2007-06-02 23:53:17 +00:00
Bill Wendling fa0c8f945f Submitted by: Bill Wendling
- Small error fix.

llvm-svn: 39573
2007-06-02 23:36:05 +00:00
Bill Wendling 7d4562b42b Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Add a reference decl type.

llvm-svn: 39572
2007-06-02 23:34:45 +00:00
Bill Wendling d8236f166f Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Diagnostic messages for invalid reference usage.

llvm-svn: 39571
2007-06-02 23:32:47 +00:00
Bill Wendling a0057196cb Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Method declaration.

llvm-svn: 39570
2007-06-02 23:31:25 +00:00
Bill Wendling 8c06ef8851 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Disallow references to references, pointers to references, or arrays of
  references.

llvm-svn: 39569
2007-06-02 23:30:50 +00:00
Bill Wendling db4f06ed2c Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- If the LHS and/or RHS is a reference, then see if they're compatible.
  If so, the type is that of the LHS.

llvm-svn: 39568
2007-06-02 23:29:59 +00:00
Bill Wendling 93efb22993 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Update the parsing of references. We allow "restrict" but not "const"
  or "volatile".

llvm-svn: 39567
2007-06-02 23:28:54 +00:00
Bill Wendling 5d107662f0 Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Added a method to determine if two types, where at least one is a
  reference, are compatible. That is you can assign the RHS to the LHS.

llvm-svn: 39566
2007-06-02 23:27:35 +00:00
Chris Lattner c18f9d1aed Change EmitUsualArithmeticConversions to use EmitExprWithUsualUnaryConversions.
This allows us to compile:

  register short X;
  {
    int Y;
    return 1+X+Y;

into:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %promote = sext i16 %tmp to i32         ; <i32> [#uses=1]
        %tmp1 = add i32 1, %promote             ; <i32> [#uses=1]
        %tmp2 = load i32* %Y            ; <i32> [#uses=1]
        %tmp3 = add i32 %tmp1, %tmp2            ; <i32> [#uses=1]
        ret i32 %tmp3

Look at the amazing sign extension, so much happier than an assertion failure. :)

llvm-svn: 39565
2007-06-02 22:51:30 +00:00
Chris Lattner 6db1fb845a implement a first hack at codegen'ing the usual unary conversions.
This allows us to compile:

int func() {
  int A[10];
  if (!A) {

to:

define i32 @func() {
entry:
        %A = alloca [10 x i32]          ; <[10 x i32]*> [#uses=1]
        %arraydecay = getelementptr [10 x i32]* %A, i32 0, i32 0                ; <i32*> [#uses=1]
        %tobool = icmp ne i32* %arraydecay, null                ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        br i1 %lnot, label %ifthen, label %ifend

-Chris

llvm-svn: 39564
2007-06-02 22:49:07 +00:00
Chris Lattner 226d419e21 trivial simplification
llvm-svn: 39563
2007-06-02 22:47:37 +00:00
Chris Lattner ea3c20b9eb When a function decays into its address, ensure the result type keeps any
typedef information associated with the input.

llvm-svn: 39562
2007-06-02 22:47:04 +00:00
Chris Lattner 2b4e21ac3f Implement translation of pointer, reference and simple array types. We now
compile:

void foo() {
  int A[10];
  int *P;

into:

entry:
        %A = alloca [10 x i32]          ; <[10 x i32]*> [#uses=0]
        %P = alloca i32*                ; <i32**> [#uses=0]

llvm-svn: 39561
2007-06-02 19:52:24 +00:00
Chris Lattner a45c5af87b Implement a trivial optimization to reduce the number of compares emitted.
For:

  register short X;
  if (!X) {

We now produce:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        br i1 %lnot, label %ifthen, label %ifend

instead of:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        %lnot.ext = zext i1 %lnot to i32                ; <i32> [#uses=1]
        %tobool1 = icmp ne i32 %lnot.ext, 0             ; <i1> [#uses=1]
        br i1 %tobool1, label %ifthen, label %ifend

llvm-svn: 39560
2007-06-02 19:47:04 +00:00
Chris Lattner f0106d2578 Refactor EvaluateScalarValueToBool out of if statement emission, so it can
be shared.

Implement infrastructure for unary operator emission.

Implement basic logical not support.  We now compile:

  register short X;

  if (!X) {

into:

        %tmp = load i16* %X             ; <i16> [#uses=1]
        %tobool = icmp ne i16 %tmp, 0           ; <i1> [#uses=1]
        %lnot = xor i1 %tobool, true            ; <i1> [#uses=1]
        zext i1 %lnot to i32            ; <i32>:0 [#uses=1]
        %tobool1 = icmp ne i32 %0, 0            ; <i1> [#uses=1]
        br i1 %tobool1, label %ifthen, label %ifend

llvm-svn: 39559
2007-06-02 19:33:17 +00:00
Chris Lattner be31ed8e88 Correct the type of logical not.
llvm-svn: 39558
2007-06-02 19:11:33 +00:00
Bill Wendling d6de65740d Submitted by: Bill Wendling
- Added C99 reference to why "auto" and "register" cannot be used as a
  storage class specifier for file scoped variable declarations.

llvm-svn: 39557
2007-06-02 09:40:07 +00:00
Chris Lattner b4522b4dec Pretty print storage classes for vardecls.
llvm-svn: 39556
2007-06-02 05:27:01 +00:00
Chris Lattner d7f58867e5 Implement scaffolding for lvalues. Implement block vardecl lvalues.
This allows us to translate:

int func() {
  register int X;
  {
    int Y;
    return 1+X+Y;
  }
}

into:

define i32 @func() {
entry:
        %X = alloca i32         ; <i32*> [#uses=1]
        %Y = alloca i32         ; <i32*> [#uses=1]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
        %tmp = load i32* %X             ; <i32> [#uses=1]
        %tmp1 = add i32 1, %tmp         ; <i32> [#uses=1]
        %tmp2 = load i32* %Y            ; <i32> [#uses=1]
        %tmp3 = add i32 %tmp1, %tmp2            ; <i32> [#uses=1]
        ret i32 %tmp3
                ; No predecessors!
        ret i32 undef
}

llvm-svn: 39555
2007-06-02 05:24:33 +00:00
Bill Wendling 44ebec5310 Submitted by: Bill Wendling
Removed #include <iostream>.

llvm-svn: 39554
2007-06-02 05:06:35 +00:00
Chris Lattner 03df12294b Add initial support for fixed-size local vardecls. This allows us to compile:
int func() {
  register int X;
  {
    int Y;

into:

define i32 @func() {
entry:
        %X = alloca i32         ; <i32*> [#uses=0]
        %Y = alloca i32         ; <i32*> [#uses=0]
        %allocapt = bitcast i32 undef to i32            ; <i32> [#uses=0]
...

llvm-svn: 39553
2007-06-02 04:53:11 +00:00
Chris Lattner 238cbc58c3 Modify Expr::isConstantExpr and friends take a pointer to a SourceLoc instead
of one by reference, making it optional.

llvm-svn: 39552
2007-06-02 04:48:48 +00:00
Chris Lattner 5e1f32a16f reorder files alphabetically
llvm-svn: 39551
2007-06-02 04:47:52 +00:00
Chris Lattner 84915fa79b Start stubbing out decl codegen.
llvm-svn: 39550
2007-06-02 04:16:21 +00:00
Chris Lattner e0c4ae1f24 Generalize this to support printing any valuedecl, e.g. function definitions.
We now print:
  extern void blah();
as:
  void (blah)();

Strange, but ok :)

llvm-svn: 39549
2007-06-02 03:38:08 +00:00
Chris Lattner d1c1c94663 DeclStmt can be just about any type of decl.
llvm-svn: 39548
2007-06-02 03:35:40 +00:00
Chris Lattner 3f3dbeedd3 implement codegen support for return of void and simple scalars.
llvm-svn: 39547
2007-06-02 03:19:07 +00:00
Chris Lattner adb6372aa5 Add support for functions that return non-void.
llvm-svn: 39546
2007-06-02 03:02:07 +00:00
Chris Lattner db91b16755 stub out codegen of binary plus. We now compile:
if (11 + 42) {

to:

        %tmp = add i32 11, 42           ; <i32> [#uses=1]
        %tobool = icmp ne i32 %tmp, 0           ; <i1> [#uses=1]
        br i1 %tobool, label %ifthen, label %ifend


but this doesn't handle any of the interesting/hard stuff yet.

llvm-svn: 39545
2007-06-02 00:16:28 +00:00
Chris Lattner 3e450f947b add new files.
llvm-svn: 39544
2007-06-02 00:01:41 +00:00
Steve Naroff 4555292b1e Bug #:
Submitted by:
Reviewed by:
After speaking with Chris, decided not to have GCC "attributes" inherit
from Decl. This will enable us to grow the attribute hierarchy over time
without effecting Decls.

llvm-svn: 39543
2007-06-01 21:56:17 +00:00
Steve Naroff 6a0675f8a4 Bug #:
Submitted by:
Reviewed by:
Add implemention file for GCC attributes

llvm-svn: 39542
2007-06-01 21:54:34 +00:00
Steve Naroff ff12778709 Bug #:
Submitted by:
Reviewed by:
Interface file for GCC attributes.

llvm-svn: 39541
2007-06-01 21:53:25 +00:00
Chris Lattner e47e440c42 split stmt/expr codegen into their own files.
llvm-svn: 39540
2007-06-01 18:02:12 +00:00
Steve Naroff 0f2fe17ff1 Bug #:
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.

- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.

Still to do...hook up to the Decl...

llvm-svn: 39539
2007-06-01 17:11:19 +00:00
Chris Lattner a076fde1e3 more minor improvements to pretty printer.
llvm-svn: 39538
2007-05-31 18:21:33 +00:00
Chris Lattner b4619481e6 add some ;'s
llvm-svn: 39537
2007-05-31 06:00:14 +00:00
Chris Lattner 1c31050d21 add fixme
llvm-svn: 39536
2007-05-31 06:00:00 +00:00
Chris Lattner df3cafb796 fix a small printer bug, to emit:
a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }
  int e;

instead of:

  a = b;
  {
    int c;
    c = a + b;
    int d;
    d++;
  }  int e;

llvm-svn: 39535
2007-05-31 05:08:56 +00:00
Chris Lattner dc6e3feade emit a return at the end of the function. Run the llvm verifier.
llvm-svn: 39534
2007-05-30 22:55:31 +00:00
Chris Lattner 5269c0377c Add support for codegen'ing paren exprs and if stmts. We can now codegen:
void test() {
  goto l;

l:
  if (11) {
    j: ;
  }
}

into:

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
        icmp ne i32 11, 0               ; <i1>:0 [#uses=1]
        br i1 %0, label %ifthen, label %ifend

ifthen:         ; preds = %l
        br label %j

j:              ; preds = %ifthen
        br label %ifend

ifend:          ; preds = %j, %l
}

whoa... :)

llvm-svn: 39533
2007-05-30 21:03:58 +00:00
Chris Lattner b2e723bed4 add accessor
llvm-svn: 39532
2007-05-30 20:59:30 +00:00
Chris Lattner fc068c15d9 pretty print exprs in stmt contexts with a trailing semicolon.
llvm-svn: 39531
2007-05-30 17:57:36 +00:00
Chris Lattner 208ae96a8c implement codegen of integer literals.
llvm-svn: 39530
2007-05-30 17:57:17 +00:00
Chris Lattner b5217858ee Update
llvm-svn: 39529
2007-05-30 17:01:31 +00:00
Steve Naroff 9992bbab14 Bug #:
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().

llvm-svn: 39528
2007-05-30 16:27:15 +00:00
Bill Wendling 216423bbd7 Submitted by: Bill Wendling
Comment format changes.

llvm-svn: 39527
2007-05-30 06:30:29 +00:00
Steve Naroff 56faab2d4f Bug #:
Submitted by:
Reviewed by:
- Many tweaks to various diagnostics.
- Fixed some location/range issues.
- Bug fix to Sema::ParseDeclStmt() - error return code is "true", not 0.

llvm-svn: 39526
2007-05-30 04:20:12 +00:00
Bill Wendling 4447083418 Submitted by: Bill Wendling
- Conjugate "diagnostic" correctly for 1 diagnostic.

llvm-svn: 39525
2007-05-30 02:38:09 +00:00
Chris Lattner ac24820fa5 Implement codegen support for labels and gotos. We now compile:
void test1() {
  foo:
    goto foo;
    goto foo;
    goto foo;
}

void test() {
  goto l;

l:
  ;
}
into:

define void @test1() {
entry:
        br label %foo

foo:            ; preds = %0, %foo, %entry
        br label %foo
                ; No predecessors!
        br label %foo
                ; No predecessors!
}

define void @test() {
entry:
        br label %l

l:              ; preds = %entry
}

llvm-svn: 39524
2007-05-30 00:13:02 +00:00
Steve Naroff eb9da94d37 Bug #:
Submitted by:
Reviewed by:
Unified the diagnostics for function calls. Since we have range support,
there is no need for including the argument number. Instead, I've made
the diags more expressive by including more type info.

Also improved the indentation of many calls to Diag (which can be 2-3
lines now).

llvm-svn: 39523
2007-05-30 00:06:37 +00:00
Chris Lattner 308f431017 Add codegen support for NullStmt and CompoundStmt. {;;{};;} is now ours!
llvm-svn: 39522
2007-05-29 23:50:05 +00:00
Chris Lattner d5322cd27e Don't print billions of spaces for a label with no indent.
llvm-svn: 39521
2007-05-29 23:49:07 +00:00
Chris Lattner da8a4f467b add accessors.
llvm-svn: 39520
2007-05-29 23:48:32 +00:00
Chris Lattner d1af2d2956 Implement conversion of clang ast types to LLVM types, at least for some trivial
cases.

llvm-svn: 39519
2007-05-29 23:17:50 +00:00
Steve Naroff 2a8ad18e71 Bug #:
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:

- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.

llvm-svn: 39518
2007-05-29 22:59:26 +00:00
Steve Naroff 6f49f5df03 Bug #:
Submitted by:
Reviewed by:
- Finished Sema::ParseReturnStmt(). Still need to tweak ranges.
- Tweaked location for function arguments (they now point at the expression directly, no parens or commas).
- Added InvalidOperands helper...was sick of looking at the same 3 lines in ~9 Check functions.
- Added a few diags and moved a group of statement diags to the proper comment/category.

llvm-svn: 39517
2007-05-29 14:23:36 +00:00
Chris Lattner e64a1b5275 Fix two bugs that fell out from a testcase steve noticed. for this testcase:
extern int pintFunc(int *, int *);

int test() {
  pintFunc(0,
           3);
}

We now print:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~  ^

instead of:

t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
  pintFunc(0,
  ~~~~~~~~

llvm-svn: 39516
2007-05-29 05:53:15 +00:00
Steve Naroff 86272ea1fe Bug #:
Submitted by:
Reviewed by:
Implement type checking for ParseDoStmt, ParseWhileStmt, ParseIfStmt, and
ParseForStmt. ParseForStmt still under construction (contains a FIXME).

llvm-svn: 39515
2007-05-29 02:14:17 +00:00
Steve Naroff 3c87a57a2c Bug #:
Submitted by:
Reviewed by:
Add range support to Sema::CheckConditionalOperands().

llvm-svn: 39514
2007-05-28 19:40:22 +00:00
Steve Naroff 8563f65042 Bug #:
Submitted by:
Reviewed by:
Refine Sema::ParseCallExpr() diags (range support, add types).

Before:

func-assign.c:27:11: warning: passing argument 1 from incompatible pointer type
  pintFunc(&FOO);
          ^
func-assign.c:28:12: error: incompatible type for argument 1
  floatFunc(&FOO);
           ^
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
           ^
After:

func-assign.c:27:11: warning: passing incompatible pointer 'struct foo *' to function expecting 'int *'
  pintFunc(&FOO);
  ~~~~~~~~^~~~~
func-assign.c:28:12: error: passing incompatible type 'struct foo *' to function expecting 'float'
  floatFunc(&FOO);
  ~~~~~~~~~^~~~~
func-assign.c:29:12: error: too many arguments to function
  floatFunc(1,2,3);
  ~~~~~~~~~^  ~

llvm-svn: 39513
2007-05-28 19:25:56 +00:00
Steve Naroff 758ada12f4 Bug #:
Submitted by:
Reviewed by:
- Implement FIXME in Sema::CheckIndirectionOperand().
- Added "const" to FunctionDecl::getResultType().

llvm-svn: 39512
2007-05-28 16:15:57 +00:00
Chris Lattner 010015a11e Add a note about an unimplemented gnu extension.
llvm-svn: 39511
2007-05-28 07:23:54 +00:00
Chris Lattner eefa10e78a implement full sema support for the GCC address-of-label extension.
llvm-svn: 39510
2007-05-28 06:56:27 +00:00
Chris Lattner e2473068d4 Change GotoStmt's to have a pointer to the LabelStmt instead of a pointer to
the label identifier.  Handle fwd references etc.  This allows us to detect
uses of undefined labels and label redefinitions, such as:

t.c:2:12: error: redefinition of label 'abc'
  abc: ;   abc:
           ^
t.c:2:3: error: previous definition is here
  abc: ;   abc:
  ^
t.c:12:12: error: use of undeclared label 'hijl'
      goto hijl;
           ^

llvm-svn: 39509
2007-05-28 06:28:18 +00:00
Chris Lattner ac4471c963 Improve the parsers resilience to sematic errors. This allows us to turn:
void foo() {
  if (0) break;
  abc:
  def:
  hij:
    break;

into:

void foo() {
  if ((0)')
    ;
abc:
def:
hij:
  ;

instead of dropping the if and labels (due to break not being in a loop).

llvm-svn: 39508
2007-05-28 05:38:24 +00:00
Chris Lattner 2f6ac263ef Null pointers in the ast are no longer considered to be the null stmt.
llvm-svn: 39507
2007-05-28 01:47:47 +00:00
Chris Lattner 0f203a7c1c add action for null stmt, create ast node.
llvm-svn: 39506
2007-05-28 01:45:28 +00:00
Chris Lattner 012a6cf1de add a NullStmt ast node.
llvm-svn: 39505
2007-05-28 01:41:58 +00:00
Chris Lattner bed314465a Reorganize codegen files.
llvm-svn: 39504
2007-05-28 01:07:47 +00:00
Chris Lattner 7a50aa98f0 Stop generating code after the first error is emitted.
llvm-svn: 39503
2007-05-28 00:47:06 +00:00
Chris Lattner c49b9051f4 track whether an error has been emitted.
llvm-svn: 39502
2007-05-28 00:46:44 +00:00
Steve Naroff 9358c715da Bug #:
Submitted by:
Reviewed by:
- Added type checking to Sema::ParseReturnStmt (still under construction).
- Improved Expr::isLvalue() and Expr::isModifiableLvalue() to return more
info. Used the info in Sema::CheckAssignmentOperands() to produce more
descriptive diagnostics. Added FIXME to other clients of isLvalue()/etc.
- Added a SourceLocation slot to MemberExpr...changed the implementation
of getSourceRange().
- Added getResultType() helper to FunctionDecl.
- Changed many Diag calls to use the SourceRange support (now that it's
a big hit...we better milk it:-).

llvm-svn: 39501
2007-05-27 23:58:33 +00:00
Bill Wendling c5fc5f197d Bug #:
Submitted by: Bill Wendling
Reviewed by:

- Can do just a 'cast<>()' because we're checking that it's Tagged.

llvm-svn: 39500
2007-05-27 23:36:18 +00:00
Bill Wendling 229f243f5f Bug #:
Submitted by: Bill Wendling
Reviewed by: Steve Naroff

- Steve suggested avoiding the dyn_cast by using the "Tagged" type class
  and having the "default" just return false.

llvm-svn: 39499
2007-05-27 23:31:02 +00:00
Bill Wendling 21862c3fbd Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Rework the isDerivedType method so that if a language doesn't support
  references, it won't have to pay the price for them. This inlines the
  checks for derived types and turns it into a switch statement instead.

llvm-svn: 39498
2007-05-27 22:46:14 +00:00
Bill Wendling 6811c0b5f3 Bug #:
Submitted by: Bill Wendling
Reviewed by:

C++ references testcase.

llvm-svn: 39497
2007-05-27 10:16:12 +00:00
Bill Wendling 3708c18559 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Initial support for C++ references. Adding to the AST and Parser.
  Skeletal support added in the semantic analysis portion. Full semantic
  analysis is to be done soon.

llvm-svn: 39496
2007-05-27 10:15:43 +00:00
Chris Lattner f97fe38cb5 Initial scaffolding for an -emit-llvm mode. This requires the LLVM VMCore
library to be built for the driver to link.

llvm-svn: 39495
2007-05-24 06:29:05 +00:00
Chris Lattner 6d4024ae6b fit in 80 cols
llvm-svn: 39494
2007-05-24 06:28:11 +00:00
Chris Lattner 7eef919d82 Accept parenthesized expressions like ((void*)0) and (void*)(0) as null pointer
constants.

llvm-svn: 39493
2007-05-24 01:23:49 +00:00
Chris Lattner a5490953d1 correct printout, enums are separate.
llvm-svn: 39492
2007-05-24 01:09:39 +00:00
Chris Lattner c31f4545d1 add ParseExprCXX.cpp to project.
llvm-svn: 39491
2007-05-24 01:09:15 +00:00
Chris Lattner 81312e7835 Remove unused #include that breaks layering
llvm-svn: 39490
2007-05-24 01:08:56 +00:00
Chris Lattner f95211394a implement printer support for C++ bool literals
llvm-svn: 39489
2007-05-24 00:50:25 +00:00
Chris Lattner 24e0d6cf40 Implement a fixme
llvm-svn: 39488
2007-05-24 00:47:01 +00:00
Chris Lattner fc234de388 silence a bunch of warnings, fix some funky indentation.
llvm-svn: 39487
2007-05-24 00:40:54 +00:00
Chris Lattner 6ba4ef5325 fix description
llvm-svn: 39486
2007-05-23 23:56:42 +00:00