Commit Graph

213 Commits

Author SHA1 Message Date
John McCall 93cc732ffc Properly account for redeclarations when explicitly instantiating class templates.
What happens here is that we actually turn the first declaration into a
definition, regardless of whether it was actually originally a definition,
and furthermore we do this all after we've instantiated all the declarations.
This exposes a bug in my DefinitionData patch where it was only setting the
DefinitionData for previous declarations, not future declarations.
Fortunately, there's an iterator for that.

llvm-svn: 99657
2010-03-26 21:56:38 +00:00
John McCall a2a3f7dc11 Implement -Wshadow. Based on a patch by Mike M.!
llvm-svn: 98684
2010-03-16 21:48:18 +00:00
John McCall 3e11ebebc8 Remember declaration scope qualifiers in the AST. Imposes no memory overhead
on unqualified declarations.

Patch by Enea Zaffanella!  Minimal adjustments:  allocate the ExtInfo nodes
with the ASTContext and delete them during Destroy().  I audited a bunch of
Destroy methods at the same time, to ensure that the correct teardown was
being done.

llvm-svn: 98540
2010-03-15 10:12:16 +00:00
Chandler Carruth f50ef6ed9a Make Decl::isOutOfLine() virtual, and use that to determine when definitions
are for out of line declarations more easily. This simplifies the logic and
handles the case of out-of-line class definitions correctly. Fixes PR6107.

llvm-svn: 96729
2010-02-21 07:08:09 +00:00
Ted Kremenek 7f4945aa9c Remove use of 'std::string' from Attr objects, using instead a byte
array allocated using the allocator in ASTContext.  This addresses
these strings getting leaked when using a BumpPtrAllocator (in
ASTContext).

Fixes: <rdar://problem/7636765>
llvm-svn: 95853
2010-02-11 05:28:37 +00:00
Douglas Gregor d505812422 Eliminate a bunch of unnecessary ASTContexts from members functions of
Decl subclasses. No functionality change.

llvm-svn: 95841
2010-02-11 01:19:42 +00:00
Douglas Gregor 0a5a2216e2 Eliminate the ASTContext parameter from RecordDecl::getDefinition()
and CXXRecordDecl::getDefinition(); it's totally unnecessary. No
functionality change.

llvm-svn: 95836
2010-02-11 01:04:33 +00:00
John McCall ae580fede3 Always start tag definitions before completing them. Assert same.
Fixes latent and not-so-latent objc++ and blocks++ bugs.

llvm-svn: 95340
2010-02-05 01:33:36 +00:00
John McCall 67da35c832 Extract a common structure for holding information about the definition
of a C++ record.  Exposed a lot of problems where various routines were
silently doing The Wrong Thing (or The Acceptable Thing in The Wrong Order)
when presented with a non-definition.  Also cuts down on memory usage.

llvm-svn: 95330
2010-02-04 22:26:26 +00:00
Douglas Gregor 7dc5c17d92 When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.

This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:

  - Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
    when the declaration is in an anonymous namespace.
  - Added Type::getLinkage() to determine the linkage of a type, which
    is defined as the minimum linkage of the types (when we're dealing
    with a compound type that is not a struct/class/union).
  - Extended NamedDecl::getLinkage() to consider the linkage of the
    template arguments and template parameters of function template
    specializations and class template specializations.
  - Taught code generation to rely on NamedDecl::getLinkage() when
    determining the linkage of variables and functions, also
    considering the linkage of the types of those variables and
    functions (C++ only). Map UniqueExternalLinkage to internal
    linkage, taking out the explicit checks for
    isInAnonymousNamespace().

This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:

LLVM:
  Expected Passes    : 4006
  Expected Failures  : 32
  Unsupported Tests  : 40
  Unexpected Failures: 736

Clang:
  Expected Passes    : 1903
  Expected Failures  : 14
  Unexpected Failures: 75

Overall:
  Expected Passes    : 5909
  Expected Failures  : 46
  Unsupported Tests  : 40
  Unexpected Failures: 811

Still to do:
  - Improve testing
  - Check whether we should allow the presence of types with
  InternalLinkage (in addition to UniqueExternalLinkage) given
  variables/functions internal linkage in C++, as mentioned in
  PR5792. 
  - Determine how expensive the getLinkage() calls are in practice;
  consider caching the result in NamedDecl.
  - Assess the feasibility of Chris's idea in comment #1 of PR5792.

