Commit Graph

893 Commits

Author SHA1 Message Date
Douglas Gregor dc70c3abc0 Diagnose the declaration of enum templates. Also, be a bit more
careful about value-dependent enumerators. Fixes PR5786.

llvm-svn: 97570
2010-03-02 17:53:14 +00:00
Douglas Gregor 1d85d2903b Fix an amusing typo that completely the re-introduction of parameters
for the purposes of parsing default arguments. In effect, we would
re-introduce the parameter with a default argument N times (where N is
the number of parameters preceding the parameter with a default
argument). This showed up when a defaulted parameter of a member
function of a local class shadowed a parameter of the enclosing
function. Fixes PR6383.

llvm-svn: 97534
2010-03-02 01:29:43 +00:00
Douglas Gregor 53db22c7aa Add comment
llvm-svn: 97528
2010-03-02 00:25:00 +00:00
Douglas Gregor d29f2799b7 When we're parsing template names as part of base-specifiers, we are
*not* entering the context of the nested-name-specifier. This was
causing us to look into an uninstantiated template that we shouldn't
look into. Fixes PR6376.

llvm-svn: 97524
2010-03-01 23:49:23 +00:00
Douglas Gregor ea99b5d736 Unbreak the build
llvm-svn: 97519
2010-03-01 23:31:19 +00:00
Douglas Gregor 9a28e84b32 Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we
had a single set of maps in Sema (for the function) along with a stack
of block scopes. However, this lead to funky behavior with nested
functions, e.g., in the member functions of local classes.

The explicit-stack approach is far cleaner, and we retain a 1-element
cache so that we're not malloc/free'ing every time we enter a
function. Fixes PR6382.

Also, tweaked the unused-variable warning suppression logic to look at
errors within a given Scope rather than within a given function. The
prior code wasn't looking at the right number-of-errors count when
dealing with blocks, since the block's count would be deallocated
before we got to ActOnPopScope. This approach works with nested
blocks/functions, and gives tighter error recovery.

llvm-svn: 97518
2010-03-01 23:15:13 +00:00
Douglas Gregor 604c30299d Robustify instantiation of templates when there are errors in the
template definition. Do this both by being more tolerant of errors in
our asserts and by not dropping a variable declaration completely when
its initializer is ill-formed. Fixes the crash-on-invalid in PR6375,
but not the original issue.

llvm-svn: 97463
2010-03-01 18:27:54 +00:00
John McCall 8bc2a70dfe Don't infinite-loop if TryAnnotateCXXScopeToken fails to annotate but doesn't
signal an error.  This can happen even when the current token is '::' if
this is a ::new or ::delete expression.

This was an oversight in my recent parser refactor;  fixes PR 5825.

llvm-svn: 97462
2010-03-01 18:20:46 +00:00
Chris Lattner 73a9c7d891 pull some altivec stuff out of line.
llvm-svn: 97405
2010-02-28 18:33:55 +00:00
Chris Lattner fd48afe412 Implement PR6423 by using one token of lookahead to disambiguate
an *almost* always incorrect case.  This only does the lookahead
in the insanely unlikely case, so it shouldn't impact performance.

On this testcase:

struct foo {
}
typedef int x;

Before:

t.c:3:9: error: cannot combine with previous 'struct' declaration specifier
typedef int x;
        ^

After:

t.c:2:2: error: expected ';' after struct
}
 ^
 ;

llvm-svn: 97403
2010-02-28 18:18:36 +00:00
Benjamin Kramer 0a1abd4088 Add an overload of Preprocessor::getSpelling which takes a SmallVector and
returns a StringRef. Use it to simplify some repetitive code.

llvm-svn: 97322
2010-02-27 13:44:12 +00:00
John McCall 1f476a1783 Fix an assertion-on-error during tentative constructor parsing by
propagating error conditions out of the various annotate-me-a-snowflake
routines.  Generally (but not universally) removes redundant diagnostics
as well as, you know, not crashing on bad code.  On the other hand,
I have just signed myself up to fix fiddly parser errors for the next
week.  Again.

llvm-svn: 97221
2010-02-26 08:45:28 +00:00
Douglas Gregor cd3f49fc88 Restore the invariant that a nested-name-specifier can only contain
class types, dependent types, and namespaces. I had previously
weakened this invariant while working on parsing pseudo-destructor
expressions, but recent work in that area has made these changes
unnecessary.

