Commit Graph

63 Commits

Author SHA1 Message Date
Chris Lattner 237f27573f Several related changes:
1) implement parser and sema support for reading and verifying attribute(warnunusedresult).
2) rename hasLocalSideEffect to isUnusedResultAWarning, inverting the sense
   of its result.
3) extend isUnusedResultAWarning to directly return the loc and range 
   info that should be reported to the user.  Make it substantially more
   precise in some cases than what was previously reported.
4) teach isUnusedResultAWarning about CallExpr to decls that are 
   pure/const/warnunusedresult, fixing a fixme.
5) change warn_attribute_wrong_decl_type to not pass in english strings, instead,
   pass in integers and use %select.

llvm-svn: 64543
2009-02-14 07:37:35 +00:00
Douglas Gregor 4feb36de04 Remove DeclGroupOwningRef, since we intend for declarations to be owned
by DeclContexts (always) rather than by statements. 

DeclContext currently goes out of its way to avoid destroying any
Decls that might be owned by a DeclGroupOwningRef. However, in an
error-recovery situation, a failure in a declaration statement can
cause all of the decls in a DeclGroupOwningRef to be destroyed after
they've already be added into the DeclContext. Hence, DeclContext is
left with already-destroyed declarations, and bad things happen. This
problem was causing failures that showed up as assertions on x86 Linux
in test/Parser/objc-forcollection-neg-2.m.

llvm-svn: 64474
2009-02-13 19:06:18 +00:00
Steve Naroff c49b22a5c8 Sema::ActOnObjCAtThrowStmt(): return from recently added errors. Thanks Chris!
llvm-svn: 64389
2009-02-12 18:09:32 +00:00
Steve Naroff 0fa412cc6d Turn warning into error. Minor incompatibility with GCC (for scalar types, GCC only produces a warning).
llvm-svn: 64375
2009-02-12 15:54:59 +00:00
Steve Naroff 5ee2c02ac6 Fix <rdar://problem/6243503> [sema] @throw; accepted outside catch block.
llvm-svn: 64318
2009-02-11 20:05:44 +00:00
Steve Naroff d5581d2af1 Fix <rdar://problem/6206858> [sema] type check @throw statements.
Added a FIXME to handle 'rethrow' check.

llvm-svn: 64308
2009-02-11 17:45:08 +00:00
Ted Kremenek 5a201951ca Overhaul of Stmt allocation:
- Made allocation of Stmt objects using vanilla new/delete a *compiler
  error* by making this new/delete "protected" within class Stmt.
- Now the only way to allocate Stmt objects is by using the new
  operator that takes ASTContext& as an argument.  This ensures that
  all Stmt nodes are allocated from the same (pool) allocator.
- Naturally, these two changes required that *all* creation sites for
  AST nodes use new (ASTContext&).  This is a large patch, but the
  majority of the changes are just this mechanical adjustment.
- The above changes also mean that AST nodes can no longer be
  deallocated using 'delete'.  Instead, one most do
  StmtObject->Destroy(ASTContext&) or do
  ASTContextObject.Deallocate(StmtObject) (the latter not running the
  'Destroy' method).

Along the way I also...
- Made CompoundStmt allocate its array of Stmt* using the allocator in
  ASTContext (previously it used std::vector).  There are a whole
  bunch of other Stmt classes that need to be similarly changed to
  ensure that all memory allocated for ASTs comes from the allocator
  in ASTContext.
- Added a new smart pointer ExprOwningPtr to Sema.h.  This replaces
  the uses of llvm::OwningPtr within Sema, as llvm::OwningPtr used
  'delete' to free memory instead of a Stmt's 'Destroy' method.

Big thanks to Doug Gregor for helping with the acrobatics of making
'new/delete' private and the new smart pointer ExprOwningPtr!

llvm-svn: 63997
2009-02-07 01:47:29 +00:00
Mike Stump 82f071faa7 Add support for blocks with explicit return types.
llvm-svn: 63784
2009-02-04 22:31:32 +00:00
Chris Lattner 60f36223a9 move library-specific diagnostic headers into library private dirs. Reduce
redundant #includes.  Patch by Anders Johnsen!

llvm-svn: 63271
2009-01-29 05:15:15 +00:00
Anders Carlsson 570c357ded If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417
llvm-svn: 63127
2009-01-27 20:38:24 +00:00
Chris Lattner 7368d581c1 Split the single monolithic DiagnosticKinds.def file into one
.def file for each library.  This means that adding a diagnostic
to sema doesn't require all the other libraries to be rebuilt.

Patch by Anders Johnsen!

llvm-svn: 63111
2009-01-27 18:30:58 +00:00
Anders Carlsson dc6ceca4ba Fix an inline asm sema bug that I introduced.
llvm-svn: 62666
2009-01-21 06:27:20 +00:00
Anders Carlsson 224fca8982 Improvements to Sema of asm statements. Fixes <rdar://problem/6156893>
llvm-svn: 62609
2009-01-20 20:49:22 +00:00
Douglas Gregor 6e6ad602e5 Remove ScopedDecl, collapsing all of its functionality into Decl, so
that every declaration lives inside a DeclContext.

