Commit Graph

1968 Commits

Author SHA1 Message Date
Ted Kremenek b56a990955 Added an early implementation of Live-Variables analysis built on
source-level CFGs.  This code may change significantly in the near
future as we explore different means to implement dataflow analyses.

Added a driver option, -dump-live-variables, to view the output of
live variable analysis.  This output is very ALPHA; it will be improved shortly.

llvm-svn: 41737
2007-09-06 00:17:54 +00:00
Chris Lattner 542a440062 remove the FATAL classifier.
llvm-svn: 41736
2007-09-06 00:16:35 +00:00
Chris Lattner aa4b29c52b remove sorry.
llvm-svn: 41734
2007-09-06 00:14:09 +00:00
Steve Naroff ca85d1dc07 Start implementing Actions interface for ObjC classes, instance variables, and methods.
Lot's of small changes to the parser.

llvm-svn: 41732
2007-09-05 23:30:30 +00:00
Fariborz Jahanian bd25f7d4a5 Patch for parsing objective-c style method calls.
llvm-svn: 41731
2007-09-05 23:08:20 +00:00
Ted Kremenek 813dd67a34 Moved tracking of CFG block IDs into the CFG class.
Added CFG::getNumBlockIDs() to query the number of distinct block ids created.

llvm-svn: 41724
2007-09-05 20:02:05 +00:00
Fariborz Jahanian 7db004df78 1. Fix parsing of method prototype involving c-style argument declarations.
2. Fixes all allowable key-words used as selectors.
3. Template to do the messaging parse.
4. A test case for all allowable selector names.

llvm-svn: 41723
2007-09-05 19:52:07 +00:00
Fariborz Jahanian 7eccba3b8e Fixed a typo pointed out by Anders Calrsson.
llvm-svn: 41716
2007-09-04 21:42:12 +00:00
Steve Naroff 67ae443954 Simplified initializer semantic analysis by adding the following 2 methods:
- ArrayType::getBaseType(), and 
- ConstantArrayType::getMaximumElements().

Wanted to do this cleanup before adding structure support, which will add more complexity.

llvm-svn: 41715
2007-09-04 21:13:33 +00:00
Fariborz Jahanian d8e12d3df3 Patch to parse objective-c's @compatibility_alias directive.
llvm-svn: 41709
2007-09-04 19:26:51 +00:00
Hartmut Kaiser db48641837 Updated VC8 project files.
llvm-svn: 41707
2007-09-04 19:06:30 +00:00
Ted Kremenek c81587d240 Updated calls to CreateGEP to new interface in LLVM mainline.
llvm-svn: 41704
2007-09-04 17:20:08 +00:00
Chris Lattner 73ab7fa9c6 disable this for now.
llvm-svn: 41701
2007-09-04 16:49:09 +00:00
Steve Naroff 77b97002e9 Make sure initializer type promotions get propagated.
This fixes a recent regression with Codegen/mandel.c.

llvm-svn: 41696
2007-09-04 14:36:54 +00:00
Chris Lattner 7717c56b4f updates (?) to the vc++ files, patch by Hartmut Kaiser
llvm-svn: 41695
2007-09-04 02:46:31 +00:00
Chris Lattner 0dc165b5f1 silence VC++ warnings, patch by Hartmut Kaiser
llvm-svn: 41694
2007-09-04 02:46:00 +00:00
Chris Lattner 9cf21c5a2c Silence VC++ warnings, patch by Hartmut Kaiser
llvm-svn: 41693
2007-09-04 02:45:27 +00:00
Chris Lattner fb2eb6941a eliminate some VC++ warnings, patch contributed by Hartmut Kaiser
llvm-svn: 41692
2007-09-04 02:34:27 +00:00
Chris Lattner e15fa6c89c add a VC++ solution file, contributed by Hartmut Kaiser
llvm-svn: 41691
2007-09-04 02:31:11 +00:00
Steve Naroff ac074b4df4 More fun with initializers!
- Fixed many bugs, enhanced test case considerably, added a diagnostic, etc.
- Refactored CheckInitList() into CheckVariableInitList()/CheckConstantInitList().
- Added CheckInitExpr().
- Support for multi-dimensional arrays looking good.

