Commit Graph

457 Commits

Author SHA1 Message Date
Chris Lattner b41df4f622 change a couple more c++ sema methods to be based on isinvalid bits.
llvm-svn: 70022
2009-04-25 08:35:12 +00:00
Chris Lattner 38378bf61f various "is invalid" cleanups for C++ ctors/dtors.
llvm-svn: 70021
2009-04-25 08:28:21 +00:00
Chris Lattner f6d1c9c7f0 This is a pretty big cleanup for how invalid decl/type are handle.
This gets rid of a bunch of random InvalidDecl bools in sema, changing
us to use the following approach:

1. When analyzing a declspec or declarator, if an error is found, we 
   set a bit in Declarator saying that it is invalid.
2. Once the Decl is created by sema, we immediately set the isInvalid
   bit on it from what is in the declarator.  From this point on, sema
   consistently looks at and sets the bit on the decl.

This gives a very clear separation of concerns and simplifies a bunch
of code.  In addition to this, this patch makes these changes:

1. it renames DeclSpec::getInvalidType() -> isInvalidType().
2. various "merge" functions no longer return bools: they just set the
   invalid bit on the dest decl if invalid.
3. The ActOnTypedefDeclarator/ActOnFunctionDeclarator/ActOnVariableDeclarator
   methods now set invalid on the decl returned instead of returning an
   invalid bit byref.
4. In SemaType, refering to a typedef that was invalid now propagates the
   bit into the resultant type.  Stuff declared with the invalid typedef
   will now be marked invalid.
5. Various methods like CheckVariableDeclaration now return void and set the
   invalid bit on the decl they check.


There are a few minor changes to tests with this, but the only major bad
result is test/SemaCXX/constructor-recovery.cpp.  I'll take a look at this
next.

llvm-svn: 70020
2009-04-25 08:06:05 +00:00
Douglas Gregor c78d34699f PCH support for the global method pool (= instance and factory method
pools, combined). The methods in the global method pool are lazily
loaded from an on-disk hash table when Sema looks into its version of
the hash tables.

llvm-svn: 69989
2009-04-24 21:10:55 +00:00
Anders Carlsson e500faf8c8 Create a CXXConstructExpr instead of a CXXTemporaryObjectExpr in InitializeVarWithConstructor.
llvm-svn: 69956
2009-04-24 05:16:06 +00:00
Douglas Gregor 38feed810f Eliminate Sema::ObjCAliasDecls. This is based on Steve's fix, but also
updates name lookup so that we see through @compatibility_alias
declarations to their underlying interfaces.

llvm-svn: 69950
2009-04-24 02:57:34 +00:00
Douglas Gregor ac345a3990 Eliminate Sema::ObjCInterfaceDecls
llvm-svn: 69942
2009-04-24 00:16:12 +00:00
Douglas Gregor 79947a24e6 Eliminate Sema::ObjCImplementations, relying instead on name lookup. What's good for uniformity is good for PCH (or is it the other way around?).
As part of this, make ObjCImplDecl inherit from NamedDecl (since
ObjCImplementationDecls now need to have names so that they can be
found). This brings ObjCImplDecl very, very close to
ObjCContainerDecl; we may be able to merge them soon.

llvm-svn: 69941
2009-04-24 00:11:27 +00:00
Douglas Gregor de9f17e943 Eliminate Sema::ObjCProtocols. Instead, we place ObjCProtocolDecls in
their own namespace (IDNS_Protocol) and use the normal name-lookup
routines to find them. Aside from the simplification this provides
(one less DenseMap!), it means that protocols will be lazily
deserialized from PCH files.

Make the code size of the selector table block match the code size of
the type and decl blocks.

llvm-svn: 69939
2009-04-23 23:18:26 +00:00
Douglas Gregor fedd428d04 Eliminate Sema::KnownFunctionIDs, so that Sema doesn't end up pulling
in a bunch of declarations from the PCH file. We're down to loading
very few declarations in Carbon-prefixed "Hello, World!":

*** PCH Statistics:
  6/20693 types read (0.028995%)
  7/59230 declarations read (0.011818%)
  50/44914 identifiers read (0.111324%)
  0/32954 statements read (0.000000%)
  5/6187 macros read (0.080815%)

llvm-svn: 69825
2009-04-22 20:56:09 +00:00
Chris Lattner dc00437fa0 change implicit int warnings to point to the identifier, not the
start of the declspec.  The fixit still goes there, and we underline
the declspec.  This helps when the start of the declspec came from a
macro that expanded from a system header.  For example, we now produce:

t.c:2:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
static x;
~~~~~~ ^