Moved several things that don't have names but were ScopedDecls (and,
therefore, NamedDecls) to inherit from Decl rather than NamedDecl,
including ObjCImplementationDecl and LinkageSpecDecl. Now, we don't
store empty DeclarationNames for these things, nor do we try to insert
them into DeclContext's lookup structure.

The serialization tests are temporarily disabled. We'll re-enable them
once we've sorted out the remaining ownership/serialiazation issues
between DeclContexts and TranslationUnion, DeclGroups, etc.

llvm-svn: 62562
2009-01-20 01:17:11 +00:00
Sebastian Redl 481bf3f48b Convert ObjC statement actions to smart pointers.
llvm-svn: 62465
2009-01-18 17:43:11 +00:00
Sebastian Redl 24b8e15dfa Convert asm statement action to smart pointers.
llvm-svn: 62464
2009-01-18 16:53:17 +00:00
Sebastian Redl 573feed2a8 Convert more statement actions to smart pointers.
llvm-svn: 62463
2009-01-18 13:19:59 +00:00
Anders Carlsson 19aa04d270 Change TargetInfo::validateInputConstraint to take begin/end name iterators instead of the number of outputs. No functionality change.
llvm-svn: 62433
2009-01-17 23:36:15 +00:00
Sebastian Redl fbfaafc0a9 Convert some more statement actions to smart pointers.
Fix a type error; parser wanted to pass the third part of a for-statement as a statement; should be expression.

llvm-svn: 62380
2009-01-16 23:28:06 +00:00
Sebastian Redl 6a8002eac7 Convert some more actions to smart pointers.
No performance regression in my basic test.
Also fixed a type error in ActOnFinishSwitchStmt's arguments (body is a stmt).

llvm-svn: 62032
2009-01-11 00:38:46 +00:00
Anders Carlsson 37e0088610 Perform default function/array conversion for input arguments to inline asm statements if the input expr can be a memory operand
llvm-svn: 61515
2008-12-31 07:27:38 +00:00
Sebastian Redl 1cbb59182c Convert a two more statement actions to smart pointers.
llvm-svn: 61456
2008-12-28 16:13:43 +00:00
Sebastian Redl 9b244a8797 Full AST support and better Sema support for C++ try-catch.
llvm-svn: 61346
2008-12-22 21:35:02 +00:00
Sebastian Redl 54c04d4700 Partial AST and Sema support for C++ try-catch.
llvm-svn: 61337
2008-12-22 19:15:10 +00:00
Sebastian Redl 52f03bac60 Convert a few Stmt actions to smart pointers.
llvm-svn: 61309
2008-12-21 12:04:03 +00:00
Chris Lattner 0cb00d66ea This is valid in C++.
void foo() { return foo(); }

llvm-svn: 61188
2008-12-18 02:03:48 +00:00
Chris Lattner 27e5beff70 Merge function-return.c into function.c
Fix PR2790 by making a warning an EXTWARN instead of EXTENSION.
Add a new EXTENSION warning for "return (some void expression);"

llvm-svn: 61187
2008-12-18 02:01:17 +00:00
Douglas Gregor 4619e439b6 Introduce basic support for dependent types, type-dependent
expressions, and value-dependent expressions. This permits us to parse
some template definitions.

This is not a complete solution; we're missing type- and
value-dependent computations for most of the expression types, and
we're missing checks for dependent types and type-dependent
expressions throughout Sema.

llvm-svn: 60615
2008-12-05 23:32:09 +00:00
Chris Lattner 79413956d4 change getCurFunctionDecl to skip through Block contexts to find
the containing block.  Introduce a new getCurFunctionOrMethodDecl
method to check to see if we're in a function or objc method.
Minor cleanups to other related places.  This fixes rdar://6405429.

llvm-svn: 60564
2008-12-04 23:50:19 +00:00
Anders Carlsson f7fba46331 Use VerifyIntegerConstantExpression for case values.
llvm-svn: 60317
2008-12-01 02:13:02 +00:00
Chris Lattner 1e5665e6be Change a whole lot of diagnostics to take QualType's directly
instead of converting them to strings first.  This also fixes a
bunch of minor inconsistencies in the diagnostics emitted by clang
and adds a bunch of FIXME's to DiagnosticKinds.def.

llvm-svn: 59948
2008-11-24 06:25:27 +00:00
Chris Lattner 0369c57ac6 Make all the 'redefinition' diagnostics more consistent, and make the
"previously defined here" diagnostics all notes.

llvm-svn: 59920
2008-11-23 23:12:31 +00:00
Chris Lattner e3d20d9545 Convert IdentifierInfo's to be printed the same as DeclarationNames
with implicit quotes around them.  This has a bunch of follow-on 
effects and requires tweaking to a whole lot of code.  This causes
a regression in two tests (xfailed) by causing it to emit things like:

  Line 10: duplicate interface declaration for category 'MyClass1' ('Category1')

instead of:

  Line 10: duplicate interface declaration for category 'MyClass1(Category1)'