llvm-svn: 41690
2007-09-04 02:20:04 +00:00
Chris Lattner ff3fa8b624 VC++ doesn't define S_ISDIR
llvm-svn: 41688
2007-09-03 18:37:14 +00:00
Chris Lattner 1463cca1cc Add a method required by the VC++ STL, patch by Hartmut Kaiser!
llvm-svn: 41687
2007-09-03 18:31:57 +00:00
Chris Lattner a263393d11 Add #include required on win32.
llvm-svn: 41686
2007-09-03 18:30:32 +00:00
Chris Lattner 78b6221ff9 Eliminate some VC++ warnings, patch by Hartmut Kaiser!
llvm-svn: 41685
2007-09-03 18:28:41 +00:00
Chris Lattner cd1e8d2c9d Add #ifdefs to make the source portable to windows. Patch contributed
by Hartmut Kaiser!

llvm-svn: 41684
2007-09-03 18:24:56 +00:00
Chris Lattner 4d37b81df9 initial checkin of vc++ project files, contributed by
Hartmut Kaiser!

llvm-svn: 41683
2007-09-03 18:21:31 +00:00
Steve Naroff 7d2c5ed92e Finish getting "array-init.c" to work properly.
Array scalar initialization is now is reasonable shape.

Next step, structure and array of structure initializers.

llvm-svn: 41681
2007-09-03 01:24:23 +00:00
Steve Naroff b03f5940d1 More progress on array initializers.
- Added Expr::isConstantExpr().
- Added type checking for InitListExpr elements.
- Added diagnostic for trying to initialize a variable sized object.

llvm-svn: 41674
2007-09-02 20:30:18 +00:00
Steve Naroff f33527a1aa More semantic analysis of initializers.
Added 2 errors and one warning, updated test case.

llvm-svn: 41672
2007-09-02 15:34:30 +00:00
Steve Naroff 2fea13926f Start implementing semantic analysis for C initializers.
Step 1: Start instantiating InitListExpr's.
Step 2: Call newly added function Sema::CheckInitializer() from Sema::ParseDeclarator().
Step 3: Give InitListExpr's a preliminary type.
Step 4: Start emitting diagnostics for simple assignments.

Note:

As a result of step 1, the CodeGen/mandel.c test asserts "Unimplemented agg expr!", which is expected.

As a result of step 4, the test below now fails. This isn't expected and needs to be investigated (it appears type checking for C++ references is flawed in some way).

******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Command: 
 clang -fsyntax-only Sema/cxx-references.cpp
Output:
Sema/cxx-references.cpp:8:12: warning: incompatible pointer types assigning 'int &*' to 'int *'
  int *p = &r;
           ^~
Sema/cxx-references.cpp:10:20: error: incompatible types assigning 'int (int)' to 'int (&)(int)'
  int (&rg)(int) = g;
                   ^
Sema/cxx-references.cpp:13:18: error: incompatible types assigning 'int [3]' to 'int (&)[3]'
  int (&ra)[3] = a;
                 ^
Sema/cxx-references.cpp:16:14: error: incompatible types assigning 'int *' to 'int *&'
  int *& P = Q;
             ^
4 diagnostics generated.
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************

llvm-svn: 41671
2007-09-02 02:04:30 +00:00
Steve Naroff 42a350a18a Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt().

Now -parse-ast-dump will display source range info for all stmts/exprs.

One day we should implement the source range protocol for Decls.

llvm-svn: 41670
2007-09-01 21:08:38 +00:00
Fariborz Jahanian 53cacaec46 Patch to parse @implementation prologue, method definitions,
objc2's @synthesize and @dynamic.

llvm-svn: 41667
2007-09-01 00:26:16 +00:00
Steve Naroff dc9f36e6c4 Convert more statments over to SourceRanges...
llvm-svn: 41666
2007-08-31 23:49:30 +00:00
Steve Naroff 33f3d05081 Move SourceRange protocol from Expr->Stmt.
Converted many of the statements over. Still a hanful left...