llvm-svn: 69777
2009-04-22 05:27:59 +00:00
Douglas Gregor beecd58e21 Explictly track tentative definitions within Sema, then hand those
tentative definitions off to the ASTConsumer at the end of the
translation unit. 

Eliminate CodeGen's internal tracking of tentative definitions, and
instead hook into ASTConsumer::CompleteTentativeDefinition. Also,
tweak the definition-deferal logic for C++, where there are no
tentative definitions.

Fixes <rdar://problem/6808352>, and will make it much easier for
precompiled headers to cope with tentative definitions in the future.

llvm-svn: 69681
2009-04-21 17:11:58 +00:00
Sebastian Redl 3b7ef5e374 Another piece of the conditional operator puzzle. We'll want to use FindCompositePointerType in some other places, too.
llvm-svn: 69534
2009-04-19 19:26:31 +00:00
Chris Lattner 45542ea107 run the jump checker on blocks, even though they don't have gotos,
they do allow switches.

llvm-svn: 69510
2009-04-19 05:28:12 +00:00
Chris Lattner 9fecd743ca add a new Sema::CurFunctionNeedsScopeChecking bool that is used to avoid
calling into the jump checker when a function or method is known to contain
no VLAs or @try blocks.

llvm-svn: 69509
2009-04-19 05:21:20 +00:00
Chris Lattner 1a1fdbd75d move jump scope checking and related code out into its own file, SemaDecl.cpp is
already too large.

llvm-svn: 69505
2009-04-19 04:46:21 +00:00
Chris Lattner 96b3139773 abstract the SwitchStack for blocks just like we do the goto labels.
This fixes a crash on invalid (test10). rdar://6805469

llvm-svn: 69465
2009-04-18 20:10:59 +00:00
Chris Lattner 3318e86541 refactor some code, adding a new getLabelMap() accessor method
so that clients can't poke the function-local one when they really
want the current block label.  No functionality change.

llvm-svn: 69463
2009-04-18 20:01:55 +00:00
Chris Lattner 40cc0044e7 make scope checking be static functions instead of sema methods.
llvm-svn: 69429
2009-04-18 07:36:39 +00:00
Anders Carlsson e6840d84df If a class has a non-trivial constructor that doesn't take any arguments, we will now make an implicit CXXTemporaryObjectExpr. So
struct S {
  S();
};

void f() {
 S s;
}

's' here will implicitly be declared as.

S s = S();

llvm-svn: 69326
2009-04-16 23:50:50 +00:00
Sebastian Redl 1a99f441e6 Fix a crash bug when comparing overload quality of conversion operators with conversion constructors.
Remove an atrocious amount of trailing whitespace in the overloaded operator mangler. Sorry, couldn't help myself.
Change the DeclType parameter of Sema::CheckReferenceInit to be passed by value instead of reference. It wasn't changed anywhere.
Let the parser handle C++'s irregular grammar around assignment-expression and conditional-expression.
And finally, the reason for all this stuff: implement C++ semantics for the conditional operator. The implementation is complete except for determining lvalueness.

llvm-svn: 69299
2009-04-16 17:51:27 +00:00
Douglas Gregor d5846a1eb5 Implement support for designated initializers that refer to members of
anonymous structs or unions. Fixes PR3778.

llvm-svn: 69153
2009-04-15 06:41:24 +00:00
Douglas Gregor 54feb84489 When building a PCH file, don't perform end-of-translation-unit
wrap-up (e.g., turning tentative definitions into definitions). Also,
very that, when we actually use the PCH file, we get the ride code
generation for tentative definitions and definitions that show up in
the PCH file.

llvm-svn: 69043
2009-04-14 16:27:31 +00:00
Chris Lattner ffaa0e6919 Diagnose invalid uses of tagged types with a missing tag. For example, in:
struct xyz { int y; };
enum abc { ZZZ };

static xyz b;
abc c;

we used to produce:

t2.c:4:8: error: unknown type name 'xyz'
static xyz b;
       ^
t2.c:5:1: error: unknown type name 'abc'
abc c;
^

we now produce:

t2.c:4:8: error: use of tagged type 'xyz' without 'struct' tag
static xyz b;
       ^
       struct
t2.c:5:1: error: use of tagged type 'abc' without 'enum' tag
abc c;
^
enum

GCC produces the normal:
t2.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘b’
t2.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’

rdar://6783347

llvm-svn: 68914
2009-04-12 21:49:30 +00:00
Sebastian Redl 42e92c4bc3 Parse deleted member functions. Parsing member declarations goes through a different code path that I forgot previously.
Implement the rvalue reference overload dance for returning local objects. Returning a local object first tries to find a move constructor now.
The error message when no move constructor is defined (or is not applicable) and the copy constructor is deleted is quite ugly, though.

