Commit Graph

34349 Commits

Author SHA1 Message Date
Bill Wendling 5a85f9104d Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Removed unneeded <iostream> header.

llvm-svn: 39484
2007-05-23 08:05:58 +00:00
Bill Wendling 48fbdd0302 Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Changed "std::cerr" to "OS" stream to be consistent with the other
  outputs in the method.

llvm-svn: 39483
2007-05-23 08:04:21 +00:00
Bill Wendling f06487034e Bug #:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner

- Comment fix.

llvm-svn: 39482
2007-05-23 08:03:10 +00:00
Steve Naroff 7fd6893333 Bug #:
Submitted by:
Reviewed by:
One bug compiling "Carbon.h" on Leopard, one diagnostic tweak.
- CheckIndirectionOperand wasn't operating on the canonical type (so it
was complaining about typedef names).
- The diagnostic was less than great. Here's what is was:

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c
t.c:4:3: error: invalid argument type to unary expression 'int'
 *p;
 ^~

And here's what I changed it to...

snaroff:clang naroff$ ../../Debug/bin/clang bug.c
bug.c:5:3: error: indirection requires a pointer ('int' operand invalid)
  *p;
  ^~

llvm-svn: 39481
2007-05-22 18:27:41 +00:00
Steve Naroff 21d5e87a97 Bug #:
Submitted by:
Reviewed by:
Add Makefile

llvm-svn: 39480
2007-05-22 17:43:50 +00:00
Chris Lattner 245368ee0f clarify library organization, document libast/libsema
llvm-svn: 39479
2007-05-21 17:47:42 +00:00
Chris Lattner a8a2c82f55 Move ASTStreamer.h into "clang/Sema/ASTStreamer.h"
llvm-svn: 39478
2007-05-21 17:38:36 +00:00
Chris Lattner d1654ef0ed Split the AST library into two libraries: libast and libsema.
llvm-svn: 39477
2007-05-21 17:34:19 +00:00
Chris Lattner e6b0f626bb minor simplification
llvm-svn: 39476
2007-05-21 05:58:35 +00:00
Chris Lattner 0643041f6c In the yet-another-crazy-idea department, we now print the actual *value* of
integer constants, whoa! :)

llvm-svn: 39475
2007-05-21 05:45:03 +00:00
Chris Lattner de5a472e02 Fix a problem where a semantic error confused error recovery to the point
where the parser emitted bogus diagnostics.  Before, when compiling:

  struct A { int X; } someA;

  int func(int, struct A);

  int test1(void *P, int C) {
    return func(((C*40) + *P) / 42+P, someA);
  }

we emitted:

bug3.c:7:25: error: invalid operands to binary expression ('int' and 'void')
    return func(((C*40) + *P) / 42+P, someA);
                 ~~~~~~ ^ ~~
bug3.c:7:31: error: expected ')'
    return func(((C*40) + *P) / 42+P, someA);
                              ^
bug3.c:7:16: error: to match this '('
    return func(((C*40) + *P) / 42+P, someA);
               ^

now we only emit the first.

llvm-svn: 39474
2007-05-21 05:27:47 +00:00
Chris Lattner 67ca9252f8 Implement Sema::ParseNumericConstant for integer constants in terms of APInt
and correctly in terms of C99 6.4.4.1p5.

llvm-svn: 39473
2007-05-21 01:08:44 +00:00
Chris Lattner 4dc8a6f1e7 add ASTContext::getIntegerBitwidth method.
llvm-svn: 39472
2007-05-20 23:50:58 +00:00
Chris Lattner f59d75c35e add getIntegerBitwidth method.
llvm-svn: 39471
2007-05-20 23:50:29 +00:00
Chris Lattner dae7f8ddf4 add interfaces to get sizes of target integer types.
llvm-svn: 39470
2007-05-20 23:50:03 +00:00
Chris Lattner 073926e39a pretty print switch/if stmts whose bodies are compound stmts.
llvm-svn: 39469
2007-05-20 23:04:55 +00:00
Chris Lattner b9eb5a1cec Pretty print labels and case stmts better. This leads to output like this:
void foo() {
abc:
def:
hij:
case 1:
case 1:
  goto abc
baz:
  goto def
}

instead of:

void foo() {
  abc:
    def:
      hij:
        case 1:
          case 1:
            goto abc
  baz:
    goto def
}

llvm-svn: 39468
2007-05-20 22:52:15 +00:00
Chris Lattner 3bbe7bed39 Don't "optimize" empty or unit compound exprs away.
llvm-svn: 39467
2007-05-20 22:47:04 +00:00
Steve Naroff 30d1fbc803 Bug #:
Submitted by:
Reviewed by:
Bozo bug in last checkin. Needed to move the check for null pointers
up (and out of the pointer/pointer clause).