llvm-svn: 41663
2007-08-31 23:28:33 +00:00
Chris Lattner 49e3bfa8a4 add stmtexpr support for aggregates
llvm-svn: 41662
2007-08-31 22:54:14 +00:00
Chris Lattner 1c3ad19714 add support for complex stmtexpr's
llvm-svn: 41661
2007-08-31 22:51:38 +00:00
Chris Lattner 4647a21825 Generalize RValue to handle complex better, generalize EmitCompoundStmt to
support any sort of expr, add a new EmitAnyExpr routine.

llvm-svn: 41660
2007-08-31 22:49:20 +00:00
Ted Kremenek cc778061e5 Fixed missing '(' and ')' characters in (CFG) pretty-printing of
statement expressions.

llvm-svn: 41659
2007-08-31 22:47:06 +00:00
Ted Kremenek 391f94a694 Added better pretty printing in CFGs for __builtin_choose_expr
llvm-svn: 41658
2007-08-31 22:29:13 +00:00
Ted Kremenek f8b50e91b7 Further cleanups in CFG printing for comma expressions, statement expressions, and indirect gotos.
llvm-svn: 41657
2007-08-31 22:26:13 +00:00
Chris Lattner 04a913b958 implement code generation for scalar stmt expressions.
llvm-svn: 41656
2007-08-31 22:09:40 +00:00
Chris Lattner cac27a5478 Fix a bug/missing-feature Ted noticed: the 'unused' warning should not
warn about the last stmt in a stmtexpr, f.e. there should be no warning for:

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

llvm-svn: 41655
2007-08-31 21:49:55 +00:00
Ted Kremenek 7f7dd7602c Cleanups for printing the terminators of CFGBlocks for "?", "||", and "&&" operators.
llvm-svn: 41654
2007-08-31 21:49:40 +00:00
Chris Lattner 78502cf4c9 diagnose extended uses of offsetof
llvm-svn: 41653
2007-08-31 21:49:13 +00:00
Chris Lattner 51728b7282 new diag
llvm-svn: 41652
2007-08-31 21:48:38 +00:00
Ted Kremenek 04f3cee11f Added "PrinterHelper" interface (include/AST/PrinterHelper) that can
be passed as an (optional) argument to StmtPrinter to customize
printing of AST nodes.

Used new PrinterHelper interface to enhance printing and visualization
of CFGs.  The CFGs now illustrate the semantic connectives between
statements and terminators, wheras in the previous printing certain
expressions would (visible) be printed multiple times to reflect which
expressions used the results of other expressions.

The end result is that the CFG is easier to read for flow of
expression values (following principles similar to the LLVM IR).

llvm-svn: 41651
2007-08-31 21:30:12 +00:00
Ted Kremenek bf57321068 Added #ifndef/#endif statements to protect the header from multiple inclusion.
llvm-svn: 41648
2007-08-31 17:53:25 +00:00
Steve Naroff 096dd942cf Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.

Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();

Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.

llvm-svn: 41647
2007-08-31 17:20:07 +00:00
Ted Kremenek 527ec81d8b Added support for __builtin_choose_expr (ChooseExpr) in CFGs.
llvm-svn: 41646
2007-08-31 17:03:41 +00:00
Fariborz Jahanian 9fca6dfad3 Author: F. Jahanian
Log:
Implement parsing of objective-c's new @property declaration.

Modified:
include/clang/Basic/DiagnosticKinds.def
include/clang/Parse/Parser.h
Parse/ParseObjc.cpp
Parse/Parser.cpp

llvm-svn: 41644
2007-08-31 16:11:31 +00:00
Chris Lattner 319079c003 don't turn semantic errors into parse errors.
llvm-svn: 41638
2007-08-31 05:01:50 +00:00
Chris Lattner c6c66c461f fix some memory leaks when recovering.
llvm-svn: 41637
2007-08-31 04:58:34 +00:00
Anders Carlsson 4692db0e7e Add InitListExpr class.
llvm-svn: 41636
2007-08-31 04:56:16 +00:00
Chris Lattner 57c523f50c add actions for deleting expr/stmt nodes.
llvm-svn: 41635
2007-08-31 04:53:24 +00:00
Chris Lattner 9e47ead594 Implement codegen support for lowering "library builtins" like __builtin_isinf
to their corresponding library routines (e.g. isinf).  This allows us to handle
all the stuff in macos math.h, and other stuff as it's added to *Builtins.def.

