Commit Graph

34276 Commits

Author SHA1 Message Date
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 5c10d4bac1 Bug #:
Submitted by:
Reviewed by:
Start hacking on binary ops...
Important bug fix...was ignoring the return value from ImplicitConversion.
This didn't bother the type checking logic, however the AST was malformed.

llvm-svn: 39410
2007-04-20 23:42:24 +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 4750051ebb Bug #:
Submitted by:
Reviewed by:
Continue working on type checking for unary operators. Added:

- Two 3 private functions to Sema: CheckAddressOfOperand(), CheckIndirectionOperand(),
and getDecl().
- Added Expr::isLvalue() - it was needed for CheckAddressOfOperand(). It will
also be needed for ++/-- and the assignment operators.
- Added a couple diagnostics for invalid lvalues (for & of).

llvm-svn: 39408
2007-04-19 23:00:49 +00:00
Chris Lattner 89399da91a fixme done!
llvm-svn: 39407
2007-04-11 04:16:36 +00:00
Chris Lattner 99ca091b9c Warn when performing 'usual' conversions that require a sign change. This
implements test/Preprocessor/expr_usual_conversions.c, which produces this
output:

expr_usual_conversions.c:5:10: warning: left side of operator converted from negative value to unsigned: -42 to 18446744073709551574
#if (-42 + 0U) / -2
         ^
expr_usual_conversions.c:5:16: warning: right side of operator converted from negative value to unsigned: -2 to 18446744073709551614
#if (-42 + 0U) / -2
               ^

llvm-svn: 39406
2007-04-11 04:14:45 +00:00
Chris Lattner 8ec9355a48 Overflow detection for multiply and divide. Fix a bug handling 'usual
arithmetic conversions'.

llvm-svn: 39405
2007-04-11 04:04:29 +00:00
Chris Lattner 7e61ac5a3c Catch overflow of negate. This allows us to emit:
t.c:2:17: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
                ^
t.c:2:5: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
    ^

GCC has some seriously confused source locations in this case:
t.c:2:19: warning: integer overflow in preprocessor expression
t.c:2:20: warning: integer overflow in preprocessor expression

column 19/20 are off the end of the line.

llvm-svn: 39404
2007-04-11 03:42:36 +00:00
Chris Lattner 028c7decef Overflow detection for +/-
llvm-svn: 39403
2007-04-11 03:34:29 +00:00
Chris Lattner 9cc755d535 Evaluate result into an explicit destination. No functionality change.
llvm-svn: 39402
2007-04-10 07:07:11 +00:00
Chris Lattner 9e2fcccc33 Fix run line
llvm-svn: 39401
2007-04-10 07:06:36 +00:00
Chris Lattner 5a0f164a52 Track overflow of shift amounts, allowing diagnostics like:
t.c:6:7: warning: integer overflow in preprocessor expression
#if 1 << 63
      ^
t.c:8:7: warning: integer overflow in preprocessor expression
#if 4 << 62
      ^
t.c:10:7: warning: integer overflow in preprocessor expression
#if 4 << 66
      ^

but no diagnostic on:
#if 1U << 63

llvm-svn: 39400
2007-04-10 06:54:33 +00:00
Chris Lattner a7fa1b247c 'true' in a CPP expression evaluates to 1 when in C++ mode. This implements
test/Preprocessor/cxx_true.cpp

llvm-svn: 39399
2007-04-10 06:16:30 +00:00
Chris Lattner 7c718bd5a4 Include the filename being looked up in an error message. This gives us stuff
like this:
t3.c:5:10: error: 'vers2.h' file not found
#include xstr(INCFILE(2).h)
         ^

instead of:

t3.c:5:10: error: file not found
#include xstr(INCFILE(2).h)
         ^

which is useful if the #include name is generated through macro expansion.

llvm-svn: 39398
2007-04-10 06:02:46 +00:00
Chris Lattner 86054a9634 Diagnostics relating to computation of values should only be produced if an
expression is live.  For example:
#if 0 ? 124/0 : 42

