Commit Graph

1761 Commits

Author SHA1 Message Date
Ted Kremenek 25fb681907 Added support for comma expressions and DeclStmts which may have
arbitrarily complex control-flow in their subexpressions.

llvm-svn: 41547
2007-08-28 18:14:37 +00:00
Ted Kremenek e07a8cd7ff Fixed return-of-stack-address checker to correctly handle stack/global
variables that have a pointer type, or arrays that contain pointers.

This fixes a crash on the following code:

int *h[3];

int **foo(int i)
{
   return &(h[i]);
}

This bug was reported by Keith Bauer (thanks!).

llvm-svn: 41546
2007-08-28 17:02:55 +00:00
Chris Lattner 35da3e29dd extwarn about VLAs in C89 mode.
llvm-svn: 41545
2007-08-28 16:54:00 +00:00
Chris Lattner 8ed218afb9 c++'0x has long long also.
llvm-svn: 41544
2007-08-28 16:41:29 +00:00
Chris Lattner f2c338b7d1 warn about long long when in c89 mode.
llvm-svn: 41543
2007-08-28 16:40:32 +00:00
Steve Naroff 4ca5d5a9e8 Tweak declaration...
llvm-svn: 41542
2007-08-28 16:31:47 +00:00
Chris Lattner 613cef84b4 new testcase
llvm-svn: 41541
2007-08-28 16:20:14 +00:00
Ted Kremenek 91e8d2a974 Removed special-casing in CFG construction for ParenExprs.
llvm-svn: 41540
2007-08-28 16:18:58 +00:00
Chris Lattner c4f6d0c5cf fix 80 col violation
llvm-svn: 41533
2007-08-28 06:17:15 +00:00
Chris Lattner b8a501ccf1 compute the required destination type for an enum, emitting various warnings.
TODO: update the types of the constants and the enum.
llvm-svn: 41532
2007-08-28 06:15:15 +00:00
Chris Lattner d0e7ed3f2c remove dead method.
llvm-svn: 41531
2007-08-28 05:56:37 +00:00
Chris Lattner bf478cbef2 add a diagnostic:
t.c:1:12: warning: ISO C restricts enumerator values to range of 'int' (180388626432 is too large)
enum e {A, B = 42LL << 32, C = -4, D = 12456 };
           ^

llvm-svn: 41530
2007-08-28 05:27:00 +00:00
Chris Lattner 67933c0aae move a todo
llvm-svn: 41528
2007-08-28 05:10:31 +00:00
Chris Lattner 39f920f35b now that all the infrastructure is in place, enforce C99 6.8.5p3.
Note the FIXME: we need some way to mark a decl erroneous :)

llvm-svn: 41524
2007-08-28 05:03:08 +00:00
Chris Lattner 773c0596b8 If the condition of a for statement is promoted, make sure the
implicit cast gets linked back into the AST.

llvm-svn: 41523
2007-08-28 04:55:47 +00:00
Steve Naroff 7e6f7c25bf Implement more thoughful error recovery when dealing with bogus declarator types.
For example, the following code was resulting in spurious warnings. This was the result of
Sema::GetTypeForDeclarator() synthesizing a type to hand back to the caller (in this case,
"int []", instead of "struct s[]", which is invalid).

struct s; 
struct s* t (struct s z[]) {   // expected-error {{array has incomplete element type}}
  return z;
}

Strategy: Flag the error in Declarator/DeclaratorChunk. This info is later stored in 
the ParmVarDecl. If the decl is referenced, Sema::ParseIdentifierExpr() will check if 
the type is invalid. If so, it quietly returns "true", without instantiating a DeclRefExpr.

This seems to work nicely. If Chris is happy with the approach, I will generalize this to
all VarDecls.