llvm-svn: 95216
2010-02-03 09:33:45 +00:00
Sebastian Redl ccdb5ff17d Fix a C++ regression where redefinitions weren't diagnosed.
llvm-svn: 95096
2010-02-02 17:55:12 +00:00
Sebastian Redl 5ca7984bb4 In C++, an initializer on a variable doesn't necessarily mean it's the definition. With that in mind, rename getDefinition to getAnyInitializer (to distinguish it from getInit) and reimplement it in terms of isThisDeclarationADefinition. Update all code to use this new function.
llvm-svn: 94999
2010-02-01 20:16:42 +00:00
Sebastian Redl 35351a9554 Add VarDecl::isThisDeclarationADefinition(), which properly encapsulates the logic for when a variable declaration is a (possibly tentativ) definition. Add a few functions building on this, and shift C tentative definition handling over to this new functionality. This shift also kills the Sema::TentativeDefinitions map and instead simply stores all declarations in the renamed list. The correct handling for multiple tentative definitions is instead shifted to the final walk of the list.
llvm-svn: 94968
2010-01-31 22:27:38 +00:00
Sebastian Redl 833ef45b1d Bring some semblance of order into Decl.h and Decl.cpp. While at it, fix some typo comments and remove an unused and unimplemented function prototype. No functionality change.
llvm-svn: 94599
2010-01-26 22:01:41 +00:00
Douglas Gregor 562c1f9365 Teach CIndex's cursor visitor to restrict its traversal to a specific
region of interest (if provided). Implement clang_getCursor() in terms
of this traversal rather than using the Index library; the unified
cursor visitor is more complete, and will be The Way Forward.

Minor other tweaks needed to make this work:
  - Extend Preprocessor::getLocForEndOfToken() to accept an offset
  from the end, making it easy to move to the last character in the
  token (rather than just past the end of the token).
  - In Lexer::MeasureTokenLength(), the length of whitespace is zero.

llvm-svn: 94200
2010-01-22 19:49:59 +00:00
Alexis Hunt c88db06565 Implement semantic checking for C++ literal operators.
This now rejects literal operators that don't meet the requirements.
Templates are not yet checked for.

llvm-svn: 93315
2010-01-13 09:01:02 +00:00
Mike Stump 13c6670273 Fix spelling.
llvm-svn: 92816
2010-01-06 02:05:39 +00:00
John McCall 91f1a02648 Typedefs can be redeclared. That seems like something we should record in
the AST lest we run into some crazy canonicalization bug like PR5874.

llvm-svn: 92283
2009-12-30 00:31:22 +00:00
Sam Weinig b999f68ed9 Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class local to a function.
llvm-svn: 92200
2009-12-28 03:19:38 +00:00
Sam Weinig 07d211ea40 Fix for PR5844. Be explicit about anonymous struct/class/union/namespaces in __PRETTY_FUNCTION__ predefined expression.
llvm-svn: 92149
2009-12-24 23:15:03 +00:00
Anders Carlsson 714d0969b3 If a ParmVarDecl's default argument is a CXXExprWithTemporaries, return the underlying expr instead. Add getNumDefaultArgTemporaries and getDefaultArgTemporary which returns the temporaries a default arg creates.
llvm-svn: 91439
2009-12-15 19:16:31 +00:00
Anders Carlsson 7e0b207e54 More improvements to checking allocation and deallocation functions.
llvm-svn: 91244
2009-12-13 17:53:43 +00:00
Jeffrey Yasskin 1615d45daa Un-namespace-qualify llvm_unreachable. It's a macro, so the qualification gave
no extra safety anyway.

llvm-svn: 91207
2009-12-12 05:05:38 +00:00
John McCall 5677499fbf First pass at implementing C++ enum semantics: calculate (and store) an
"integer promotion" type associated with an enum decl, and use this type to
determine which type to promote to.  This type obeys C++ [conv.prom]p2 and
is therefore generally signed unless the range of the enumerators forces
it to be unsigned.

Kills off a lot of false positives from -Wsign-compare in C++, addressing
rdar://7455616

llvm-svn: 90965
2009-12-09 09:09:27 +00:00
John McCall bcd035061d DeclaratorInfo -> TypeSourceInfo. Makes an effort to rename associated variables,
but the results are imperfect.

For posterity, I did:

cat <<EOF > $cmdfile
s/DeclaratorInfo/TypeSourceInfo/g
s/DInfo/TInfo/g
s/TypeTypeSourceInfo/TypeSourceInfo/g
s/SourceTypeSourceInfo/TypeSourceInfo/g
EOF

