Commit Graph

402 Commits

Author SHA1 Message Date
Anders Carlsson 978f08d9b4 Pass the location of the start of the selector to ActOnClassMessage/ActOnInstanceMessage.
llvm-svn: 64560
2009-02-14 18:21:46 +00:00
Chris Lattner 62bf958247 just ignore hte format_arg attribute for now, it doesn't have any semantic implications.
llvm-svn: 64547
2009-02-14 08:12:47 +00:00
Chris Lattner 677a35804f add parser and type checking support for attribute((objc_exception)).
We don't have "zero cost" exceptions for ObjC yet, so there is no codegen
support required.

llvm-svn: 64546
2009-02-14 08:09:34 +00:00
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
Anders Carlsson 0ed56a1b9f Don't ignore the const attribute - we even have CG support for that. Do ignore the malloc attribute however.
llvm-svn: 64538
2009-02-14 04:12:57 +00:00
Chris Lattner b12f4f8731 ignore the const attribute for now.
llvm-svn: 64536
2009-02-14 03:51:44 +00:00
Daniel Dunbar fee07a0b47 Sema/AST support for attribute used. Patch by Anders Johnson (with small tweaks & test case)!
llvm-svn: 64478
2009-02-13 19:23:53 +00:00
Anders Carlsson b4f3134ca3 Add a new Ignored attribute type, and use it for may_alias.
llvm-svn: 64446
2009-02-13 08:16:43 +00:00
Anders Carlsson 76187b4d68 Add sema support for the nodebug attribute.
llvm-svn: 64441
2009-02-13 06:46:13 +00:00
Daniel Dunbar 648bf78333 Support __attribute__(section(<name>))
llvm-svn: 64380
2009-02-12 17:28:23 +00:00
Douglas Gregor 4e5cbdcbed Initial implementation of function overloading in C.
This commit adds a new attribute, "overloadable", that enables C++
function overloading in C. The attribute can only be added to function
declarations, e.g.,

  int *f(int) __attribute__((overloadable));

If the "overloadable" attribute exists on a function with a given
name, *all* functions with that name (and in that scope) must have the
"overloadable" attribute. Sets of overloaded functions with the
"overloadable" attribute then follow the normal C++ rules for
overloaded functions, e.g., overloads must have different
parameter-type-lists from each other.

When calling an overloaded function in C, we follow the same
overloading rules as C++, with three extensions to the set of standard
conversions:

  - A value of a given struct or union type T can be converted to the
    type T. This is just the identity conversion. (In C++, this would
    go through a copy constructor).
  - A value of pointer type T* can be converted to a value of type U*
    if T and U are compatible types. This conversion has Conversion
    rank (it's considered a pointer conversion in C).
  - A value of type T can be converted to a value of type U if T and U
    are compatible (and are not both pointer types). This conversion
    has Conversion rank (it's considered to be a new kind of
    conversion unique to C, a "compatible" conversion).

Known defects (and, therefore, next steps):
  1) The standard-conversion handling does not understand conversions
  involving _Complex or vector extensions, so it is likely to get
  these wrong. We need to add these conversions.
  2) All overloadable functions with the same name will have the same
  linkage name, which means we'll get a collision in the linker (if
  not sooner). We'll need to mangle the names of these functions.

llvm-svn: 64336
2009-02-11 23:02:49 +00:00
Steve Naroff 7a54c0d7d4 Fix <rdar://problem/6505139> [clang on growl]: need to allow unnamed selectors as the first argument
llvm-svn: 64320
2009-02-11 20:43:13 +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
Douglas Gregor 85e8b3eeed Fix a problem with bogus template shadowing warnings
llvm-svn: 64230
2009-02-10 19:52:54 +00:00
Douglas Gregor dba326363c Implement parsing, semantic analysis and ASTs for default template
arguments. This commit covers checking and merging default template
arguments from previous declarations, but it does not cover the actual
use of default template arguments when naming class template
specializations.

llvm-svn: 64229
2009-02-10 19:49:53 +00:00
Douglas Gregor 97f34576d4 Teach the type-id/expression disambiguator about different
disambiguation contexts, so that we properly parse template arguments
such as

  A<int()>

as type-ids rather than as expressions. Since this can be confusing
(especially when the template parameter is a non-type template
parameter), we try to give a friendly error message.

Almost, eliminate a redundant error message (that should have been a
note) and add some ultra-basic checks for non-type template
arguments.

llvm-svn: 64189
2009-02-10 00:53:15 +00:00
Douglas Gregor d32e028f79 Rudimentary checking of template arguments against their corresponding
template parameters when performing semantic analysis of a template-id
naming a class template specialization.

llvm-svn: 64185
2009-02-09 23:23:08 +00:00
Douglas Gregor 0db4ccd7fb Implement Sebastian's idea for simplifying our handling of the greater-than operator/delimiter. Also, clean up after ourselves following a failed parse of a template-argument-list
llvm-svn: 64166
2009-02-09 21:04:56 +00:00
Douglas Gregor 67b556a0da Eliminate TemplateArg so that we only have a single kind of
representation for template arguments. Also simplifies the interface
for ActOnClassTemplateSpecialization and eliminates some annoying
allocations of TemplateArgs.