llvm-svn: 41521
2007-08-28 03:03:08 +00:00
Ted Kremenek 12687ff9b8 Added support for short-circuit '&&' and '||' operators in source-level CFGs.
llvm-svn: 41520
2007-08-27 21:54:41 +00:00
Steve Naroff a042db2b80 Some minor aesthetic changes to the control flow.
llvm-svn: 41517
2007-08-27 21:43:43 +00:00
Steve Naroff e31313d792 Fix remaining bugs with complex/float promotions.
llvm-svn: 41515
2007-08-27 21:32:55 +00:00
Ted Kremenek 9e248870e5 Implemented support for ternary "?" operators in source-level CFGs.
llvm-svn: 41514
2007-08-27 21:27:44 +00:00
Chris Lattner 0515e4b26a Fix a few enum-related fixme's
llvm-svn: 41513
2007-08-27 21:16:18 +00:00
Ted Kremenek 251c9544e8 Fixed bug in child_begin/child_end for CallExpr where we incorrectly calculated a Stmt** pointer
based on an offset within SubExprs.

llvm-svn: 41512
2007-08-27 21:11:44 +00:00
Ted Kremenek 5b3ed283f5 Fixed bug in child_begin/child_end for ReturnStmt where the iterator
would be invalid when RetValExp == NULL.

llvm-svn: 41511
2007-08-27 20:58:16 +00:00
Ted Kremenek 81e1485d4c Changes to CFGBuilder:
+ Added the creation of an empty Entry block at the end of CFG
  construction if the Entry block in the CFG contains multiple
  predecessors (which can happen with labels and do loops).

+ Fixed bug in the creation of an empty Exit block with functions where not
  all paths end in a return statement (but some do).  Basic blocks with
  return statements were jumping to a (sometimes) non-empty block.

+ FinishBlock no longer checks for labels at the beginning of a basic
  block before reversing the statements in the block.  This is because
  the recursion invariants of the builder methods have been cleaned up,
  and blocks are only passed to FinishBlock at most once.

+ Modified handling of "if", "for", "while", "do", and "switch" to allow
  condition expressions that can span multiple basic blocks.  This allows
  such conditions to contain short-circuit expressions (which span multiple
  blocks in the CFG).

llvm-svn: 41508
2007-08-27 19:46:09 +00:00
Chris Lattner 8f63b9d534 constify some stuff
llvm-svn: 41503
2007-08-27 17:56:57 +00:00
Chris Lattner 304ff47b1a teach codegen to lay out enum types.
llvm-svn: 41501
2007-08-27 17:44:34 +00:00
Chris Lattner a9e7961a44 implement sizeof(enum x), patch inspired by Keith Bauer.
llvm-svn: 41500
2007-08-27 17:38:00 +00:00
Chris Lattner f283a37179 better error recovery for non-i-c-e enum constants.
llvm-svn: 41499
2007-08-27 17:37:24 +00:00
Chris Lattner 37256fbdec C++ allows empty enum list.
llvm-svn: 41498
2007-08-27 17:24:30 +00:00
Chris Lattner 1c14d71010 add some accessors.
llvm-svn: 41496
2007-08-27 16:50:56 +00:00
Chris Lattner db37c8391c Add enum type conversion policies, patch by Keith Bauer
llvm-svn: 41495
2007-08-27 16:48:59 +00:00
Ted Kremenek d11e460810 Updated checker for "return of address of stack variable" to look for
implicit casts from T to T& at the topmost part of the return-value expression.

This checking may be needed within EvalAddr later on.  We'll wait until
test cases show this kind of logic is necessary (as more C++ features are
implemented in clang).

llvm-svn: 41493
2007-08-27 16:39:17 +00:00
Chris Lattner 23bf38b8c5 add some more testcases now that sema is happier :)
llvm-svn: 41492
2007-08-27 16:37:44 +00:00
Steve Naroff 7af82d462a Replaced ASTContext::maxFloatingType() with ASTContext::compareFloatingType().
Changed Sema::UsualArithmeticConversions to use the new API.

This fixes the following case...

_Complex double X;
double y;