llvm-svn: 41634
2007-08-31 04:44:06 +00:00
Chris Lattner 1eec6601d9 add the ability to get the llvm function corresponding to a library builtin.
llvm-svn: 41633
2007-08-31 04:31:45 +00:00
Chris Lattner 7e2e459c48 add some accessors for querying attributes of builtins. Add the new 'F' attribute.
llvm-svn: 41631
2007-08-31 03:44:20 +00:00
Steve Naroff 43b8f7fa4f Sema::ParseCastExpr() missing call to UsualUnaryConversions().
The following case now works...

void empty(void * a ) {}

void test()
{
    unsigned char A[4]; 
    empty( (void *) A); 
}

Thanks to Patrick Flannery for finding this...

llvm-svn: 41630
2007-08-31 00:32:44 +00:00
Steve Naroff d57fa94148 Final phase of array cleanup (for now), removing a FIXME from yesterday.
Moved several array constraints checks from Sema::VerifyConstantArrayType() to
Sema::GetTypeForDeclarator(). VerifyConstantArrayType() is now very simple, and
could be removed eventually.

Now, we get the following (correct) messages for BlockVarDecls:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -pedantic
x.c:4:20: error: size of array has non-integer type 'float'
  int size_not_int[f];
                   ^
x.c:5:21: error: array size is negative
  int negative_size[1-2];
                    ^~~
x.c:6:17: warning: zero size arrays are an extension
  int zero_size[0];
                ^
3 diagnostics generated.

llvm-svn: 41624
2007-08-30 22:35:45 +00:00
Ted Kremenek fc7aafcef0 Minor cleanups to pretty-printing for loops in CFGs.
llvm-svn: 41623
2007-08-30 21:28:02 +00:00
Ted Kremenek 55e91e8bdd Fixed a bug in constructing CFG blocks for case statement fall-through
introduced by moving "CaseStmt" pointers out of the list of statements
and into the explicit "label" associated with a CFGBlock.  --This
line, and those below, will be ignored--

M    AST/CFG.cpp

llvm-svn: 41622
2007-08-30 18:48:11 +00:00
Steve Naroff 09b0fd24a7 Diff is self small & self explanatory...
llvm-svn: 41621
2007-08-30 18:45:57 +00:00
Ted Kremenek e961050104 Fixed bug in CFG construction where we failed to handle loop bodies with
no statements (or just full of ';' statements).

llvm-svn: 41620
2007-08-30 18:39:40 +00:00
Ted Kremenek f9b1756029 Fixed bug in CFG construction involving use of labels and "empty"
blocks involving only ';' statements.  We now correctly handle the following:

void empty_label() { l1: ; }

llvm-svn: 41619
2007-08-30 18:20:57 +00:00
Steve Naroff cadebd086f Fix a comment.
llvm-svn: 41618
2007-08-30 18:14:25 +00:00
Ted Kremenek bbad8ce2e7 Fixed bug where the CFG would fail to build when an 'if' statement had
an empty then or else block (or contained only ';' statements).

For example, we now handle the following:

int empty_else() { if (0) { int a; } else ; }
int empty_then() { if (0) ; else { int a; } }

Thanks to Nico Weber for spotting this problem.

llvm-svn: 41617
2007-08-30 18:13:31 +00:00
Steve Naroff 90dfdd5774 Polish yesterday's Array/ConstantArray/VariableArray rewrite, removing a couple FIXME's.
Refactored Array/VariableArray, moving SizeModifier/IndexTypeQuals back up to Array. These
attributes are not specific to VLA's. Most of them are specific to array parameter types.

llvm-svn: 41616
2007-08-30 18:10:14 +00:00
Chris Lattner 98dbf0a3b8 implement pretty printing of offsetof
llvm-svn: 41615
2007-08-30 17:59:59 +00:00
Chris Lattner 8718fcf35e a new testcase
llvm-svn: 41614
2007-08-30 17:51:09 +00:00
Chris Lattner f17bd423c2 implement initial sema support for __builtin_offsetof
llvm-svn: 41613
2007-08-30 17:45:32 +00:00
Chris Lattner e4ee2dfcf5 Pass the location of the type.
llvm-svn: 41612
2007-08-30 17:08:45 +00:00
Chris Lattner 55343038f4 Fix 80 col violations.
llvm-svn: 41611
2007-08-30 17:08:17 +00:00
Ted Kremenek 14f0d1a85a Fixed bug for CaseStmt where the child_begin/child_end methods were not
including the expressions in the case statement itself (not the body of
the case).