llvm-svn: 68902
2009-04-12 17:16:29 +00:00
Chris Lattner a8a7d0f371 implement rdar://6780761, making sema reject some code that otherwise
crashes codegen.

llvm-svn: 68891
2009-04-12 08:11:20 +00:00
Chris Lattner d8626fd283 change the interface to ActOnMethodDeclaration to pass down argument
information in a little struct instead of individually.  While we're
at it, add per-argument loc info and attribute info.

llvm-svn: 68871
2009-04-11 18:57:04 +00:00
Eli Friedman 574c745370 Diagnose uses of function specifiers on declarations which don't declare
functions.  Fixes PR3941.

llvm-svn: 68541
2009-04-07 19:37:57 +00:00
Fariborz Jahanian 69ba935743 Fixes method name lookup when method appears in
the base implementations (and not in
current implementation).

llvm-svn: 68527
2009-04-07 18:28:06 +00:00
Douglas Gregor 7a5bc76b81 Fixed the Fix-It hints for comparison against a string literal. Thanks, Chris!
llvm-svn: 68454
2009-04-06 18:45:53 +00:00
Douglas Gregor 170512fa78 Add some more code modification hints
llvm-svn: 68261
2009-04-01 23:51:29 +00:00
Douglas Gregor fe3d7d0880 Make parsing a semantic analysis a little more robust following Sema
failures that involve malformed types, e.g., "typename X::foo" where
"foo" isn't a type, or "std::vector<void>" that doens't instantiate
properly.

Similarly, be a bit smarter in our handling of ambiguities that occur
in Sema::getTypeName, to eliminate duplicate error messages about
ambiguous name lookup.

This eliminates two XFAILs in test/SemaCXX, one of which was crying
out to us, trying to tell us that we were producing repeated error
messages.

llvm-svn: 68251
2009-04-01 21:51:26 +00:00
Douglas Gregor dce2b62b70 Parsing, semantic analysis, and template instantiation for typename
specifiers that terminate in a simple-template-id, e.g.,

  typename MetaFun::template apply<T1, T2>

Also, implement template instantiation for dependent
nested-name-specifiers that involve unresolved identifiers, e.g.,

  typename T::type::type

llvm-svn: 68166
2009-04-01 00:28:59 +00:00
Douglas Gregor aa59489b18 Implement template instantiation for template names, including both
template template parameters and dependent template names. For
example, the oft-mentioned

  typename MetaFun::template apply<T1, T2>::type

can now be instantiated, with the appropriate name lookup for "apply".

llvm-svn: 68128
2009-03-31 18:38:02 +00:00
Douglas Gregor b67535d1b6 Parsing and AST representation for dependent template names that occur
within nested-name-specifiers, e.g., for the "apply" in

  typename MetaFun::template apply<T1, T2>::type

At present, we can't instantiate these nested-name-specifiers, so our
testing is sketchy.

llvm-svn: 68081
2009-03-31 00:43:58 +00:00
Douglas Gregor dc572a3266 Improve the representation of template names in the AST. This
representation handles the various ways in which one can name a
template, including unqualified references ("vector"), qualified
references ("std::vector"), and dependent template names
("MetaFun::template apply").

One immediate effect of this change is that the representation of
nested-name-specifiers in type names for class template
specializations (e.g., std::vector<int>) is more accurate. Rather than
representing std::vector<int> as

  std::(vector<int>)

we represent it as

  (std::vector)<int>

which more closely follows the C++ grammar. 

Additionally, templates are no longer represented as declarations
(DeclPtrTy) in Parse-Sema interactions. Instead, I've introduced a new
OpaquePtr type (TemplateTy) that holds the representation of a
TemplateName. This will simplify the handling of dependent
template-names, once we get there.

llvm-svn: 68074
2009-03-30 22:58:21 +00:00
Chris Lattner 5bbb3c8ad9 Push DeclGroup much farther throughout the compiler. Now the various
productions (except the already broken ObjC cases like @class X,Y;) in 
the parser that can produce more than one Decl return a DeclGroup instead
of a Decl, etc.

This allows elimination of the Decl::NextDeclarator field, and exposes
various clients that should look at all decls in a group, but which were
only looking at one (such as the dumper, printer, etc).  These have been
fixed.

Still TODO:

1) there are some FIXME's in the code about potentially using
DeclGroup for better location info.
2) ParseObjCAtDirectives should return a DeclGroup due to @class etc.
3) I'm not sure what is going on with StmtIterator.cpp, or if it can
   be radically simplified now.
4) I put a truly horrible hack in ParseTemplate.cpp.

I plan to bring up #3/4 on the mailing list, but don't plan to tackle
#1/2 in the short term.