void foo() {
  X = X + y;
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -parse-ast-dump
Read top-level variable decl: 'X'
Read top-level variable decl: 'y'

void foo()
(CompoundStmt 0x2605cc0
  (BinaryOperator 0x2605ca0 '_Complex double' '='
    (DeclRefExpr 0x2605c10 '_Complex double' Decl='X' 0x2605ab0)
    (BinaryOperator 0x2605c80 '_Complex double' '+'
      (DeclRefExpr 0x2605c30 '_Complex double' Decl='X' 0x2605ab0)
      (ImplicitCastExpr 0x2605c70 '_Complex double'
        (DeclRefExpr 0x2605c50 'double' Decl='y' 0x2605ae0)))))

llvm-svn: 41483
2007-08-27 15:30:22 +00:00
Chris Lattner 61f6077814 testcase that doesn't work quite yet
llvm-svn: 41478
2007-08-27 05:23:45 +00:00
Chris Lattner d864daf5c6 extwarn about decls intermixed with code in c89 mode.
llvm-svn: 41477
2007-08-27 04:29:41 +00:00
Steve Naroff 808eb8fe88 Add Type::getAsBuiltinType() and Type::builtinTypesAreCompatible().
Modified Type::typesAreCompatible() to use the above.

This fixes the following bug submitted by Keith Bauer (thanks!).

int equal(char *a, const char *b)
{
    return a == b;
}

Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).

llvm-svn: 41476
2007-08-27 04:08:11 +00:00
Steve Naroff fc6ffa2513 Tweak a comment and assert.
llvm-svn: 41475
2007-08-27 01:41:48 +00:00
Steve Naroff 9091ef703c Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions, 
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().

llvm-svn: 41474
2007-08-27 01:27:54 +00:00
Chris Lattner dfaf9f8c2f implement a fixme: __extension__ marker on decls in compound stmts.
llvm-svn: 41473
2007-08-27 01:01:57 +00:00
Chris Lattner bda69f80bc move EmitAggregateCopy into AggExprEmitter
llvm-svn: 41472
2007-08-26 23:13:56 +00:00
Chris Lattner 2dd1b72bde Fix test/Parser/if-scope-*.c. Patch by Neil Booth!
llvm-svn: 41471
2007-08-26 23:08:06 +00:00
Chris Lattner c1045b1a69 remove dead code
llvm-svn: 41470
2007-08-26 23:02:57 +00:00
Chris Lattner 1916b88723 remove dead protos
llvm-svn: 41469
2007-08-26 23:01:23 +00:00
Chris Lattner 6c555f96e8 eliminate EmitAnyExpr, inlining it and simplifying it into its only caller.
llvm-svn: 41468
2007-08-26 22:58:05 +00:00
Chris Lattner a811da5fcd eliminate use of EmitAnyExpr.
llvm-svn: 41467
2007-08-26 22:55:13 +00:00
Chris Lattner a8d8b71680 implement a fixme
llvm-svn: 41466
2007-08-26 22:47:40 +00:00
Chris Lattner 02aac86549 new testcases
llvm-svn: 41465
2007-08-26 22:41:57 +00:00
Chris Lattner e56d3e1a23 Implement compound assignment operators whose LHS is scalar but RHS is complex.
llvm-svn: 41464
2007-08-26 22:37:40 +00:00
Chris Lattner 624e6d0c68 implement codegen of compound assignment operators for complex.
llvm-svn: 41463
2007-08-26 22:09:01 +00:00
Chris Lattner 6d7b404d08 If a visitor doesn't define VisitBinMulAssign, fallback to VisitCompoundAssignOperator
instead of VisitBinaryOperator.

llvm-svn: 41462
2007-08-26 22:08:29 +00:00
Chris Lattner b633469e02 compound assignment operators are of type CompoundAssignOperator
llvm-svn: 41460
2007-08-26 21:41:21 +00:00
Chris Lattner d65598daa3 dispatch to functions like VisitBinRemAssign with knowledge that
the operand is of type CompoundAssignOperator, not just BinaryOperator.

llvm-svn: 41459
2007-08-26 21:40:28 +00:00
Chris Lattner 2c666fa40d update fixme's
llvm-svn: 41458
2007-08-26 21:27:07 +00:00
Chris Lattner 6f672c150c implement complex division
llvm-svn: 41457
2007-08-26 21:24:19 +00:00
Chris Lattner dd9a319158 Add isysroot support, patch by Keith Bauer
llvm-svn: 41455
2007-08-26 17:47:35 +00:00
Chris Lattner 0c6aad373f Fix %p format checking, patch by Keith Bauer.
llvm-svn: 41454
2007-08-26 17:39:38 +00:00
Chris Lattner 0d850bfed8 For warnings like this:
t.c:3:9: warning: invalid conversion '%B'
printf("%B\a\n", p);
~~~~~~  ^