This required moving SubStmt out of SwitchCase into CaseStmt and DefaultStmt
respectively.  getSubStmt() now is a virtual call for SwitchCase, but is
a direct (static) call for CaseStmt and DefaultStmt.

llvm-svn: 41609
2007-08-30 16:50:46 +00:00
Chris Lattner 5ad4f46fd6 make sure to parse postfix expression suffixes after builtin
primary expressions.

llvm-svn: 41607
2007-08-30 15:52:49 +00:00
Chris Lattner 687d609f04 add an action callback for __builtin_offsetof
llvm-svn: 41606
2007-08-30 15:51:11 +00:00
Chris Lattner fec2519b4b -C mode doesn't return comments on "#" lines, so the diag checker doesn't pick them up.
Test this the hard way.

llvm-svn: 41605
2007-08-30 06:38:49 +00:00
Chris Lattner e41d2d3b22 When relexing the file to find expected warnings/errors, make sure
to turn off all lexer-related warnings.

llvm-svn: 41604
2007-08-30 06:34:23 +00:00
Chris Lattner 1e43547a53 fix a bug that is causing CodeGen/complex.c to be grumpy.
llvm-svn: 41603
2007-08-30 06:19:11 +00:00
Chris Lattner 11e30d355e Teach the stmtdumper to dump location/range info when a SourceMgr is available.
For example, -parse-ast-dump now prints:

static inline int __inline_isinff(float __x)
(CompoundStmt 0x2409a20
  (ReturnStmt 0x2409a10
    (BinaryOperator 0x24099f0 'int' <///usr/include/architecture/i386/math.h:183:63, col:102> '=='
      (CallExpr 0x24098f0 'float' <col:63, col:82>
        (ImplicitCastExpr 0x24098e0 'float (*)(float)' <col:63>
          (DeclRefExpr 0x2409880 'float (float)' <col:63> Decl='__builtin_fabsf' 0x2409840))
        (DeclRefExpr 0x24098a0 'float' <col:79> Decl='__x' 0x2409810))
      (CallExpr 0x24099c0 'float' <col:87, col:102>
        (ImplicitCastExpr 0x2409870 'float (*)(void)' <col:87>
          (DeclRefExpr 0x2409980 'float (void)' <col:87> Decl='__builtin_inff' 0x2409940))))))

where it only prints filename/line# if it changes from the previous value.  We 
really need loc info on stmts though, like we have on exprs.

llvm-svn: 41602
2007-08-30 06:17:34 +00:00
Chris Lattner 270228599d Fix a regression on test/Sema/unused-expr.c by fixing the type predicates
to test for the right type class.

llvm-svn: 41601
2007-08-30 06:10:41 +00:00
Chris Lattner 257fa2ae22 constify a method.
llvm-svn: 41600
2007-08-30 05:59:30 +00:00
Steve Naroff 5c13180a27 Fix the following redefinition errors submitted by Keith Bauer...
[dylan:~/llvm/tools/clang] admin% cat tentative_decls.c 
// incorrectly generates redefinition error
extern int array[3];
int array[3];

// incorrectly generates a redefinition error
extern void nup(int a[3]);
void nup(int a[3]) {}

It turns out that this exposed a fairly major flaw in the type system,
array types were never getting uniqued! This is because all array types
contained an expression, which aren't unique.

To solve this, we now have 2 array types, ConstantArrayType and
VariableArrayType. ConstantArrayType's are unique, VAT's aren't.

This is a fairly extensive set of fundamental changes. Fortunately,
all the tests pass. Nevertheless, there may be some collateral damage:-)
If so, let me know!