should cause no error.

This implements test/Preprocessor/expr_liveness.c

llvm-svn: 39397
2007-04-10 05:26:38 +00:00
Chris Lattner 6acf759735 new testcase
llvm-svn: 39396
2007-04-10 05:25:39 +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
Steve Naroff d50c88e489 Bug #:
Submitted by:
Reviewed by:
Fix "FIXME: does this lose qualifiers from the typedef??" in ASTContext::getTypedefType().

This change was fairly pervasive...nevertheless, here are the highlights:
- Change the type of Type::CanonicalType to TypeRef (was "Type *").
- Change the implementation of TypeRef::getCanonicalType() to work for typedefs.
- Make the implementation of Type::getCanonicalType private (only TypeRef should access). This
will force clients to use TypeRef::getCanonicalType (the correct version of the function). Since
TypeRef overloads "->", it was very easy to fall into this bug...
- Changed many references of "Type *" to "TypeRef"...when the raw type pointer is required, use t.getTypePtr().
- Changed all the *Type classes to take a TypeRef.
- Made the Type constructor protected (cleanup).
- Removed function Expr::getType().
- Convert functions in SemaExpr to use the above support. This fixed the "const" bug I was originally investigating.

I will follow this check-in up with a rename of TypeRef->QualType. I will also make sure the constructor does not default to 0 (which can lead to broken code...).

llvm-svn: 39394
2007-04-05 21:15:20 +00:00
Chris Lattner f8a0b0fa50 Add support for character constants in PP expressions, like:
#if 'a'

llvm-svn: 39393
2007-04-05 06:58:56 +00:00
Chris Lattner 380048807e Implement support for semantic analysis of character constants.
llvm-svn: 39392
2007-04-05 06:58:19 +00:00
Chris Lattner d5a828b6bb wchar_t width is now expressed in terms of bits for uniformity.
llvm-svn: 39391
2007-04-05 06:57:57 +00:00
Chris Lattner 2f5add6272 Implement support for performing semantic analysis of character literals.
llvm-svn: 39390
2007-04-05 06:57:15 +00:00
Chris Lattner d2f5ec4e55 add some more dummy target hooks
llvm-svn: 39389
2007-04-05 06:40:47 +00:00
Chris Lattner a9eac7ff44 Correctly represent and propagate signedness information in preprocessor
constant expressions.  This allows us to emit this diagnostic:

t.c:5:5: warning: integer constant is so large that it is unsigned
#if 12345678901234567890
    ^

And makes constant evaluation fully correct, but we do not yet detect and
warn about integer overflow.

This patch requires cvs up'ing the main llvm tree to get the APSInt class,
but no libraries need to be rebuilt there.

llvm-svn: 39388
2007-04-05 05:24:00 +00:00
Chris Lattner 6df7975ae6 minor cleanups. The major missing piece is tracking:
* signedness of values
 * overflow of intermediate computations.

llvm-svn: 39387
2007-04-04 06:54:19 +00:00
Chris Lattner 531efa43d8 Ah, this is already correctly rejected!
llvm-svn: 39386
2007-04-04 06:49:26 +00:00
Chris Lattner ce5dc8a6b4 Switch PPExpression parsing to be in terms of APInt's whose widths are properly
sized to the target's intmax_t.  This also allows us to emit diagnostic like:

t.c:11:5: warning: integer constant is too large for its type
#if 18446744073709551616  // 2^64
    ^
t.c:15:5: warning: integer constant is too large for its type
#if 18446744073709551617  // 2^64-1
    ^

llvm-svn: 39385
2007-04-04 06:46:55 +00:00
Chris Lattner ef8743b4f6 Move LiteralSupport files to their alphabetic position.
llvm-svn: 39384
2007-04-04 06:45:50 +00:00
Chris Lattner 525bafbd59 Stub out a method.
llvm-svn: 39383
2007-04-04 06:45:12 +00:00
Chris Lattner 871b4e101c Minor enhancements to GetIntegerValue(APInt):
* Detect overflow correctly.  When it occurs, return the truncated value.
  * Add fixme for radix analysis.