My attempt at smart pointers for template arguments lists is
relatively lame. We can improve it once we're sure that we have the
right representation for template arguments.

llvm-svn: 64154
2009-02-09 19:34:22 +00:00
Douglas Gregor 8bf4205c70 Start processing template-ids as types when the template-name refers
to a class template. For example, the template-id 'vector<int>' now
has a nice, sugary type in the type system. What we can do now:

  - Parse template-ids like 'vector<int>' (where 'vector' names a
    class template) and form proper types for them in the type system.
  - Parse icky template-ids like 'A<5>' and 'A<(5 > 0)>' properly,
    using (sadly) a bool in the parser to tell it whether '>' should
    be treated as an operator or not.

This is a baby-step, with major problems and limitations:
  - There are currently two ways that we handle template arguments
  (whether they are types or expressions). These will be merged, and,
  most likely, TemplateArg will disappear.
  - We don't have any notion of the declaration of class template
  specializations or of template instantiations, so all template-ids
  are fancy names for 'int' :)

llvm-svn: 64153
2009-02-09 18:46:07 +00:00
Sebastian Redl f6591ca6d9 Implement Declarator::getSourceRange().
llvm-svn: 64151
2009-02-09 18:23:29 +00:00
Douglas Gregor 9817f4a717 Make Sema::getTypeName return the opaque pointer of a QualType rather
than a Decl, which gives us some more flexibility to express the
results with the type system. There are no clients using this
flexibility yet, but it's meant to be able to describe qualified names
as written in the source (e.g., "foo::type") or template-ids that name
a class template specialization (e.g., "std::vector<INT>").

DeclSpec's TST_typedef has become TST_typename, to reflect its use to
describe types found by name (that may or may not be typedefs). The
type representation of a DeclSpec with TST_typename is an opaque
QualType pointer. All users of TST_typedef, both direct and indirect,
have been updated for these changes.

llvm-svn: 64141
2009-02-09 15:09:02 +00:00
Sebastian Redl 112a976616 Implement dereferencing of pointers-to-member.
llvm-svn: 63983
2009-02-07 00:15:38 +00:00
Douglas Gregor cd72ba97e7 Semantic checking for class template declarations and
redeclarations. For example, checks that a class template
redeclaration has the same template parameters as previous
declarations.

Detangled class-template checking from ActOnTag, whose logic was
getting rather convoluted because it tried to handle C, C++, and C++
template semantics in one shot.

Made some inroads toward eliminating extraneous "declaration does not
declare anything" errors by adding an "error" type specifier.

llvm-svn: 63973
2009-02-06 22:42:48 +00:00
Sebastian Redl 726a0d9524 Put the invalid flag of OwningResult into the Action pointer.
This shrinks OwningResult by one pointer. Since it is no longer larger than OwningPtr, merge the two.
This leads to simpler client code and speeds up my benchmark by 2.7%.
For some reason, this exposes a previously hidden bug, causing a regression in SemaCXX/condition.cpp.

llvm-svn: 63867
2009-02-05 15:02:23 +00:00
Mike Stump 82f071faa7 Add support for blocks with explicit return types.
llvm-svn: 63784
2009-02-04 22:31:32 +00:00
Douglas Gregor ded2d7b021 Basic representation of C++ class templates, from Andrew Sutton.
llvm-svn: 63750
2009-02-04 19:02:06 +00:00
Douglas Gregor 8a6be5ec64 Diagnose ambiguities in getTypeName. Fixes http://llvm.org/bugs/show_bug.cgi?id=3475
llvm-svn: 63737
2009-02-04 17:00:24 +00:00
Sebastian Redl 3d3f75a995 Allow taking the address of data members, resulting in a member pointer.
Pointers to functions don't work yet, and pointers to overloaded functions even less. Also, far too much illegal code is accepted.

llvm-svn: 63655
2009-02-03 20:19:35 +00:00
Mike Stump 99231d5c98 Formatting fix.
llvm-svn: 63573
2009-02-02 23:46:21 +00:00
Anders Carlsson d277d790e0 Add sema support for the cleanup attribute.
llvm-svn: 63462
2009-01-31 01:16:18 +00:00
Douglas Gregor d14247a9e5 Implement and test aggregate initialization in C++. Major changes:
- Support initialization of reference members; complain if any
  reference members are left uninitialized.
  - Use C++ copy-initialization for initializing each element (falls
  back to constraint checking in C)
  - Make sure we diagnose when one tries to provide an initializer
  list for a non-aggregate.
  - Don't complain about empty initializers in C++ (they are permitted)
  - Unrelated but necessary: don't bother trying to convert the
  decl-specifier-seq to a type when we're dealing with a C++
  constructor, destructor, or conversion operator; it results in
  spurious warnings.

llvm-svn: 63431
2009-01-30 22:09:00 +00:00
Steve Naroff 3b6a4bd891 Simplify/cleanup r63219 (based on Chris review).
llvm-svn: 63393
2009-01-30 14:23: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
Steve Naroff 16c8e598ae Name change (isTypeName->getTypeName).
Since it doesn't return a bool, is shouldn't be prefixed with 'is'.

