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

61 Коммитов

Автор SHA1 Сообщение Дата
Steve Naroff 363bcff47d - Finish hooking up support for __builtin_types_compatible_p().
- Fix type printing code for recently added TypeOfExpr/TypeOfType.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40700 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-01 23:45:51 +00:00
Steve Naroff d34e915f33 Add AST/Sema support for __builtin_types_compatible_p (a GNU extension).
Todo...still need to call the action from the parser...


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40693 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-01 22:05:33 +00:00
Steve Naroff 8d1a3b8ca1 Two typeof() related changes...
- Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr().
- Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal
for error diagnostics (since it's more natural to display the expressions type). 

One "random" (or at least delayed:-) change...

- Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now
off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will
emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn
this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes
an issue, we can revisit.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40676 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-01 17:20:42 +00:00
Chris Lattner 02c642e8f4 remove more explicit accesses to the canonical type pointer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40653 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 21:33:24 +00:00
Chris Lattner 2dcb6bb17d simplify some type checking code, don't explicitly access
canonical types.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40652 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 21:27:01 +00:00
Chris Lattner c8629630ce split the rest of the type predicates into pure predicates:
there is now an isXXXType and a getAsXXXType


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40646 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 19:29:30 +00:00
Chris Lattner a1d9fdea79 rename isReferenceType to follow the new scheme.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40640 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 16:56:34 +00:00
Chris Lattner befee48ff2 make isPointerType() a pure predicate, rename the
existing one to getAsPointerType()


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40639 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 16:53:04 +00:00
Steve Naroff d1861fd633 Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40631 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-31 12:34:36 +00:00
Chris Lattner d51d890954 Don't use canonical type for sema here. In
void func() {
typedef int foo;
foo *Y;
**Y; // error
}

we now get:
indirection requires pointer operand ('foo' invalid)
instead of:
indirection requires pointer operand ('int' invalid)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40597 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-30 18:53:26 +00:00
Steve Naroff fec0b49c3f Finish up semantic analysis for vector components.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40584 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-30 03:29:09 +00:00
Steve Naroff bea0b34d99 Implement pretty diagnostics when doing on-the-fly vector sizing (for vector component access).
For example, before this commit, the following diagnostics would be emitted...

ocu.c:49:12: error: incompatible types assigning 'float  __attribute__((ocu_vector_type(3)))' to 'float4'
    vec4_2 = vec4.rgb; // shorten
    ~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float  __attribute__((ocu_vector_type(2)))' to 'float'
    f = vec2.xx; // shorten
    ~ ^ ~~~~~~~

Now, the diagnostics look as you would expect...

ocu.c:49:12: error: incompatible types assigning 'float3' to 'float4'
    vec4_2 = vec4.rgb; // shorten
    ~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float2' to 'float'
    f = vec2.xx; // shorten
    ~ ^ ~~~~~~~



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40579 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-29 16:33:31 +00:00
Steve Naroff 31a458462c Added a new expression, OCUVectorComponent.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40577 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-28 23:10:27 +00:00
Steve Naroff e1b31fedbc Implement syntax/semantic analysis for OCU Vector Components.
Next step, AST support...



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40568 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-27 22:15:19 +00:00
Steve Naroff 08f794b212 Fix the following bogus diagnostic...reported by Jeroen.
#include <stdio.h>

int
main(void) {
        int test = 0;

        printf("Type is %s\n", (test >= 1 ? "short" : "char"));

        return (0);
}

It comes up with a diagnostic that's misleading upon first read.

t.c:7:36: error: incompatible operand types ('char *' and 'char *')
        printf("Type is %s\n", (test >= 1 ? "short" : "char"));
                                          ^ ~~~~~~~   ~~~~~~
1 diagnostic generated.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40526 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-26 14:35:56 +00:00
Steve Naroff dfa6aae5a1 Various improvements to Sema::ParseMemberReferenceExpr().
- Added source range support to Diag's.
- Used the new type predicate API to remove dealing with the canonical
type explicitly.
- Added Type::isRecordType().
- Removed some casts.
- Removed a const qualifier from RecordType::getDecl(). 




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40508 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-26 03:11:44 +00:00
Steve Naroff 82c7e6d821 - Fix commit in Parser.h (patch by Kevin Andre).
- Add comment and minor cleanup to yesterday's fix to ParseCallExpr().


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40492 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-25 20:45:33 +00:00
Chris Lattner e80a59cc41 Fix a couple of bugs, add some new cool stuff.
1. Fix a todo in Parser::ParseTag, to recover better.  On code like
   that in test/Sema/decl-invalid.c it causes us to return a single
   error instead of multiple.
2. Fix an error in Sema::ParseDeclarator, where it would crash if the
   declarator didn't have an identifier.  Instead, diagnose the problem.
3. Start adding infrastructure to track the range of locations covered
   by a declspec or declarator.  This is mostly implemented for declspec,
   but could be improved, it is missing for declarator.

Thanks to Neil for pointing out this crash.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40482 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-25 00:24:17 +00:00
Steve Naroff 700204c74b Fix Sema::ParseCallExpr()...it wasn't doing the default array/function promotions on it's argument types.
This resulted in the following errors when compiling promote_types_in_proto.c test...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang test/Parser/promote_types_in_proto.c 
test/Parser/promote_types_in_proto.c:7:24: error: incompatible types passing 'char *[]' to function expecting 'char *const []'
        arrayPromotion(argv);
        ~~~~~~~~~~~~~~ ^~~~
test/Parser/promote_types_in_proto.c:8:27: error: incompatible types passing 'void (char *const [])' to function expecting 'void (char *const [])'
        functionPromotion(arrayPromotion);
        ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~
2 diagnostics generated.

When fixing this, noticed that both ParseCallExpr() and ParseReturnStmt() were prematurely comparing types for
equivalence. This is incorrect (since the expr. promotions haven't been done yet). To fix this, I moved the
check "down" to Sema::CheckAssignmentConstraints().

I also converted Type::isArrayType() to the modern API (since I needed it). Still more Type predicates to 
convert.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40475 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-24 21:46:40 +00:00
Chris Lattner ab18c4c0ac implement ast building and trivial semantic analysis of stmt exprs.
This implements test/Sema/stmt_exprs.c



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40465 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-24 16:58:17 +00:00
Chris Lattner 8a87e57beb correctly verify that default and case are in a switchstmt,
this fixes test/Sema/switch.c.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40438 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-23 17:05:23 +00:00
Anders Carlsson c1fcb77626 Refactor switch analysis to make it possible to detect duplicate case values
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40388 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-22 07:07:56 +00:00
Chris Lattner 78c75fb3d2 recover from void argument types more nicely.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40169 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 05:30:18 +00:00
Chris Lattner 4565d4e83c better wording for an error, suggested by Neil.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40163 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 05:26:43 +00:00
Anders Carlsson 227426661b Implement code generation for __func__, __FUNCTION__ and __PRETTY_FUNCTION__
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40162 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 05:21:51 +00:00
Chris Lattner 2ff5426cd8 improve and simplify error recovery for calls, fix a crash when diagnosing
invalid arguments.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40161 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 05:18:12 +00:00
Chris Lattner eddbe03075 fix a warning on some compilers
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40139 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-21 04:57:45 +00:00
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 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
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
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
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 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 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
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
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
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 7a2e047c60 Now that isPointerType can return a pointer type, avoid stripping off typedef
information in the common case.  On this invalid code:

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

we now generate:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
instead of:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int  __attribute__((vector_size(16)))'

This implements test/Sema/typedef-retain.c



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39892 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 00:23:25 +00:00
Chris Lattner 12d9ff6a07 Use the return value of isPointerType and isVectorType to significantly simplify
ParseArraySubscriptExpr.  Notably, the new code doesn't have to think about 
canonical types at all.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39891 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-16 00:14:47 +00:00
Chris Lattner 727a80dda3 rename variables to be more consistent. Always use LHS/RHS intead of T1/T2 sometimes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39889 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-15 23:59:53 +00:00
Chris Lattner 590b6646ef Refactor code so that isIntegerConstantExpr has an ASTContext available.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39884 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-15 23:26:56 +00:00
Steve Naroff fa2eaabd30 This is the final step/commit for implementing exlicit implicit casts. Unlike the
previous two checkins, which involved lot's of tedious refactoring, this checkin is nice and clean:-)

- Hacked UsualUnaryConversions, UsualArithmeticConversions, and DefaultFunctionArrayConversion
to create the AST node (using a helper function promoteExprToType).
- Added a setType method to Expr.
- Changed Expr::isIntegerConstantExpr to allow for the new node.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39866 91177308-0d34-0410-b5e6-96231b3b80d8
2007-07-15 02:02:06 +00:00