Commit Graph

81 Commits

Author SHA1 Message Date
Steve Naroff f7a5da17d9 Added a new expression, OCUVectorComponent.
llvm-svn: 40577
2007-07-28 23:10:27 +00:00
Steve Naroff c701ace221 Add Type::isOCUVectorType().
Convert isFunctionType(), isStructureType(), and isUnionType() to the new API.

llvm-svn: 40541
2007-07-26 18:32:01 +00:00
Steve Naroff 62b35d41cd Forgot a return stmt (oops).
llvm-svn: 40509
2007-07-26 03:18:02 +00:00
Steve Naroff 185616f293 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(). 

llvm-svn: 40508
2007-07-26 03:11:44 +00:00
Steve Naroff 44fd8ff400 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.

llvm-svn: 40475
2007-07-24 21:46:40 +00:00
Chris Lattner 9802144709 Fix a valgrind error noticed by Benoit Boissinot
llvm-svn: 40113
2007-07-20 18:48:28 +00:00
Bill Wendling ee673372ef Return the correct type from isReferenceType().
llvm-svn: 39956
2007-07-17 04:47:36 +00:00
Bill Wendling 354fb2678d 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
llvm-svn: 39954
2007-07-17 04:16:47 +00:00
Chris Lattner 96d423ef37 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.

llvm-svn: 39932
2007-07-16 22:05:22 +00:00
Chris Lattner aee0cfd486 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

llvm-svn: 39892
2007-07-16 00:23:25 +00:00
Chris Lattner 68ebef886a as a very useful feature, make isVectorType and isPointerType return
the actual vectortype or pointertype when they return success.

llvm-svn: 39890
2007-07-16 00:13:25 +00:00
Chris Lattner 0e9d6226ca Refactor code so that isIntegerConstantExpr has an ASTContext available.
llvm-svn: 39884
2007-07-15 23:26:56 +00:00
Chris Lattner 983a8bbbb2 Move getSize() out of type, into ASTContext, where it has target info, and
where ASTContext can manage caches for struct layout, etc.

llvm-svn: 39835
2007-07-13 22:13:22 +00:00
Chris Lattner 2ce5dd4c98 remove some extraneous spaces, no functionality change.
llvm-svn: 39832
2007-07-13 21:01:17 +00:00
Chris Lattner d2b88ab313 Implement codegen for + and - with pointers. Patch contributed by
Keith Bauer.

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

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

float4 float4_return()
{
    float4 xx;

    return ~xx;
}

...now emits the following diagnostic...

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

llvm-svn: 39791
2007-07-12 21:46:55 +00:00
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 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
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 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 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 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 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
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 226d419e21 trivial simplification
llvm-svn: 39563
2007-06-02 22:47:37 +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
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 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 db5ac601e7 eliminate an extraneous space when printing qualified types in some cases.
llvm-svn: 39461
2007-05-20 04:21:51 +00:00
Steve Naroff 72cada0ad9 Bug #:
Submitted by:
Reviewed by:
Extended Expr's constant expression predicates to return a source location
if the predicate returns false. This enables us to position the cursor
exactly were the error occurred (simple pleasures:-).

constant.c:9:9: error: enumerator value for 'E2' is not an integer constant
  E2 = (aconst + 1), // illegal
        ^
constant.c:10:8: error: enumerator value for 'E3' is not an integer constant
  E3 = "abc",
       ^
constant.c:12:12: error: enumerator value for 'E5' is not an integer constant
  E5 = 0?7:printf("xx"), // illegal
           ^
constant.c:13:12: error: enumerator value for 'E6' is not an integer constant
  E6 = 1?7:printf("xx"), // legal
           ^
constant.c:16:14: error: enumerator value for 'E9' is not an integer constant
  E9 = E0 || a, // illegal
             ^
constant.c:21:6: error: array has incomplete element type 'void'
void ary[7];
     ^
constant.c:22:28: error: variable length array declared outside of any function
struct { int a; } ary2[1?7:printf("xx")],
                           ^
constant.c:23:34: error: variable length array declared outside of any function
                  aryIllegal[0?7:printf("yy")];
                                 ^
constant.c:25:10: error: variable length array declared outside of any function
int ary3[a]; // illegal
         ^
constant.c:26:17: error: size of array has non-integer type 'float'
typedef int vla[2.0]; // illegal
                ^
constant.c:30:22: error: size of array has non-integer type 'float'
int nonIntegerArray2[1+2.0];
                     ^

llvm-svn: 39454
2007-05-18 00:18:52 +00:00
Steve Naroff a78fe7e3ed Bug #:
Submitted by:
Reviewed by:
- Implement type checking for Sema::CheckConditionalOperands.
- Fixed crasher in Sema::UsualUnaryConversion (incorrect use of cast<>).
- Added a few diagnostics and started passing 2 args! (Thanks Chris!).

