Граф коммитов

28076 Коммитов

Автор SHA1 Сообщение Дата
Chris Lattner d472b31d80 Fix off-by-one error when emitting diagnostics. Also, make diagnostic
a bit nicer for people who pass lots of extra arguments to calls by 
selecting them all instead of just the first one:

arg-duplicate.c:13:13: error: too many arguments to function
  f3 (1, 1, 2, 3, 4);   // expected-error {{too many arguments to function}}
            ^~~~~~~

This implements test/Sema/arg-duplicate.c, thanks to Neil for pointing
out this crash.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40136 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 03:09:58 +00:00
Chris Lattner 74c469fef4 move some casts up to the entry of the function for clarity.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40135 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 03:03:59 +00:00
Chris Lattner 0fa152e72b Two fixes:
1) fix a crash on test/Sema/default.c by making
   sure that the switch scope is non-null.
2) if there is an error sema'ing a default or case stmt,
   make sure to return the substmt up, so that the error
   recovery code has more acurate info to continue with.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40134 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 03:00:26 +00:00
Chris Lattner 942cfd3729 Fix a valgrind error noticed by Benoit Boissinot
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 18:48:28 +00:00
Chris Lattner 45011cf25e remove some old cruft
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40111 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 18:26:45 +00:00
Chris Lattner b1c2df99ba fix a nasty bug Owen noticed in a gcc warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40110 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 18:13:33 +00:00
Chris Lattner 31bb8be680 improve comments, implement a trivial single-entry cache in
SourceManager::getInstantiationLoc.  With this change, every token
expanded from a macro doesn't get its own MacroID.  :)

This reduces # macro IDs in carbon.h from 16805 to 9197



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40108 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 18:00:12 +00:00
Chris Lattner 60c3a1ba7a Update project for LexerToken.h -> Token.h
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40106 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 17:01:09 +00:00
Chris Lattner d217773f10 At one point there were going to be lexer and parser tokens.
Since that point is now long gone, we should rename LexerToken to
Token, as it is the only kind of token we have.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40105 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 16:59:19 +00:00
Chris Lattner 25bdb51276 simplify the lexer ctor to take a SLoc instead of a sloc and a redundant buffer*.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40104 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 16:52:03 +00:00
Chris Lattner 9dc1f530c0 Reimplement SourceLocation. Instead of having a
fileid/offset pair, it now contains a bit discriminating between
mapped locations and file locations.  This separates the tables for
macros and files in SourceManager, and allows better separation of
concepts in the rest of the compiler.  This allows us to have *many*
macro instantiations before running out of 'addressing space'.