llvm-svn: 41592
2007-08-30 01:06:46 +00:00
Chris Lattner 84ca3762ae Previous commit should have been:
Use Ted's child walking interface to allow the dumper to walk the tree 
  in one place and only have node-specific callbacks worry about 
  formatting the nodes (instead of formatting the nodes plus walking the
  tree).

This commit eliminates now default cases by letting them fall through with
the normal visitor stuff.

llvm-svn: 41591
2007-08-30 01:00:35 +00:00
Chris Lattner cfb83dd7f2 elimiante some virtual calls.
llvm-svn: 41589
2007-08-30 00:53:54 +00:00
Chris Lattner 779d5d9476 Allow a SourceManager to optionally be passed into Stmt::dump
llvm-svn: 41588
2007-08-30 00:40:08 +00:00
Ted Kremenek 7142e18823 Added comments about -dump-cfg and -view-cfg modes for the clang driver.
llvm-svn: 41586
2007-08-29 23:26:37 +00:00
Ted Kremenek 71eca01291 Added an (optional) explicit "Label" statement to CFGBlock. If a
block begins with a label or case statement, CFGBlock::getLabel() will
return the corresponding LabelStmt/CaseStmt/DefaultStmt.

LabelStmts and SwitchCases no longer appear within the "executable"
statements of a CFGBlock.

More cleanups on visualization/pretty-printing of CFGs (less verbose).

llvm-svn: 41585
2007-08-29 23:20:49 +00:00
Chris Lattner 6678284a73 cleanup context-sensitive objc keyword recognition. Patch by Fariborz Jahanian.
llvm-svn: 41583
2007-08-29 22:54:08 +00:00
Neil Booth 4a1ee0562d Spaces not tabs.
llvm-svn: 41582
2007-08-29 22:13:52 +00:00
Neil Booth ac582c5ecb Ensure we diagnose long long literals in C90 mode.
llvm-svn: 41581
2007-08-29 22:00:19 +00:00
Ted Kremenek 4e5f99da6c Added GraphTraits to source-level CFGs (CFG and CFGBlock) to allow
(LLVM-provided) graph algorithms such as DFS and graph visualization
to work effortless on source-level CFGs.

Further cleanup on pretty printing of CFGs.  CFGBlock::dump and
CFGBlock::print now take the parent CFG as an argument.  This allows
CFGBlocks to print their own appropriate label indicating whether or
not they are the Entry/Exit/IndirectGotoBlock without the CFG::print
routine doing it instead.

Added Graphviz visualization for CFGs: CFG::viewCFG.  This employs the
GraphTraits just implemented.

Added "-view-cfg" mode the to clang driver.  This is identical to
"-dump-cfg" except that it calls Graphviz to visualize the CFGs
instead of dumping them to the terminal.

llvm-svn: 41580
2007-08-29 21:56:09 +00:00
Ted Kremenek 5ccf0d832d Added checking (during parsing) of comparison of floating point values using == or !=.
This is the same functionality gcc provides via --Wfloat-equal.

llvm-svn: 41574
2007-08-29 18:06:12 +00:00
Chris Lattner 8a241f9359 Teach Type::is[un]SignedIntegerType about enum decls. This allows the code generator
to emit signed comparisons when needed for enum decl references.  This implements
test/CodeGen/enum.c.  I think enums should be good now.

llvm-svn: 41572
2007-08-29 17:48:46 +00:00
Chris Lattner 3a370bf33f Implement GCC-compatible layout and typing of enum constants and enum decl.
A small bit of codegen work is still pending.

llvm-svn: 41571
2007-08-29 17:31:48 +00:00
Chris Lattner 959bcdcae6 add some accessors
llvm-svn: 41570
2007-08-29 17:23:37 +00:00
Chris Lattner c92bc4ce2f Fix a null dereference Neil ran into
llvm-svn: 41564
2007-08-29 16:03:41 +00:00
Chris Lattner fb38f274ff remove some ugly code now that implicit defs are being generated in this case, thanks Steve!
llvm-svn: 41560
2007-08-29 06:38:44 +00:00
Steve Naroff c5e5027b86 Re-teach Expr::isNullPointerConstant() about ImplicitCastExpr:-)
This fixes the following bug submitted by Neil...

const char *f (void) { return 0; }

...which would incorrectly warn with -pedantic enabled.

