- 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
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
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
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
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
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
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
'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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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