This is also more efficient, because testing whether something is a
macro expansion is now a bit test instead of a table lookup (which
also used to require having a srcmgr around, now it doesn't).

This is fully functional, but there are several refinements and
optimizations left.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40103 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-20 16:37:10 +00:00
Chris Lattner 030d8846c7 implement size/alignment analysis for arrays and vectors. This gets carbon.h working again.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40068 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 22:06:24 +00:00
Steve Naroff aff1edd84a Finish fixing crasher with compound literals.
We still need to do sematic analysis (and implement initializers), however this 
should complete the parsing & ast building for compound literals.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40067 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 21:32:11 +00:00
Chris Lattner 2b64fdc499 Fix a stringizing bug that Neil noticed. We should preprocess this:
#define t(x) #x
t(a
c)

to "a c", not "ac".



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40060 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 16:11:58 +00:00
Chris Lattner a87b63b492 silence a warning by treating ocuvectors the same as vectors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40037 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 05:13:51 +00:00
Steve Naroff 4aa88f8d84 Work towards fixing crasher with compound literals...
Before this commit, we crashed in ParseBinOp...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:1298: failed assertion `(rhs != 0) && "ParseBinOp(): missing right expression"'

With this commit, we still crash in the newly added action ParseCompoundLiteral (which is progress:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:478: failed assertion `(Op != 0) && "ParseCompoundLiteral(): missing expression"'

The crash go away once the actions return AST nodes. I will do this in a separate commit.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40032 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 01:06:55 +00:00
Chris Lattner 5265af5b55 Fix a crasher that Neil reported: Sema::GetTypeForDeclarator should never
return a null type.  If there is an error parsing the type, pick a new type
for error recovery purposes.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40029 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 00:42:40 +00:00
Chris Lattner 938867c6cf Make sure to initialize an ivar, patch by Benoit Boissinot.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40027 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 00:11:19 +00:00
Chris Lattner 0ea793e5e3 Correctly respect C99 5.1.1.2p4 when searching for the first '(' of
a function-like macro invocation.  Patch contributed by Neil Booth.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40026 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-19 00:07:36 +00:00
Chris Lattner 76e773a443 implement i-c-e correct evaluation for sizeof/alignof, remove some obsolete fixme's.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40012 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 18:38:36 +00:00
Chris Lattner 5d2a630346 implement sizeof/alignof support for structs, unions and complex.
This allows us to compile this:

struct abc { char A; double D; };

int foo() {
  return sizeof(struct abc);
  return __alignof__(struct abc);
}

Into:

        ret i32 16
        ret i32 8



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40010 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 18:26:58 +00:00
Chris Lattner 5e3fbe503a implement codegen support for sizeof/alignof
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40009 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 18:12:07 +00:00
Steve Naroff 7332292412 First round of extended vector support. Here is an overview...
- added ocu_vector_type attribute, Sema::HandleOCUVectorTypeAttribute(). 
- added new AST node, OCUVectorType, a subclass of VectorType.
- added ASTContext::getOCUVectorType.
- changed ASTContext::convertToVectorType() to ASTContext::getVectorType(). This is 
unrelated to extended vectors, however I was in the vicinity and it was on my todo list.
Added a FIXME to Sema::HandleVectorTypeAttribute to deal with converting complex types.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40007 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 18:00:27 +00:00
Chris Lattner 464175bba1 initial layout support for structures and unions. This isn't actually
hooked up to anything, so it's not very useful yet.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40006 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 17:52:12 +00:00
Chris Lattner a8fe39eb2b add accessors
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40005 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 17:50:10 +00:00
Chris Lattner 75af4801c8 Cast to void is valid, patch by Benoit Boissinot
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40003 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 16:00:06 +00:00
Chris Lattner 6d87fc66ca teach -stats about new types
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39996 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 05:50:59 +00:00
Chris Lattner ce0afc0b09 add a note Neil pointed out
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39994 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 05:21:20 +00:00
Chris Lattner 6c36be5b38 Add initial switch stmt support, patch by Anders Carlsson!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39989 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-18 02:28:47 +00:00
Chris Lattner 67798cb3dd strtod is more portable than strtof apparently. Instead of making this conditional,
just always use strtod.  This is temporary code anyway.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39972 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 15:27:33 +00:00
Gabor Greif 79cc005a07 cheap change to fix solaris compilation. I can make this a static inline if desired
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39970 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 11:05:49 +00:00
Bill Wendling ccb4af858b Use the correct method for getting the ReferenceType from a QualType.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39960 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 05:09:22 +00:00
Chris Lattner 9697a5c457 I forgot to check this in earlier
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39958 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 04:58:06 +00:00
Bill Wendling 251dcaf861 Return the correct type from isReferenceType().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39956 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 04:47:36 +00:00
Bill Wendling ea5e79f930 Change dyn_cast for reference types to be more like pointers and not need the canonical type. Also fix so that we're not expecting a return value from a void function
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39954 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 04:16:47 +00:00
Bill Wendling 08ad47cbd1 Fix references:
According to the spec (C++ 5p6[expr]), we need to adjust "T&" to
    "T" before further analysis. We do this via the "implicit cast"
    thingy.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39953 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 03:52:31 +00:00
Steve Naroff a4332e283e Convert UsualArithmeticConversions to return "void". Now that we synthesize ImplicitCastExpr's,
there is no compelling need to return the converted type. If both expression type's are arithmetic, then
both types will always be the same. If they aren't (for pointer/int types, say), then the
types will be different. The client is responsible for distinguishing...


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39947 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-17 00:58:39 +00:00
Steve Naroff 16beff8408 Implement semantic analysis for the cast operator.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39943 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 23:25:18 +00:00
Steve Naroff 3e5e5560b3 Remove the 2 QualType references to method UsualArithmeticConversions. Last week, I added these
to quickly fix a regression. Avoiding them entirely is a much cleaner solution. Clients of 
UsualArithmeticConversions should simply call getType() on the expression to get the
converted type. In practice, only a small number of routines care about this.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39934 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 22:23:01 +00:00
Chris Lattner a2c7767ce7 In the final step for preserving typedef info better in the AST, upgrade
isPointerType and isVectorType to only look through a single level of typedef
when one is present.  For this invalid code:

typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
typedef int4* int4p;
void test(float4 a, int4p result, int i) {
    result[i] = a;
}

we now get:

t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
    result[i] = a;
    ~~~~~~~~~ ^ ~

instead of:

t.c:5:15: error: incompatible types assigning 'float4' to 'int  __attribute__((vector_size(16)))'
    result[i] = a;
    ~~~~~~~~~ ^ ~

The rest of the type predicates should be upgraded to do the same thing.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39932 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 22:05:22 +00:00
Steve Naroff c80b4eefa2 Change DefaultFunctionArrayConversions and UsualUnaryConversions to return void. The caller
needs to query the expression for the type. Since both these functions guarantee the expression 
contains a valid type, removed old/vacuous asserts (from code calling both of these routines).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39930 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 21:54:35 +00:00
Chris Lattner 26824906e5 Fix a GCC warning:
SemaExpr.cpp:561: warning: dereferencing type-punned pointer will break strict-aliasing rules

Patch by Benoit Boissinot!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39928 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 21:39:03 +00:00
Chris Lattner da13870e99 Implement break and continue. Patch by Anders Carlsson!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39927 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 21:28:45 +00:00
Chris Lattner f0fbcb356b avoid requiring people to update from llvm svn.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39925 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 21:04:56 +00:00
Bill Wendling ca51c97fbb Constify the is*Lvalue() methods.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39907 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 07:07:56 +00:00
Chris Lattner 136f93a2b6 Make octal constant lexing use AdvanceToTokenCharacter to give more
accurate diagnostics.  For test/Lexer/comments.c we now emit:

int x = 000000080;  /* expected-error {{invalid digit}} */
               ^
constants.c:7:4: error: invalid digit '8' in octal constant
00080;             /* expected-error {{invalid digit}} */
   ^


The last line is due to an escaped newline.  The full line looks like:

int y = 0000\
00080;             /* expected-error {{invalid digit}} */


Previously, we emitted:
constants.c:4:9: error: invalid digit '8' in octal constant
int x = 000000080;  /* expected-error {{invalid digit}} */
        ^
constants.c:6:9: error: invalid digit '8' in octal constant
int y = 0000\
        ^

which isn't too bad, but the new way is better for the user,
regardless of whether there is an escaped newline or not.

All the other lexer-related diagnostics should switch over 
to using AdvanceToTokenCharacter where appropriate.  Help
wanted :).

This implements test/Lexer/constants.c.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39906 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 06:55:01 +00:00
Chris Lattner 97ba77cf09 Add a new Preprocessor::AdvanceToTokenCharacter method which, given a sloc
specifying the start of a token and a logical (phase 3) character number,
returns a sloc representing the input character corresponding to it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39905 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 06:48:38 +00:00
Chris Lattner 20e6ccd6f7 add better comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39904 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 06:46:50 +00:00
Chris Lattner f66d3e390f factor a common predicate into a static method.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39903 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 06:16:59 +00:00
Chris Lattner 99e0d7905d Add a hack (mirroring llvm-gcc) to pointer difference
codegen to compile:

int test(int *A, int *B) {
  return A-B;
}

into:

_test:
        movl 4(%esp), %eax
        subl 8(%esp), %eax
        sarl $2, %eax
        ret

instead of:

_test:
        movl 4(%esp), %eax
        subl 8(%esp), %eax
        movl %eax, %ecx
        sarl $31, %ecx
        shrl $30, %ecx
        addl %ecx, %eax
        sarl $2, %eax
        ret



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39902 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 05:43:05 +00:00