llvm-svn: 41559
2007-08-29 00:00:02 +00:00
Steve Naroff 0b66158248 Implement default argument promotions (for old-style function calls and variable argument lists).
[dylan:~/llvm/tools/clang] admin% cat x.c

int printf(const char *, ...);

int oldschool();

void foo() {
  float f; 
  short i;
  printf("foo %f", 1.0f);

  oldschool(f,i);
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -parse-ast-dump

int printf(char const *, ...);

int oldschool();

void foo()
(CompoundStmt 0x3105f00
  (DeclStmt 0x3105ba0
    0x3105ce0 "float f")
  (DeclStmt 0x3105c90
    0x3105d10 "short i")
  (CallExpr 0x3105df0 'int'
    (ImplicitCastExpr 0x3105dc0 'int (*)(char const *, ...)'
      (DeclRefExpr 0x3105c20 'int (char const *, ...)' Decl='printf' 0x3105bd0))
    (ImplicitCastExpr 0x3105dd0 'char const *'
      (StringLiteral 0x3105d60 'char *' "foo %f"))
    (ImplicitCastExpr 0x3105de0 'double'
      (FloatingLiteral 0x3105d80 'float' 1.000000)))
  (CallExpr 0x3105ed0 'int'
    (ImplicitCastExpr 0x3105ea0 'int (*)()'
      (DeclRefExpr 0x3105e20 'int ()' Decl='oldschool' 0x3105c40))
    (ImplicitCastExpr 0x3105eb0 'double'
      (DeclRefExpr 0x3105e40 'float' Decl='f' 0x3105ce0))
    (ImplicitCastExpr 0x3105ec0 'int'
      (DeclRefExpr 0x3105e60 'short' Decl='i' 0x3105d10))))

llvm-svn: 41558
2007-08-28 23:30:39 +00:00
Steve Naroff 1d8ce44aa4 Teach Expr::isNullPointerConstant() about ImplicitCastExpr's.
This fixes the following (recent) regression noticed by Keith Bauer (thanks!).

void func(void *a);

main() {
  void *p;
  p = 0;
  func(0);
}

...which now works as you would expect.

llvm-svn: 41557
2007-08-28 21:20:34 +00:00
Steve Naroff f93b6726b1 Finish converting decls over to the new invalid decl API.
Also removed an old FIXME (FIXME: "auto func();" passes through...).

llvm-svn: 41555
2007-08-28 20:14:24 +00:00
Ted Kremenek eda180e239 Added support for indirect-gotos (GCC extension) in source-level CFGs.
This involves the construction of a specialized "dispatch" block that
all basic blocks containing indirect gotos unconditionally transfer
control-flow to.  The successors of the dispatch block has as its successors
all of the blocks containing labels whose address was taken somewhere in
the function.

llvm-svn: 41554
2007-08-28 19:26:49 +00:00
Steve Naroff cf871f59bf Move the "invalid decl" idiom up to Decl (where we have some bits to steal:-)
Converted ParmVarDecl, FileVarDecl, BlockVarDecl, and Sema::ParseIdentifierExpr() to use the idiom.

Updated array-constraint.c to make sure we no longer get "undeclared identifier" errors:-)

llvm-svn: 41552
2007-08-28 18:45:29 +00:00
Chris Lattner 24b51ff752 Emit a slightly better warning for unused values for unary and binary operators:
t2.c:3:18: warning: expression result unused
     x = ++x, ++y, y+2;
     ~~~~~~~~~~~~^ ~~~

llvm-svn: 41551
2007-08-28 18:40:30 +00:00
Chris Lattner c11005faa1 add a sourcelocation to binary operator to keep track of the location of the operator.
llvm-svn: 41550
2007-08-28 18:36:55 +00:00
Ted Kremenek 105efce68f Added support for GCC-style statement expressions in source-level CFGs.
llvm-svn: 41549
2007-08-28 18:30:10 +00:00
Chris Lattner 1c1f932433 Change EnumDecl to store its corresponding integer type
directly in it.  Remove TargetInfo::getEnumPolicy, as there is only
one policy that we support right now.

llvm-svn: 41548
2007-08-28 18:24:31 +00:00
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