llvm-svn: 63226
2009-01-28 19:39:02 +00:00
Steve Naroff b04867265c Change Parser::ParseFunctionDeclarator() to annotate typename tokens.
This removes ~10% of the calls to Sema::isTypeName(), which amount to a little less than a 1% reduction in usertime (for Cocoa.h).

llvm-svn: 63219
2009-01-28 19:16:40 +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
Eli Friedman eb3a9b03ab Fix for PR3418: make sure to handle the RHS of expressions starting with
__extension__.  This sort of construct shows up in the gcc source code.

llvm-svn: 63100
2009-01-27 08:43:38 +00:00
Douglas Gregor f829825d04 Some micro-optimizations for DISABLE_SMART_POINTERS:
- When it's safe, ActionResult uses the low bit of the pointer for
  the "invalid" flag rather than a separate "bool" value. This keeps
  GCC from generating some truly awful code, for a > 3x speedup in the
  result-passing microbenchmark.
  - When DISABLE_SMART_POINTERS is defined, store an ActionResult
  within ASTOwningResult rather than an ASTOwningPtr. Brings the
  performance benefits of the above to smart pointers with
  DISABLE_SMART_POINTERS defined.

Sadly, these micro-benchmark performance improvements don't seem to
make much of a difference on Cocoa.h right now. However, they're
harmless and might help with future optimizations.

llvm-svn: 63061
2009-01-26 22:44:13 +00:00
Sebastian Redl c6d52f5dfb Make tentative parsing of pointer-to-member decls work, and fix other stuff pointed out by Doug.
llvm-svn: 62944
2009-01-24 23:29:36 +00:00
Sebastian Redl 9ed6efdd75 Add support for declaring pointers to members.
Add serialization support for ReferenceType.

llvm-svn: 62934
2009-01-24 21:16:55 +00:00
Douglas Gregor 9aa8904a46 Handle any undeclared parameters in a K&R-style function with a
special action, inside function prototype scope. This avoids confusion
when we try to inject these parameters into the scope of the function
body before the function itself has been added to the surrounding
scope. Fixes <rdar://problem/6097326>.

llvm-svn: 62849
2009-01-23 16:23:13 +00:00
Sebastian Redl b2e6ca7ff3 Add a switch that allows disabling the smart pointers.
Uncomment the define in Ownership.h to disable the smart pointers.
Disabled, the smart pointers no longer contain a pointer
to the action, and no longer have special destruction or
copying semantics. They are, compiler willing, raw
pointers or ActionResult equivalents.

llvm-svn: 62767
2009-01-22 17:31:11 +00:00
Douglas Gregor e4a0bb7a20 Initial implementation of semantic analysis and ASTs for C99
designated initializers. This implementation should cover all of the
constraints in C99 6.7.8, including long, complex designations and
computing the size of incomplete array types initialized with a
designated initializer. Please see the new test-case and holler if you
find cases where this doesn't work.

There are still some wrinkles with GNU's anonymous structs and
anonymous unions (it isn't clear how these should work; we'll just
follow GCC's lead) and with designated initializers for the members of a
union. I'll tackle those very soon.

CodeGen is still nonexistent, and there's some leftover code in the
parser's representation of designators that I'll also need to clean up.

llvm-svn: 62737
2009-01-22 00:58:24 +00:00
Chris Lattner e387d9ed5b Inline ParseOptionalTypeSpecifier into ParseDeclarationSpecifiers.
This avoids call overhead and extraneous switches when parsing
very simple declspecs like "int" "void" etc, which are pretty common :)

llvm-svn: 62711
2009-01-21 19:48:37 +00:00
Chris Lattner 78ecd4f61e ParseOptionalTypeSpecifier should consume a token if it returns true.
llvm-svn: 62704
2009-01-21 19:19:26 +00:00
Chris Lattner 1ce41edd8d Optimize Declarator to avoid malloc/free traffic for the argument list of a
function DeclaratorChunk in common cases.  This uses a fixed array in 
Declarator when it is small enough for the first function declarator chunk
in a declarator.

This eliminates all malloc/free traffic from DeclaratorChunk::getFunction
when running on Cocoa.h except for five functions: signal/bsd_signal/sigset,
which have multiple Function DeclChunk's, and 
CFUUIDCreateWithBytes/CFUUIDGetConstantUUIDWithBytes, which take more than
16 arguments.

This patch was pair programmed with Steve.

llvm-svn: 62599
2009-01-20 19:11:22 +00:00
Sebastian Redl b5d49356e6 Convert more expression actions to smart pointers.
llvm-svn: 62537
2009-01-19 22:31:54 +00:00
Sebastian Redl c215cfc3e1 Convert more expression actions to smart pointers.
Fix type of logical negation for C++.

llvm-svn: 62475
2009-01-19 00:08:26 +00:00
Sebastian Redl ffbcf96d1c Convert a few expression actions to smart pointers.
These actions are extremely widely used (identifier expressions and literals); still no performance regression.

llvm-svn: 62468
2009-01-18 18:53:16 +00:00