llvm-svn: 39466
2007-05-20 19:46:53 +00:00
Chris Lattner 5ab15f154d Steve pointed out that testcases like this (with a macro expansion):
#define friendlystruct fs

  struct A { int X; };

  void test2(struct A friendlystruct, int C) {
    return friendlystruct + (C     *40);
  }

were getting diagnosed like this:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~             ^ ~~~~~~~~~~~

The problem is that getCharacterData returns a pointer to the macro expansion,
not to the macro instantiation.  Instead, use getLogicalLoc to get a pointer
to the instatiation location, so we relex the macro id.  We now get:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

oooh ahh. :)

llvm-svn: 39465
2007-05-20 18:08:36 +00:00
Steve Naroff ada7d4298b Bug #:
Submitted by:
Reviewed by:
Fix two bugs...

- Sema::CheckConditionalOperands(). Needed to move the check for
null pointer constants up to the clause dealing with two pointers types.
The previous code would never get executed.
- Expr::isNullPointerConstant(). This predicate was much too naive...it
should have had a FIXME (my bad). It now deals with "void *" cast expressions.
It still has one major bug...it needs to evaluate the expression to correctly
determine if it is a null pointer constant (e.g. 7-7 should pass).

llvm-svn: 39464
2007-05-20 17:54:12 +00:00
Chris Lattner 812eda8259 implement octal escape sequences.
llvm-svn: 39463
2007-05-20 05:17:04 +00:00
Chris Lattner c10adde406 Implement hex escape sequences in string and character literals, e.g. L"\x12345"
llvm-svn: 39462
2007-05-20 05:00:58 +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
Chris Lattner beeb9bc51d improve const correctness
llvm-svn: 39460
2007-05-19 08:07:42 +00:00
Chris Lattner ebd1b33477 Use the new source ranges tracking feature to highlight the important pieces
of a subexpression when emitting a diagnostic.  Consider this example:

struct A { int X; };

void test1(void *P, int C) {
  return ((C*40) + *P) / 42+P;
}

void test2(struct A friendlystruct, int C) {
  return (C     *40) + friendlystruct;
}

void test3(struct A friendlystruct, int C) {
  return friendlystruct + test2(friendlystruct
                               , C);
}


clang now produces this output:

t.c:4:18: error: invalid operands to binary expression ('int' and 'void')
  return ((C*40) + *P) / 42+P;
          ~~~~~~ ^ ~~

This shows the important pieces of a nested (and potentially very complex)
expression.


t.c:8:18: error: invalid operands to binary expression ('int' and 'struct A')
  return (C     *40) + friendlystruct;
         ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

This shows that tabs in source files (after the 'C') and multichar tokens
(friendlystruct) are handled correctly.



t.c:12:25: error: invalid operands to binary expression ('struct A' and 'void')
  return friendlystruct + test2(friendlystruct
         ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~

This shows how multiline ranges are printed.  Any part of the range that is
not on the same line as the carat is just ignored.  This also shows that
trailing spaces on the line aren't highlighted.

llvm-svn: 39459
2007-05-19 08:06:14 +00:00
Chris Lattner f8d3197831 Change the structure of the code that emits the ^ marker in a diagnostic,
but there is no functionality change yet.

llvm-svn: 39458
2007-05-19 07:25:55 +00:00
Chris Lattner 84e160a7a8 fix some indentation funkiness
llvm-svn: 39457
2007-05-19 07:03:17 +00:00
Steve Naroff 71ce2e061d Bug #:
Submitted by:
Reviewed by:
An important, but truly mind numbing change.

Added 6 flavors of Sema::Diag() that take 1 or two SourceRanges. Considered
adding 3 flavors (using default args), however this wasn't as clear.

Removed 2 flavors of Sema::Diag() that took LexerToken's (they weren't used).

Changed all the typechecking routines to pass the appropriate range(s).

Hacked the diagnostic machinery and driver to acccommodate the new data.

What's left? A FIXME in clang.c to use the ranges. Chris offered to do the
honors:-) Which includes taking us to the end of an identifier:-)

llvm-svn: 39456
2007-05-18 22:53:50 +00:00
Steve Naroff e845e272ba Bug #:
Submitted by:
Reviewed by:
More tweaks to error diagnostics (adding types, using the new hooks on expr).
Still more to do...

llvm-svn: 39455
2007-05-18 01:06:45 +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 53f07dc54d Bug #:
Submitted by:
Reviewed by:
Refinements to the SourceRange/SourceLocation work.

- Renamed Expr::getSourceLocation() helper function to getLocStart(). Added
Expr::getLocEnd(). Converted all the getSourceRange() methods to use the new helpers.
- Removed many getSourceLocation() accessors. The Expr::getLocStart() helper
is the "right" way to get a source location. If we want to add class specific
getters (for location), then the names should be reflective of the specific class.
For examaple, UnaryOperator::getOpLocation(). For now, I see no reason to have these.
- Fixed StringLiteral.
- Start actually instantiating ParenExpr()!