Don't beep the console or print the newline.

llvm-svn: 41453
2007-08-26 17:38:22 +00:00
Chris Lattner 9decfbabd3 Fix a bug reported by Keith Bauer
llvm-svn: 41452
2007-08-26 17:32:59 +00:00
Chris Lattner 2e928885b2 fix a typo noticed by Gordon Henriksen
llvm-svn: 41451
2007-08-26 17:25:57 +00:00
Chris Lattner c3b3707536 llvmgcc is right :)
llvm-svn: 41450
2007-08-26 16:54:05 +00:00
Chris Lattner 183c231cf9 compound assignmetns work for scalars.
llvm-svn: 41449
2007-08-26 16:52:57 +00:00
Chris Lattner c141c1b390 implement conversions of complex to bool.
llvm-svn: 41448
2007-08-26 16:52:28 +00:00
Chris Lattner 268fcce4f0 remove ConvertScalarValueToBool.
llvm-svn: 41447
2007-08-26 16:46:58 +00:00
Chris Lattner e004438f4a reimplement ConvertScalarValueToBool in CGExprScalar.cpp
llvm-svn: 41446
2007-08-26 16:42:57 +00:00
Chris Lattner 42e6b8150a refactor some code to expose compex->scalar conversion to CGF
llvm-svn: 41445
2007-08-26 16:34:22 +00:00
Chris Lattner b84bb95b44 be slightly more volatile correct
llvm-svn: 41444
2007-08-26 16:22:13 +00:00
Steve Naroff 5f90ca9904 Fix bogus warnings (noticed by Chris) with array-constraints.c.
Remove bogus type conversions in Sema::GetTypeForDeclarator(). This commit
only deals with the array types (DeclaratorCheck::Array), though the
rest of this routine should be reviewed. Given the complexity of C declarators,
I don't want to change the entire routine now (will discuss with Chris tomorrow).

llvm-svn: 41443
2007-08-26 14:38:38 +00:00
Chris Lattner f6dcc9df7e these fixme's are easy :)
llvm-svn: 41442
2007-08-26 07:30:49 +00:00
Chris Lattner b753f66339 implement a fixme, add a couple more :)
llvm-svn: 41441
2007-08-26 07:29:23 +00:00
Chris Lattner 5de3b174c8 there are no conversions from aggregates to scalars.
llvm-svn: 41440
2007-08-26 07:26:12 +00:00
Chris Lattner 08c611e4dc implement conversions from complex to scalar types.
llvm-svn: 41439
2007-08-26 07:21:11 +00:00
Chris Lattner 46c7161311 Omit EmitConversion
llvm-svn: 41438
2007-08-26 07:16:41 +00:00
Chris Lattner 45067906ad Fix return of aggregate and return of complex.
llvm-svn: 41437
2007-08-26 07:14:44 +00:00
Chris Lattner 44d3e74e22 these implicit conversions are now explicit :)
llvm-svn: 41436
2007-08-26 07:09:42 +00:00
Chris Lattner cf3da8495a remove uses of EmitConversion
llvm-svn: 41435
2007-08-26 07:08:39 +00:00
Chris Lattner 798da7033f implicit casts take care of this code, remove it now.
llvm-svn: 41434
2007-08-26 07:06:24 +00:00
Chris Lattner 3474c202ab refactor scalar conversions out into CGExprScalar.cpp
llvm-svn: 41433
2007-08-26 06:48:56 +00:00
Chris Lattner e026ebd6fe steve's recent changes fixed this bogus warning.
llvm-svn: 41432
2007-08-26 06:48:28 +00:00
Chris Lattner 1a76a3c970 Break the assumption that any sort of scope (e.g. a loop scope) can
hold declarations.  Instead, introduce a new "DeclScope" scope type that
holds them explicitly.  For now, all scopes have this bit, but in the 
future we can use them to fix some issues Neil noticed.