Here's some diagnostic output that is much nicer than gcc...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cond.c
cond.c:12:14: error: used type 'struct foo' where arithmetic or pointer type is required
  result = s ? 1 : 2;
             ^
cond.c:13:14: error: incompatible operand types ('struct foo' and 'struct bar')
  result = a ? s : s2;
             ^
cond.c:14:14: warning: pointer type mismatch ('struct foo *' and 'struct bar *')
  result = a ? ps : ps2;
             ^
cond.c:14:10: warning: assignment makes integer from pointer without a cast
  result = a ? ps : ps2;
         ^
cond.c:15:14: error: incompatible operand types ('struct foo *' and 'struct foo')
  result = a ? ps : s;
             ^
cond.c:16:14: warning: pointer type mismatch ('void (*)(int)' and 'void (*)(int, int)')
  result = a ? func : func2;
             ^
cond.c:16:10: warning: assignment makes integer from pointer without a cast
  result = a ? func : func2;
         ^
7 diagnostics generated.
[dylan:~/llvm/tools/clang] admin% cc -c cond.c
cond.c: In function 'main':
cond.c:12: error: used struct type value where scalar is required
cond.c:13: error: type mismatch in conditional expression
cond.c:14: warning: pointer type mismatch in conditional expression
cond.c:14: warning: assignment makes integer from pointer without a cast
cond.c:15: error: type mismatch in conditional expression
cond.c:16: warning: pointer type mismatch in conditional expression
cond.c:16: warning: assignment makes integer from pointer without a cast

llvm-svn: 39451
2007-05-16 19:47:19 +00:00
Chris Lattner 3dc3d775fb Rename type::getAsString to getAsStringInternal. Add a new
QualType::getAsString() that returns a string, which is much easier
for clients to use.  Convert clients to use it.

llvm-svn: 39449
2007-05-16 18:07:12 +00:00
Steve Naroff 475cca0d1a Bug #:
Submitted by:
Reviewed by:
Fixed a bug in Sema::CheckAddressOfOperand(). It was (incorrectly) using
isModifiableLvalue() instead of isLvalue(). This motivated me to (finally)
cleanup methods surrounding lsLvalue/isModifiableLvalue. Cleanup involved:
- adding Expr::isLvalue().
- modified Expr::isModifiableLvalue() to use Expr::isLvalue().
- removed Type::isLvalue(), Type::isModifiableLvalue(), and
QualType::isModifiableLvalue(). They were confusing...the respective logic
is now a part of the Expr member functions...
- also added some comments and spec references, since these methods are
so central to expressions working properly.

llvm-svn: 39443
2007-05-14 17:19:29 +00:00
Steve Naroff 29d386c8c6 Bug #:
Submitted by:
Reviewed by:
Removed a couple superflous checks from typesAreCompatible. Moved the
spec references up to a comment.

llvm-svn: 39441
2007-05-12 15:17:11 +00:00
Steve Naroff 3f59729549 Bug #:
Submitted by:
Reviewed by:
This check-in should finally "nail" complex pointer assignments (involving
qualifiers, etc.).
- Replaced pointerTypeQualifiersAlign() with CheckPointerTypesForAssignment()
This also simplified UsualAssignmentConversions().
- Fixed Type::pointerTypesAreCompatible() and Type::typesAreCompatible()
to closely reflect the spec. They were (unfortunately) compensating for some of the
missing logic in the assignment checking code.

llvm-svn: 39440
2007-05-11 22:18:03 +00:00
Steve Naroff 1f4d72724e Bug #:
Submitted by:
Reviewed by:
- Enhanced UsualAssignmentConversions() to properly handle type qualifiers on
pointers.
- Added helper function Sema::pointerTypeQualifiersAlign().
- Noticed several errors improperly named "ext_" (fixed).
- Combined structureTypesAreCompatible/unionTypesAreCompatible into
tagTypesAreCompatible.
- Renamed Type::getCanonicalType() to Type::getCanonicalTypeInternal(). It
will never confuse/bite me again:-)
- Added a couple extension diagnostics for discarded type qualifiers.