llvm-svn: 39382
2007-04-04 06:36:34 +00:00
Chris Lattner 5b743d3801 Add some really simplistic code for turning a ppnumber into an APInt. Much
improvement is needed!

llvm-svn: 39381
2007-04-04 05:52:58 +00:00
Steve Naroff 6f65421eab Bug #:
Submitted by:
Reviewed by:
Minor bug/typo in classof.

llvm-svn: 39380
2007-04-03 23:26:02 +00:00
Steve Naroff 46ba1ebaeb Bug #:
Submitted by:
Reviewed by:
- Typechecking for ++/-- not operating on canonical type (fixed).
- Many changes to Decl.h...
-- Changed ObjectDecl->ValueDecl.
-- ValueDecl doesn't define a storage class. The storage class is now
defined by VarDecl/FunctionDecl. EnumConstant decls don't need a storage class.
-- FieldDecl now inherits directly from Decl (it is not a value).
- Changed SemaExpr to use the new Decl.h. Also added a couple diagnostics for
bogus storage class usage. For example:
z.c:6:10: error: illegal storage class on function
auto int func();
         ^
z.c:7:14: error: illegal storage class on file-scoped variable
register int b;
             ^

llvm-svn: 39379
2007-04-03 23:13:13 +00:00
Chris Lattner 23d890337b Specify an initial size for StringMap.
llvm-svn: 39378
2007-04-03 22:14:25 +00:00
Chris Lattner 442f380edd Specify an initial size for StringMap's
llvm-svn: 39377
2007-04-03 22:13:57 +00:00
Steve Naroff 0f6256d0fa Bug #:
Submitted by:
Reviewed by:
declare getSizeType() const and fix typo in comment...

llvm-svn: 39376
2007-04-02 23:01:44 +00:00
Steve Naroff 7840336c91 Bug #:
Submitted by:
Reviewed by:
Avoid including "clang/AST/Expr.h" in Sema.h just to access
UnaryOperator::Opcode. While the inclusion wasn't objectionable in terms
of layering, it is nice to keep the inclusions as modest as possible.

llvm-svn: 39375
2007-04-02 22:55:05 +00:00
Steve Naroff 92e30f8cc7 Bug #:
Submitted by:
Reviewed by:
Incorporate code review feedback from Chris...
- minor restructure of ParseMemberReferenceExpr logic. The last statement
is now the instantiation of the AST node (which I like a lot and will conform
to throughout Sema).
- declare StmtClassNameTable const.
- reword an error diagnostic.
- install the correct type for ParseSizeOfAlignOfTypeExpr. Added hook in
ASTContext. For now, simply return Context.UnsignedLongTy. Added a FIXME
to revisit (i.e. compute using TargetInfo).

llvm-svn: 39374
2007-04-02 22:35:25 +00:00
Steve Naroff ef2ab6a572 Bug #:
Submitted by:
Reviewed by:
Add three new classes to Decl.h: BlockVarDecl, FileVarDecl, and ParmVarDecl.

Made the constructor to VarDecl protected, to indicate it is "abstract".

Reorganized the Decl::Kind enum to allow us to add ObjectDecls/TypeDecls with
minimal breakage.  In the process, realized the isa support for ObjectDecl was already broken (so
the reorg paid for itself already:-) The range check should also be more efficient...

llvm-svn: 39373
2007-04-02 20:50:54 +00:00
Steve Naroff fc49d67add Bug #:
Submitted by:
Reviewed by:
- Finished up incomplete type analysis for varibles (in Sema::ParseDeclarator()).
- Added many spec refs, since this area is confusing (for top level decls
in particular).
- Added a FIXME to MergeVarDecl()...it needs to be taught about tentative
definitions. As a result, we currently issue some bogus diagnostics.