llvm-svn: 97112
2010-02-25 04:46:04 +00:00
Douglas Gregor 40d732fee7 Make sure that we finish the DeclSpec when parsing a C++
type-specifier-seq. Fixes some conditional-jump-on-unitialized-value
errors in valgrind. Also counts as attempt #2 at making the MSVC
buildbot happy.

llvm-svn: 97077
2010-02-24 23:13:13 +00:00
Douglas Gregor 0d5b0a1e5e ActOnPseudoDestructorExpr now performs all semantic analysis for
pseudo-destructor expressions, and builds the CXXPseudoDestructorExpr
node directly. Currently, this only affects pseudo-destructor
expressions when they are parsed, but not after template
instantiation. That's coming next...

Improve parsing of pseudo-destructor-names. When parsing the
nested-name-specifier and we hit the sequence of tokens X :: ~, query
the actual module to determine whether X is a type-name (in which case
the X :: is part of the pseudo-destructor-name but not the
nested-name-specifier) or not (in which case the X :: is part of the
nested-name-specifier). 

llvm-svn: 97058
2010-02-24 21:29:12 +00:00
Douglas Gregor e610adae17 Rework parsing of pseudo-destructor expressions and explicit
destructor calls, e.g., 

  p->T::~T

We now detect when the member access that we've parsed, e.g.,

  p-> or x.

may be a pseudo-destructor expression, either because the type of p or
x is a scalar or because it is dependent (and, therefore, may become a
scalar at template instantiation time). 

We then parse the pseudo-destructor grammar specifically:

  ::[opt] nested-name-specifier[opt] type-name :: ∼ type-name

and hand those results to a new action, ActOnPseudoDestructorExpr,
which will cope with both dependent member accesses of destructors and
with pseudo-destructor expressions.

This commit affects the parsing of pseudo-destructors, only; the
semantic actions still go through the semantic actions for member
access expressions. That will change soon.

llvm-svn: 97045
2010-02-24 18:44:31 +00:00
Rafael Espindola c18086ae17 Add support for the weakref attribute. We still produce "alias weak" as llvm-gcc does, but are more strict on what uses of weakref we accept.
llvm-svn: 96992
2010-02-23 22:00:30 +00:00
Richard Pennington 14cc983d86 Retain attributes for K&R style parameter declarations.
llvm-svn: 96941
2010-02-23 12:22:13 +00:00
Fariborz Jahanian 4c172c63e5 Early support for declaring ivars in class extensions. wip.
llvm-svn: 96819
2010-02-22 23:04:20 +00:00
Douglas Gregor 90d554ecb3 Implement support for parsing pseudo-destructor expression with a nested-name-specifier, e.g.,
typedef int Int;
  int *p;
  p->Int::~Int();

This weakens the invariant that the only types in nested-name-specifiers are tag types (restricted to class types in C++98/03). However, we weaken this invariant as little as possible, accepting arbitrary types in nested-name-specifiers only when we're in a member access expression that looks like a pseudo-destructor expression.

llvm-svn: 96743
2010-02-21 18:36:56 +00:00
Douglas Gregor 0286b46702 Only parse C++0x attribute specifiers in declarators when in C++0x
mode. This allows us to detect invalid VLAs in Objective-C++
mode. This should be the last of <rdar://problem/7660386>.

llvm-svn: 96679
2010-02-19 16:47:56 +00:00
Ted Kremenek 66f2d6ba7b Allow GNU attributes to appear in an Objective-C method declaration
before the selector name (but after the return type).  Among other things,
this allows IBAction to be implemented with an attribute.

llvm-svn: 96623
2010-02-18 23:05:16 +00:00
Ted Kremenek d9c6663124 Add 'ns_returns_not_retained' and 'cf_returns_not_retained' attributes to
match 'ns_returns_retained' and 'cf_returns_retained' respectively.  These
are not yet hooked up to the static analyzer.

llvm-svn: 96535
2010-02-18 00:05:45 +00:00
Ted Kremenek 06be968942 Add IBAction attribute to keep the IBOutlet attribute company.
llvm-svn: 96447
2010-02-17 02:37:45 +00:00
Douglas Gregor fe17d2550b Improve parsing and instantiation of destructor names, so that we can
now cope with the destruction of types named as dependent templates,
e.g.,

  y->template Y<T>::~Y()

Nominally, we implement C++0x [basic.lookup.qual]p6. However, we don't
follow the letter of the standard here because that would fail to
parse

  template<typename T, typename U>
  X0<T, U>::~X0() { }