llvm-svn: 39439
2007-05-11 04:00:31 +00:00
Steve Naroff 8eeeb1345f Bug #:
Submitted by:
Reviewed by:
- Added Sema::isConstantArrayType() and Type::isConstantSizeType().
- Implemented type checking for "variably modified" types (i.e. VLA's).
Added checking for file scope variables, static variables, member variables,
and typedefs.
- Changed Expr::isIntegerConstantExpr() to non-virtual implementation.
Fixed bug with sizeof/alignof. Looking at the diff, I may need to
add a check to exclude alignof.
- Added Expr::isConstantExpr()...non-virtual, like above.
- Added typechecking for case statements (found a bug with actions/parsing...).
- Added several diagnostics.
- Fixed several comments.
Started implemented constant expression checking for arrays.

llvm-svn: 39437
2007-05-08 21:09:37 +00:00
Steve Naroff 38a9dae33f Bug #:
Submitted by:
Reviewed by:
- implement Type::functionTypesAreCompatible().
- fix bug in Sema::CheckAssignmentOperands(). Spec allows any pointer type
to be assigned to _Bool.

llvm-svn: 39428
2007-05-02 19:22:16 +00:00
Steve Naroff dd92b932e0 Bug #:
Submitted by:
Reviewed by:
Implement CheckAssignmentOperands(). This includes...

- Adding 6 static member predicates to Type.
- Adding 2 error diagnostics and 3 GCC extensions.
- Adding a "getValue" accessor to IntegerLiteral.

Still more work to do (including implement compound assignments).

llvm-svn: 39427
2007-05-02 02:47:33 +00:00
Steve Naroff 1cbdf71d2e Bug #:
Submitted by:
Reviewed by:
Carbon.h now compiles without error!

All 14 errors were the result of two Type predicates (isArithmeticType
and isScalarType) not allowing enums. Note: this could have been avoided by rigorously using
isIntegerType. For efficiency, I decided not to have predicates use predicates.

Still more work to do, however this is a nice milestone considering how much "work" is being done...

llvm-svn: 39417
2007-04-26 21:44:56 +00:00
Steve Naroff 82ceca595e Bug #:
Submitted by:
Reviewed by:
Implement FIXME's for signed/unsigned operands in UsualArithmeticConversions()...
- Added GetIntegerRank() and used it in the appropriate places.
- Added ConvertSignedWithGreaterRankThanUnsigned(), with a FIXME.
Misc...converted a bunch of static_cast usage to dyn_cast (in Type.cpp)

A and handled signed/unsigned combos.

llvm-svn: 39415
2007-04-25 21:10:52 +00:00
Steve Naroff b01bbe3ecb Bug #:
Submitted by:
Reviewed by:
Refactored code that deals with float/complex conversions (the previous commit).

- Removed 6 predicates that identify the built-in float/complex types.
- Added two helper functions GetFloatingRank() & ConvertFloatingRankToComplexType().
At present, these are static functions in SemaExpr.cpp. Conceptually, they would be nice
to move to Type, however there are layering problems with that (i.e. no ASTContext).
Another possibility is to move them to ASTContext?
- Simplified the logic in UsualArithmeticConversions() considerably.

llvm-svn: 39413
2007-04-25 01:22:31 +00:00
Steve Naroff bf223ba1fa Bug #:
Submitted by:
Reviewed by:
-Lot's of detail work in UsualArithmeticConversion(). Needed to expand
the code for dealing with floating types. This code still has a couple
of FIXME's and could be refactored a bit.
-Added a bunch of Type predicates to simplify the float conversions.
Used the opportunity to convert a bunch of predicates to dyn_cast (it's cleaner
when just dealing with Builtin types).

llvm-svn: 39412
2007-04-24 20:56:26 +00:00
Steve Naroff 1926c836bb Bug #:
Submitted by:
Reviewed by:
Lot's of changes related to type checking binary expressions.
- Changed the name/proto of ImplicitConversion. It is now named UsualUnaryConversion - it takes a
type and returns a type. This allowed me to remove the explicit node creation for array/function->pointer conversions.
- Added function UsualArithmeticConversions().
- Changed all the "Check" functions for binary ops. They use the new "Usual" functions above.
- new predicates on Type, isSignedIntegerType()/isUnsignedIntegerType().
- moved getDecl() out of the Sema class. It is now a static helper function in SemaExpr.cpp. It was also renamed getPrimaryDeclaration().
- Added CheckArithmeticOperand() for consistency with the other unary "Check" functions.

Should finish up the binary expressions tomorrow...with a small number of "FIXME's"

llvm-svn: 39411
2007-04-24 00:23:05 +00:00
Steve Naroff 4b7ce03f55 Bug #:
Submitted by:
Reviewed by:
- Added Type::isPromotableIntegerType().
- The unary operators are now largely complete (Sema::ParseUnaryOp and friends).
- Implemented ImplicitConversion hook (was a stub).

llvm-svn: 39409
2007-04-20 22:26:17 +00:00
Steve Naroff e5aa9be0a0 Bug #:
Submitted by:
Reviewed by:
-Changed the name of TypeRef to QualType. Many diffs.
-Changed the QualType constructor to require Quals be passed. This makes the code a bit
more verbose, however will make the code easier to work on. Given the complexity
of types, this should help spot bogosities.
-Changed the Expr constructor to require a QualType. Same motivation.

llvm-svn: 39395
2007-04-05 22:36:20 +00:00