llvm-svn: 41431
2007-08-26 06:24:45 +00:00
Chris Lattner 88078594fc remove some dead enum values.
llvm-svn: 41430
2007-08-26 06:03:04 +00:00
Chris Lattner 7460f9620c Implement casts from scalar -> complex and complex->complex.
llvm-svn: 41429
2007-08-26 05:57:57 +00:00
Chris Lattner e267f5d2f7 require that operands to __real/__imag are complex or arithmetic. This
fixes GCC PR33193

llvm-svn: 41428
2007-08-26 05:39:26 +00:00
Chris Lattner b5e1262437 implement codegen of __imag of a scalar. Our impl doesn't suffer from
GCC bug PR33192.

llvm-svn: 41427
2007-08-26 05:29:21 +00:00
Chris Lattner 9de9527ad6 Make initialization of complex vars work.
llvm-svn: 41426
2007-08-26 05:13:54 +00:00
Chris Lattner a01d898ff5 fix codegen of pre/post inc/dec of a pointer.
llvm-svn: 41425
2007-08-26 05:10:16 +00:00
Chris Lattner c7f06ca780 tolerate unimplemented codegen better
llvm-svn: 41424
2007-08-26 05:06:40 +00:00
Chris Lattner e7a160b37d int X[] isn't a VLA. This improves support for stdio.h on darwin.
llvm-svn: 41423
2007-08-26 05:02:07 +00:00
Neil Booth cd995b0b4a Make some diags EXTENSION so they are errors with pedantic errors
llvm-svn: 41422
2007-08-26 05:01:15 +00:00
Chris Lattner 57c269b5d3 implement rudimentary union layout support.
llvm-svn: 41421
2007-08-26 04:50:19 +00:00
Chris Lattner 5e75e8bc71 Why didn't gcc catch this? :(
llvm-svn: 41420
2007-08-26 04:42:42 +00:00
Chris Lattner 881440f5d2 Don't make unknown builtins fatal errors yet.
llvm-svn: 41419
2007-08-26 04:17:05 +00:00
Chris Lattner c5221650b3 remove a bunch of dead code
llvm-svn: 41418
2007-08-26 04:13:58 +00:00
Chris Lattner 71236d0485 fix a bug introduced by the recent childification of ForStmt.
llvm-svn: 41417
2007-08-26 04:11:23 +00:00
Chris Lattner b677a9398a Make parse-ast-print print the storage class and inline
specifier of functions.

llvm-svn: 41416
2007-08-26 04:02:13 +00:00
Chris Lattner 1c72d77d01 null pointers don't get an extra newline.
llvm-svn: 41415
2007-08-26 03:53:29 +00:00
Chris Lattner 0fffcb5b28 implement codegen for complex literals.
llvm-svn: 41414
2007-08-26 03:51:12 +00:00
Chris Lattner 1c20a170c0 add a new ImaginaryLiteral AST node that is used to
represent imaginary literals:

float _Complex A;
void foo() {
  A = 1.0iF;
}

generates:

  (BinaryOperator 0x2305ec0 '_Complex float' '='
    (DeclRefExpr 0x2305e60 '_Complex float' Decl='A' 0x2305cf0)
    (ImaginaryLiteral 0x2305f40 '_Complex float'
      (FloatingLiteral 0x2305ea0 'float' 1.000000))))

llvm-svn: 41413
2007-08-26 03:42:43 +00:00
Chris Lattner ed045421a8 1.0 is double, 1.0F is a float.
llvm-svn: 41412
2007-08-26 03:29:23 +00:00
Chris Lattner f55ab18663 1) refactor some code.
2) Add support for lexing imaginary constants (a GCC extension):

t.c:5:10: warning: imaginary constants are an extension
  A = 1.0iF;
         ^

3) Make the 'invalid suffix' diagnostic pointer more accurate:

t.c:6:10: error: invalid suffix 'qF' on floating constant
  A = 1.0qF;
         ^

instead of:

t.c:6:10: error: invalid suffix 'qF' on floating constant
  A = 1.0qF;
      ^

llvm-svn: 41411
2007-08-26 01:58:14 +00:00