llvm-svn: 39453
2007-05-17 21:49:33 +00:00
Steve Naroff 509fe025aa Bug #:
Submitted by:
Reviewed by:
- Added a getSourceRange() method to all subclasses of Expr.
- Changed all the constructors and instantiators.
- Only added SourceLocations's when necessary. For example, binary
expression *don't* carry the operator location...it isn't
necessary to implement getSourceRange(). On the other hand, unary
expressions *do* carry the operator location.
- Added trivial SourceRange value class to SourceLocation.

Note: need to talk to Chris about the FIXME for StringLiteral...
llvm-svn: 39452
2007-05-17 01:16:00 +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 c04bd6ae32 Remove the Sema::Diag helper that takes a type. Convert clients to use
the version that takes a string.

llvm-svn: 39450
2007-05-16 18:09:54 +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
Chris Lattner d6647d3d60 Add helper to emit two strings for a diagnostic.
llvm-svn: 39448
2007-05-16 17:56:50 +00:00
Chris Lattner 36982e4367 Add support for inserting up to 10 strings in a diagnostic, with %0, %1, %2,
etc.

llvm-svn: 39447
2007-05-16 17:49:37 +00:00
Steve Naroff f8a28c5379 Bug #:
Submitted by:
Reviewed by:
- Unified isConstantExpr/isIntegerConstantExpr by creating a private function
named isConstantExpr (that takes a bool to indicate the flavor). isConstantExpr
and isIntegerConstantExpr are now inline wrapper/helper functions.
- Fixed bug in expression based sizeof (it needed to make sure the type is constant).
- Added Sema::CheckConditionalOperands() stub. Will add contraints in my next commit.

llvm-svn: 39446
2007-05-15 20:29:32 +00:00
Steve Naroff 043d45da72 Bug #:
Submitted by:
Reviewed by:
- Completed Expr::isConstantExpr() and Expr::isIntegerConstantExpr().
- Completed Sema::ParseUnaryOp(), it lacked support for sizeof/alignof.
- Added Sema::CheckSizeOfAlignOfOperand(), used by ParseUnaryOp/ParseSizeOfAlignOfTypeExpr.
- Fixed a couple bugs in CheckRelationalOperands/CheckEqualityOperands (make sure extensions aren't treated as errors).
- Changed a bunch of predicates (in BinaryOperator/UnaryOperator) to member functions (the static members weren't being used).
- Added UnaryOperator::isIncrementDecrementOp/isSizeOfAlignOfOp.

llvm-svn: 39445
2007-05-15 02:32:35 +00:00
Steve Naroff 5dd642eb4a Bug #:
Submitted by:
Reviewed by:
Some minor cleanup (comments, spec refs, simplied some expressions).

llvm-svn: 39444
2007-05-14 18:14:51 +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 094046fdfc Bug #:
Submitted by:
Reviewed by:
Two bug fixes to CheckIncrementDecrementOperand:
- removed "constantOne" usage and simply use Context.IntTy.
- fix the last constraint check...the lvalue test needs to be on the
expression, not the type! (duh).

llvm-svn: 39442
2007-05-13 03:21:25 +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 b8c289df7a Bug #:
Submitted by:
Reviewed by:
Fix a couple bugs in ParseCallExpr().
- check isVariadic().
- make sure an AST isn't created if the number of args don't match but the
types do!
- rename "n" to something more descriptive:-)

llvm-svn: 39438
2007-05-08 22:18:00 +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 6396921550 Bug #:
Submitted by:
Reviewed by:
Start work on typechecking constant expressions.

- Added isIntegerConstantExpr() predicate to all exprs.
- Use the predicate to implement checking for enum constant initializers.
- Added diagnostic.
- Added Init slot to EnumConstantDecl class/constructor.

llvm-svn: 39436
2007-05-07 21:22:42 +00:00
Steve Naroff 35d8515be7 Bug #:
Submitted by:
Reviewed by:
- Unified CheckSimpleAssignmentOperands/CheckCompoundAssignmentOperands
into one function, named CheckAssignmentOperands. One less function to maintain.
- Converted the unary check functions (ParseUnaryOp and friends) to have
the same API as their binary counterparts.
- Implemented CheckIndirectionOperand (was stubbed). While testing, noticed
that Expr::isModifiableLvalue was incomplete (fixed and referenced draft).
- Added constantOne instance variable to Sema.
- Removed CheckArithmeticOperand (the code was so simple that it is now
part of ParseUnaryOp). The name wasn't great anyway:-)

llvm-svn: 39435
2007-05-07 00:24:15 +00:00