properly. The problem is captured in core issue 339, which gives some
(but not enough!) guidance. I expect to revisit this code when the
resolution of 339 is clear, and/or we start capturing better source
information for DeclarationNames.

Fixes PR6152.

llvm-svn: 96367
2010-02-16 19:09:40 +00:00
Fariborz Jahanian 8efe0ec899 Issue a bettter diagnostics for incorrect property setter name.
(radar 7647953).

llvm-svn: 96284
2010-02-15 22:20:11 +00:00
John McCall 38200b081a Improve the diagnostic given when referring to a tag type without a tag (in C)
or that's been hidden by a non-type (in C++).

The ideal C++ diagnostic here would note the hiding declaration, but this
is a good start.

llvm-svn: 96141
2010-02-14 01:03:10 +00:00
Ted Kremenek c162e8e193 Clean up ownership of 'AttributeList' objects in Parser. Apparently
we would just leak them all over the place, with no clear ownership of
these objects at all.  AttributeList objects would get leaked on both
error and non-error paths.

Note: I introduced the usage of llvm::OwningPtr<AttributeList> to
manage these objects, which is particularly useful for methods with
multiple return sites.  In at least one method I used them even when
they weren't strictly necessary because it clarified the ownership
semantics and made the code easier to read.  Should the excessive
'take()' and 'reset()' calls become a performance issue we can always
re-evaluate.

Note+1: I believe I have not introduced any double-frees, but it would
be nice for someone to review this.

This fixes <rdar://problem/7635046>.

llvm-svn: 95847
2010-02-11 02:19:13 +00:00
Sebastian Redl b0e3e1bf67 When placing an annotation token over an existing annotation token, make sure that the new token's range extends to the end of the old token. Assert that in AnnotateCachedTokens. Fixes PR6248.
llvm-svn: 95555
2010-02-08 19:35:18 +00:00
Douglas Gregor b65a913c35 Fix assertion failure when parsing linkage specifications (PR5921),
from Keir Mierle!

llvm-svn: 95516
2010-02-07 08:38:28 +00:00
Anders Carlsson a7bcade229 Add attributes to namespace decls.
llvm-svn: 95510
2010-02-07 01:09:23 +00:00
Douglas Gregor 7df89f5d18 When we're parsing an expression that may have looked like a
declaration, we can end up with template-id annotation tokens for
types that have not been converted into type annotation tokens. When
this is the case, translate the template-id into a type and parse as
an expression.

llvm-svn: 95404
2010-02-05 19:11:37 +00:00
Chandler Carruth bc50da6360 Revert the unused TST_pixel entry from r95335 as it is not listed in the Sema
switch, triggering warnings.

llvm-svn: 95381
2010-02-05 07:38:55 +00:00
John Thompson 2233460de6 First stage of adding AltiVec support
llvm-svn: 95335
2010-02-05 00:12:22 +00:00
Sebastian Redl 2b37272c11 In some contexts, type declarations cannot occur. Pass this information down to ParseClassSpecifier, to make its decision easier. Fixes PR6200.
llvm-svn: 95255
2010-02-03 21:21:43 +00:00
Chris Lattner 5e854b95f3 Declarators can have grouping parens. This fixes rdar://7608537.
llvm-svn: 95246
2010-02-03 20:41:24 +00:00
Chris Lattner 35af0ab3eb fix PR6216
llvm-svn: 95185
2010-02-03 01:45:03 +00:00
Fariborz Jahanian e165191990 Simplify setting of DeclContext for @catch variable
(per Doug's comment).

llvm-svn: 95169
2010-02-03 00:32:51 +00:00
Fariborz Jahanian 08d614d92e Fix DeclContext of an objective-c @catch variable
declaration. Fixes radar 7590273.

llvm-svn: 95164
2010-02-03 00:01:43 +00:00
Chris Lattner afe6a840d4 the declspec of a declaration can have storage-class specifiers,
type qualifiers and type specifiers in any order.   For example,
this is valid: struct x {...} typedef y;

This fixes PR6208.

llvm-svn: 95094
2010-02-02 17:32:27 +00:00
Chris Lattner cf25141d14 Implement PR6180, substantially improving the diagnostics we get from
forgetting a ';' at the end of a struct.  For something like:

class c {
}
void foo() {}

we now produce:

t.cc:3:2: error: expected ';' after class
}
 ^
 ;

instead of:

t.cc:4:1: error: cannot combine with previous 'class' declaration specifier
void foo() {}
^
t.cc:2:7: error: 'class c' can not be defined in the result type of a function
class c {
      ^

GCC produces:

t.cc:4: error: new types may not be defined in a return type
t.cc:4: note: (perhaps a semicolon is missing after the definition of ‘c’)
t.cc:4: error: two or more data types in declaration of ‘foo’

I *think* I got the follow set right, but if I forgot anything, we'll start 
getting spurious "expected ';' after class" errors, let me know if you see
any.

llvm-svn: 95042
2010-02-02 01:23:29 +00:00
Chris Lattner 916dbf114a improve diagnostics for C++ struct ; issues. Before:
t.cc:4:3: error: expected ';' at end of declaration list
  int y;
  ^
t.cc:6:1: error: expected ';' at end of declaration list
};
^

After:

t.cc:3:8: error: expected ';' at end of declaration list
  int x
       ^
       ;
t.cc:5:8: error: expected ';' at end of declaration list
  int z
       ^
       ;

llvm-svn: 95039
2010-02-02 00:43:15 +00:00
Chris Lattner 245c5335b5 improve diagnostics on missing ; in a struct. Before:
t.c:4:3: error: expected ';' at end of declaration list
  int y;
  ^
t.c:4:8: warning: extra ';' inside a struct or union
  int y;
       ^
t.c:6:1: warning: expected ';' at end of declaration list
};
^

After:

t.c:3:8: error: expected ';' at end of declaration list
  int x  // expected-error {{expected ';' at end of declaration list}}
       ^
       ;
t.c:5:8: warning: expected ';' at end of declaration list
  int z
       ^
       ;

llvm-svn: 95038
2010-02-02 00:37:27 +00:00
Douglas Gregor 7ae2d7758f Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:

  - CXXBaseOrMemberInitializer now contains only a single initializer
    rather than a set of initialiation arguments + a constructor. The
    single initializer covers all aspects of initialization, including
    constructor calls as necessary but also cleanup of temporaries
    created by the initializer (which we never handled
    before!).

  - Rework + simplify code generation for CXXBaseOrMemberInitializers,
    since we can now just emit the initializer as an initializer.

  - Switched base and member initialization over to the new
    initialization code (InitializationSequence), so that it

  - Improved diagnostics for the new initialization code when
    initializing bases and members, to match the diagnostics produced
    by the previous (special-purpose) code.

  - Simplify the representation of type-checked constructor initializers in
    templates; instead of keeping the fully-type-checked AST, which is
    rather hard to undo at template instantiation time, throw away the
    type-checked AST and store the raw expressions in the AST. This
    simplifies instantiation, but loses a little but of information in
    the AST.

  - When type-checking implicit base or member initializers within a
    dependent context, don't add the generated initializers into the
    AST, because they'll look like they were explicit.

  - Record in CXXConstructExpr when the constructor call is to
  initialize a base class, so that CodeGen does not have to infer it
  from context. This ensures that we call the right kind of
  constructor.

There are also a few "opportunity" fixes here that were needed to not
regress, for example:

  - Diagnose default-initialization of a const-qualified class that
    does not have a user-declared default constructor. We had this
    diagnostic specifically for bases and members, but missed it for
    variables. That's fixed now.

  - When defining the implicit constructors, destructor, and
    copy-assignment operator, set the CurContext to that constructor
    when we're defining the body.

llvm-svn: 94952
2010-01-31 09:12:51 +00:00
Anders Carlsson 9a020f9a3a Use IdentifierInfo * instead of std::string for the AsmStmt names.
llvm-svn: 94925
2010-01-30 22:25:16 +00:00
John McCall 5cb5287467 Fixit to remove 'volatile' in file-scope 'asm volatile'.
llvm-svn: 94466
2010-01-25 23:12:50 +00:00
John McCall 9dfb16210e Warn on top-level 'asm volatile' (instead of misparsing it).
"Fixes" rdar://problem/7574870

llvm-svn: 94458
2010-01-25 22:27:48 +00:00
Douglas Gregor 7210063126 Move the type specifier location for elaborated-type-specifiers from
the tag kind (union, struct, class, enum) over to the name of the tag,
if there is a name, since most clients want to point at the name.

llvm-svn: 94424
2010-01-25 16:33:23 +00:00
Chris Lattner 0bcc858a2b -fno-rtti is now the default.
llvm-svn: 94379
2010-01-24 20:43:31 +00:00
Chris Lattner 8fd2d01118 fix PR6034, a crash on invalid where the switch stack would get
unbalanced.

llvm-svn: 94347
2010-01-24 01:50:29 +00:00