llvm-svn: 68002
2009-03-29 16:50:03 +00:00
Anders Carlsson bb1e4724f1 More improvements to namespace aliases. We now support everything except aliases in using directives.
llvm-svn: 67966
2009-03-28 23:53:49 +00:00
Anders Carlsson 47952aec09 Parse the location of the 'namespace' token to ActOnNamespaceAliasDef. No functionality change.
llvm-svn: 67961
2009-03-28 22:53:22 +00:00
Chris Lattner 83f095cc7e Introduce a new OpaquePtr<N> struct type, which is a simple POD wrapper for a
pointer.  Its purpose in life is to be a glorified void*, but which does not
implicitly convert to void* or other OpaquePtr's with a different UID.

Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>.  Change the 
entire parser/sema interface to use DeclPtrTy instead of DeclTy*.  This
makes the C++ compiler enforce that these aren't convertible to other opaque
types.

We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc,
but I don't plan to do that in the short term.

The one outstanding known problem with this patch is that we lose the 
bitmangling optimization where ActionResult<DeclPtrTy> doesn't know how to
bitmangle the success bit into the low bit of DeclPtrTy.  I will rectify
this with a subsequent patch.

llvm-svn: 67952
2009-03-28 19:18:32 +00:00
Anders Carlsson 9205d55390 Add an ActOnNamespaceAliasDef action and have the parser call it.
llvm-svn: 67915
2009-03-28 05:27:17 +00:00
Eli Friedman 8b7b1b1aee Change compound assignment operators to keep track of both the promoted
LHS type and the computation result type; this encodes information into 
the AST which is otherwise non-obvious.  Fix Sema to always come up with the 
right answer for both of these types.  Fix IRGen and the analyzer to 
account for these changes.  This fixes PR2601.  The approach is inspired 
by PR2601 comment 2.

Note that this changes real *= complex in CodeGen from a silent 
miscompilation to an explicit error.

I'm not really sure that the analyzer changes are correct, or how to 
test them... someone more familiar with the analyzer should check those 
changes.

llvm-svn: 67889
2009-03-28 01:22:36 +00:00
Douglas Gregor 5c7c9cb678 Make our diagnostics about the obsolete GNU designated-initializer
syntax into extension warnings, and provide code-modification hints
showing how to fix the problem.

llvm-svn: 67885
2009-03-28 00:41:23 +00:00
Douglas Gregor 333489bba3 Initial implementation of parsing, semantic analysis, and template
instantiation for C++ typename-specifiers such as

  typename T::type

The parsing of typename-specifiers is relatively easy thanks to
annotation tokens. When we see the "typename", we parse the
typename-specifier and produce a typename annotation token. There are
only a few places where we need to handle this. We currently parse the
typename-specifier form that terminates in an identifier, but not the
simple-template-id form, e.g.,

  typename T::template apply<U, V>

Parsing of nested-name-specifiers has a similar problem, since at this
point we don't have any representation of a class template
specialization whose template-name is unknown.

Semantic analysis is only partially complete, with some support for
template instantiation that works for simple examples. 

llvm-svn: 67875
2009-03-27 23:10:48 +00:00
Anders Carlsson 4742a9c19a Add a stubbed out CheckBaseClassAccess method.
llvm-svn: 67821
2009-03-27 05:05:05 +00:00
Douglas Gregor f21eb49a04 Revamp our representation of C++ nested-name-specifiers. We now have a
uniqued representation that should both save some memory and make it
far easier to properly build canonical types for types involving
dependent nested-name-specifiers, e.g., "typename T::Nested::type".

This approach will greatly simplify the representation of
CXXScopeSpec. That'll be next.

llvm-svn: 67799
2009-03-26 23:50:42 +00:00
Anders Carlsson 5558ca1d4f Factor the member access specifier setting code into its own function. No intended functionality change.
llvm-svn: 67725
2009-03-26 01:19:02 +00:00
Anders Carlsson dfbbdf6fd5 Handle parsing of templates in member declarations. Pass the AccessSpecifier all the way down to ActOnClassTemplate.
Doug, Sebastian: Plz review! :)

llvm-svn: 67723
2009-03-26 00:52:18 +00:00
Douglas Gregor ef1a09a336 Implement template instantiation for static data members of class
templates, including in-class initializers. For example:

  template<typename T, T Divisor>
  class X {
  public:
    static const T value = 10 / Divisor;
  };

instantiated with, e.g.,

  X<int, 5>::value

to get the value '2'.

llvm-svn: 67715
2009-03-25 23:32:15 +00:00
Douglas Gregor 6c2adff380 Pass access specifiers through to member classes and member enums.
llvm-svn: 67710
2009-03-25 22:00:53 +00:00