find lib -name '*.cpp' -not -path 'lib/Parse/*' -exec sed -i '' -f $cmdfile '{}' \;
find lib -name '*.h' -exec sed -i '' -f $cmdfile '{}' \;
find include -name '*.h' -not -path 'include/clang/Parse/*' -not -path 'include/clang/Basic/*' -exec sed -i '' -f $cmdfile '{}' \;

llvm-svn: 90743
2009-12-07 02:54:59 +00:00
Anders Carlsson cfb65d7432 Be a little more clever about inline member functions that are marked inline in the inline class declaration but not in the actual definition:
class A {
  inline void f();
}

void A::f() { }

This is not the most ideal solution, since it doesn't work 100% with regular functions (as my FIXME comment states).

llvm-svn: 90607
2009-12-04 22:35:50 +00:00
Eli Friedman f873c2fb68 Slight tweak to the algorithm for getLinkage().
llvm-svn: 89932
2009-11-26 03:04:01 +00:00
Douglas Gregor f73b282bf0 Implement the rules in C++ [basic.link] and C99 6.2.2 for computing
the linkage of a declaration. Switch the lame (and completely wrong)
NamedDecl::hasLinkage() over to using the new NamedDecl::getLinkage(),
along with the "can this declaration be a template argument?" check
that started all of this.

Fixes -fsyntax-only for PR5597.

llvm-svn: 89891
2009-11-25 22:24:25 +00:00
John McCall 3f746828d7 Instead of hanging a using declaration's target decls directly off the using
decl, create shadow declarations and put them in scope like normal.
Work in progress.

llvm-svn: 89048
2009-11-17 05:59:44 +00:00
Douglas Gregor b7e5c847c4 Implement proper linkage for explicit instantiation declarations of
inlined functions. For example, given

  template<typename T>
  class string {
    unsigned Len;

  public:
    unsigned size() const { return Len; }
  };

  extern template class string<char>;

we now give the instantiation of string<char>::size
available_externally linkage (if it is ever instantiated!), as
permitted by the C++0x standard.
      

llvm-svn: 85340
2009-10-27 23:26:40 +00:00
Douglas Gregor 583dcafce4 Introduce FunctionDecl::isInlined() to tell whether a function should
be inlined.

llvm-svn: 85307
2009-10-27 21:11:48 +00:00
Douglas Gregor 35b5753e17 Rename FunctionDecl::isInline/setInline to
FunctionDecl::isInlineSpecified/setInlineSpecified.

llvm-svn: 85305
2009-10-27 21:01:01 +00:00
Douglas Gregor afca3b4a5c Explicit instantiation suppresses the instantiation of non-inline
function template specializations and member functions of class
template specializations.

llvm-svn: 85300
2009-10-27 20:53:28 +00:00
Douglas Gregor 1d957a336f An explicit instantiation definition only instantiations those class
members that have a definition. Also, use
CheckSpecializationInstantiationRedecl as part of this instantiation
to make sure that we diagnose the various kinds of problems that can
occur with explicit instantiations.

llvm-svn: 85270
2009-10-27 18:42:08 +00:00
John McCall 703a3f8a7b Preserve type source information in TypedefDecls. Preserve it across
template instantiation.  Preserve it through PCH.  Show it off to the indexer.

I'm healthily ignoring the vector type cases because we don't have a sensible
TypeLoc implementation for them anyway.

llvm-svn: 84994
2009-10-24 08:00:42 +00:00
John McCall 856bbea332 Remove OriginalTypeParmDecl; the original type is the one specified
in the DeclaratorInfo, if one is present.

Preserve source information through template instantiation.  This is made
more complicated by the possibility that ParmVarDecls don't have DIs, which
is possibly worth fixing in the future.

Also preserve source information for function parameters in ObjC method
declarations.

llvm-svn: 84971
2009-10-23 21:48:59 +00:00
Daniel Dunbar 2c422dc9ca Move clients to use IdentifierInfo::getNameStart() instead of getName()
llvm-svn: 84436
2009-10-18 20:26:12 +00:00
John McCall 1700197e65 Clone the full Type hierarchy into the TypeLoc hierarchy. Normalize
TypeLoc class names to be $(Type classname)Loc.  Rewrite the visitor.
Provide skeleton implementations for all the new TypeLocs.

Handle all cases in PCH.  Handle a few more cases when inserting
location information in SemaType.

It should be extremely straightforward to add new location information
to existing TypeLoc objects now.