I will fix this in a follow-up commit.

As part of this, I had to start switching stuff to use ->getDeclName() instead
of Decl::getName() for consistency.  This is good, but I was planning to do this
as an independent patch.  There will be several follow-on patches
to clean up some of the mess, but this patch is already too big.

llvm-svn: 59917
2008-11-23 21:45:46 +00:00
Anders Carlsson 475f4bce36 Case values must be evaluated
llvm-svn: 59884
2008-11-22 21:50:49 +00:00
Anders Carlsson 59689ed764 Use Expr::Evaluate for case statements. Fixes PR2525
llvm-svn: 59881
2008-11-22 21:04:56 +00:00
Chris Lattner 651d42dba5 remove the last old-fashioned Diag method. Transition complete!
llvm-svn: 59714
2008-11-20 06:38:18 +00:00
Chris Lattner 29e812b905 remove another old-school Diag method.
llvm-svn: 59712
2008-11-20 06:06:08 +00:00
Chris Lattner 4bd8dd8568 stop calling II::getName() unnecesarily in sema
llvm-svn: 59609
2008-11-19 08:23:25 +00:00
Chris Lattner f490e15729 remove one more old-style Diag method.
llvm-svn: 59589
2008-11-19 05:27:50 +00:00
Chris Lattner 3b05413e9d Switch several more Sema Diag methods over. This simplifies the
__builtin_prefetch code to only emit one diagnostic per builtin_prefetch.
While this has nothing to do with the rest of the patch, the code seemed
like overkill when I was updating it.

llvm-svn: 59588
2008-11-19 05:08:23 +00:00
Douglas Gregor 8e1cf608dc Implement initialization of a reference (C++ [dcl.init.ref]) as part
of copy initialization. Other pieces of the puzzle:

  - Try/Perform-ImplicitConversion now handles implicit conversions
    that don't involve references.
  - Try/Perform-CopyInitialization uses
    CheckSingleAssignmentConstraints for C. PerformCopyInitialization
    is now used for all argument passing and returning values from a
    function.
  - Diagnose errors with declaring references and const values without
    an initializer. (Uses a new Action callback, ActOnUninitializedDecl).
  
We do not yet have implicit conversion sequences for reference
binding, which means that we don't have any overloading support for
reference parameters yet.

llvm-svn: 58353
2008-10-29 00:13:59 +00:00
Ted Kremenek 9bb286ff43 Migrate DeclStmt over to using a DeclGroup instead of a pointer to a ScopedDecl*.
This also removes the ugly hack needed in CFG.cpp for subclassing DeclStmt to create a DeclStmt with one Decl*.

llvm-svn: 57275
2008-10-07 23:09:49 +00:00
Ted Kremenek 11b004216c When processing Objective-C foreach statements, first check to see if the statement has a DeclStmt with a single Decl. Afterwards, use DeclStmt::getSolitaryDecl() to access that Decl (thus avoiding an assertion being triggered). These changes remove an unneeded use of ScopedDecl::getNextDeclarator() and DeclStmt::getDecl().
llvm-svn: 57207
2008-10-06 20:58:11 +00:00
Ted Kremenek dcd6632463 Use the DeclStmt::decl_iterator to get the first decl in a DeclStmt instead of using DeclStmt::getDecl().
llvm-svn: 57196
2008-10-06 18:48:35 +00:00
Steve Naroff c60873ce44 Fix <rdar://problem/6243788> clang: Incorrect return statement for Blocks?
llvm-svn: 56590
2008-09-24 22:26:48 +00:00
Steve Naroff 3b1e172d7e Sema::ActOnBlockReturnStmt(): Need to perform the UsualUnaryConversions on the return type.
Sema::CheckReturnStackAddr(): Make sure we skip over implicit casts.
Added some more test cases...

llvm-svn: 56254
2008-09-16 22:25:10 +00:00
Argyrios Kyrtzidis 176edb5490 Do implicit conversion to bool for the condition in a do-while statement.
llvm-svn: 56096
2008-09-11 05:16:22 +00:00
Argyrios Kyrtzidis 7620ee4550 Implement Sema support for the 'condition' part of C++ selection-statements and iteration-statements (if/switch/while/for).
llvm-svn: 56044
2008-09-10 02:17:11 +00:00
Steve Naroff c540d66940 Add semantic analysis for "blocks".
Highlights...

- 4 new AST nodes, BlockExpr, BlockStmtExpr, BlockExprExpr, BlockDeclRefExpr.
- Sema::ActOnBlockStart(), ActOnBlockError(), ActOnBlockStmtExpr(), ActOnBlockExprExpr(), ActOnBlockReturnStmt().

Next steps...

- hack Sema::ActOnIdentifierExpr() to deal with block decl refs.
- add attribute handler for byref decls.
- add test cases.

llvm-svn: 55710
2008-09-03 18:15:37 +00:00
Anders Carlsson 1ec2ccd8ee Objective-C foreach selector elements must be lvalues.
llvm-svn: 55316
2008-08-25 18:16:36 +00:00