llvm-svn: 39372
2007-04-01 21:27:45 +00:00
Steve Naroff ca8f71287f Bug #:
Submitted by:
Reviewed by:
- ParseMemberReferenceExpr wasn't operating on the canonical type. From
now on, I will make sure the prologue to each Parse/Check function has
both the qualified type and the canonical type.
- More refinements to ParseDeclarator. It was allowing variable declarations
to incomplete types (e.g. void, struct foo, where foo wasn't defined).

llvm-svn: 39371
2007-04-01 01:41:35 +00:00
Steve Naroff 95af013c77 Bug #:
Submitted by:
Reviewed by:
Incorporate feedback from Chris (on the last check-in).
- added a shared hook for pre/post ++/-- CheckIncrementDecrementOperand().
- handle invalid arithmetic on incomplete types (void *, struct foo *, where the
body isn't in scope). Added a diagnostic for this case.
- added some comments and C99 annotations.
- Sema.h now includes Expr.h. I'd prefer not to, however it doesn't break
any layering.

llvm-svn: 39370
2007-03-30 23:47:58 +00:00
Steve Naroff bc2f0993c0 Bug #:
Submitted by:
Reviewed by:
Implement ++/-- typechecking for pre/post unary expressions. This includes:

- added isLvalue, isModifiableLvalue (on TypeRef, Type, and RecordType).
- added isRealType, isRealFloatingType, isComplexType.
- hacked Diag to take a TypeRef (I was sick of writing the 2 line "setup":-)
In addition, this will likely lead to less bugs...I already had written code
that was doing a getAsString on "Type" (which is wrong...since it doesn't include
any qualifiers).
- Changed UnaryOperator to take a TypeRef...pass it the right stuff.
- Removed redundant ternary expressions in several predicates.
- A couple diagnostics.

llvm-svn: 39369
2007-03-30 20:09:34 +00:00
Steve Naroff c1aadb172f Bug #:
Submitted by:
Reviewed by:
Finish up Sema::ParseArraySubscriptExpr. This involved:
- adding a couple predicates to Type.h (isObjectType, isDerivedType).
- added a diagnostic for subscripting non-object types (e.g. void (*)()).
- pass the correct result type...a minor detail:-)
- added some spec references to Type.h

llvm-svn: 39368
2007-03-28 21:49:40 +00:00
Steve Naroff d9e7bd46dd Bug #:
Submitted by:
Reviewed by:
Make an error diagnosic a bit more expression (in Sema::GetTypeForDeclarator)

llvm-svn: 39367
2007-03-27 21:47:23 +00:00
Steve Naroff bc57d0fe19 Bug #:
Submitted by:
Reviewed by:
Finish up fixes to Sema::GetTypeForDeclarator(). The typechecking should
now conform to the standard.

llvm-svn: 39366
2007-03-27 21:40:41 +00:00
Steve Naroff 06deba91d1 Bug #:
Submitted by:
Reviewed by:
Fix a couple bugs in Sema::GetTypeForDeclarator(). Need to disallow:
- void arrayOfFunctions[3]()
- void arrayOfVoids[3]
Need to talk to Chris about the return value...

llvm-svn: 39365
2007-03-27 18:04:48 +00:00
Steve Naroff cc3214299b Bug #:
Submitted by:
Reviewed by:
Finish up Sema::ParseMemberReferenceExpr. This involved:
- added a getMember() function to RecordDecl.
- added stronger typing for "Members" (from Decl->FieldDecl).
- added a dignostic for members not found.
- changed MemberExpr to install the correct TypeRef.
- In general, simplified and cleaned up the routing.

llvm-svn: 39364
2007-03-26 23:09:51 +00:00
Chris Lattner cceab1a8b7 Unnest assignment to make the code more clear
llvm-svn: 39363
2007-03-26 20:16:44 +00:00
Chris Lattner 0e13faa8ce Fix comment.
llvm-svn: 39362
2007-03-26 20:15:47 +00:00