llvm-svn: 84386
2009-10-18 01:05:36 +00:00
Douglas Gregor 3d7e69f2c9 Simplify checking of explicit template specialization/explicit
instantiation redeclaration semantics for function template
specializations and member functions of class template
specializations. Also, record the point of instantiation for
explicit-instantiated functions and static data members.

llvm-svn: 84188
2009-10-15 17:21:20 +00:00
Douglas Gregor 3cc3cdeea9 Give explicit and implicit instantiations of static data members of
class templates the proper linkage. 

Daniel, please look over the CodeGenModule bits.

llvm-svn: 84140
2009-10-14 21:29:40 +00:00
Douglas Gregor 3c74d41d27 Testing and some minor fixes for explicit template instantiation.
llvm-svn: 84129
2009-10-14 20:14:33 +00:00
Douglas Gregor cf91555cb8 When explicitly specializing a member that is a template, mark the
template as a specialization. For example, this occurs with:

  template<typename T>
  struct X {
    template<typename U> struct Inner { /* ... */ };
  };

  template<> template<typename T>
  struct X<int>::Inner {
    T member;
  };

We need to treat templates that are member specializations as special
in two contexts:

  - When looking for a definition of a member template, we look
    through the instantiation chain until we hit the primary template
    *or a member specialization*. This allows us to distinguish
    between the primary "Inner" definition and the X<int>::Inner
    definition, above.
  - When computing all of the levels of template arguments needed to
    instantiate a member template, don't add template arguments
    from contexts outside of the instantiation of a member
    specialization, since the user has already manually substituted
    those arguments.

Fix up the existing test for p18, which was actually wrong (but we
didn't diagnose it because of our poor handling of member
specializations of templates), and add a new test for member
specializations of templates.

llvm-svn: 83974
2009-10-13 16:30:37 +00:00
Douglas Gregor 06db9f50a2 Diagnose the declaration of explicit specializations after an implicit
instantiation has already been required. To do so, keep track of the
point of instantiation for anything that can be instantiated.

llvm-svn: 83890
2009-10-12 20:18:28 +00:00
John McCall 9f3059a192 Refactor the LookupResult API to simplify most common operations. Require users to
pass a LookupResult reference to lookup routines.  Call out uses which assume a single
result.

llvm-svn: 83674
2009-10-09 21:13:30 +00:00
Douglas Gregor 86d142a801 For instantiations of static data members of class templates, keep
track of the kind of specialization or instantiation. Also, check the
scope of the specialization and ensure that a specialization
declaration without an initializer is not a definition.

llvm-svn: 83533
2009-10-08 07:24:58 +00:00
Douglas Gregor d801b06232 Keep track of whether a member function instantiated from a member
function of a class template was implicitly instantiated, explicitly
instantiated (declaration or definition), or explicitly
specialized. The same MemberSpecializationInfo structure will be used
for static data members and member classes as well.

llvm-svn: 83509
2009-10-07 23:56:10 +00:00
Argyrios Kyrtzidis 1b7c4ca37d -Introduce TypeLoc::getOpaqueData()
-Make TypeLoc's constructor public.

llvm-svn: 83088
2009-09-29 19:40:20 +00:00
Mike Stump e7a2b48572 Fix http://llvm.org/PR5090.
llvm-svn: 83035
2009-09-29 00:50:50 +00:00
Douglas Gregor 3a923c2d37 WIP implementation of explicit function template specialization. This
first implementation recognizes when a function declaration is an
explicit function template specialization (based on the presence of a
template<> header), performs template argument deduction + ambiguity
resolution to determine which template is being specialized, and hooks

There are many caveats here:
  - We completely and totally drop any explicitly-specified template
  arguments on the floor
  - We don't diagnose any of the extra semantic things that we should
  diagnose. 
  - I haven't looked to see that we're getting the right linkage for
  explicit specializations

On a happy note, this silences a bunch of errors that show up in
libstdc++'s <iostream>, although Clang still can't get through the
entire header.

llvm-svn: 82728
2009-09-24 23:14:47 +00:00
John McCall 9dd450bb78 Change all the Type::getAsFoo() methods to specializations of Type::getAs().
Several of the existing methods were identical to their respective
specializations, and so have been removed entirely.  Several more 'leaf'
optimizations were introduced.

The getAsFoo() methods which imposed extra conditions, like
getAsObjCInterfacePointerType(), have been left in place.

llvm-svn: 82501
2009-09-21 23:43:11 +00:00