llvm-project/clang/test/SemaTemplate
Douglas Gregor 88d292ccb8 Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions. 

The new scheme:
  - For every use of a vtable, Sema calls MarkVTableUsed() to indicate
  the use. For example, this occurs when calling a virtual member
  function of the class, defining a constructor of that class type,
  dynamic_cast'ing from that type to a derived class, casting
  to/through a virtual base class, etc.
  - For every definition of a vtable, Sema calls MarkVTableUsed() to
  indicate the definition. This happens at the end of the translation
  unit for classes whose key function has been defined (so we can
  delay computation of the key function; see PR6564), and will also
  occur with explicit template instantiation definitions.
 - For every vtable defined/used, we mark all of the virtual member
 functions of that vtable as defined/used, unless we know that the key
 function is in another translation unit. This instantiates virtual
 member functions when needed.
  - At the end of the translation unit, Sema tells CodeGen (via the
  ASTConsumer) which vtables must be defined (CodeGen will define
  them) and which may be used (for which CodeGen will define the
  vtables lazily). 

From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).

Notes:
  (1) There's a ton of churn in the tests, because the order in which
  vtables get emitted to IR has changed. I've tried to isolate some of
  the larger tests from these issues.
  (2) Some diagnostics related to
  implicitly-instantiated/implicitly-defined virtual member functions
  have moved to the point of first use/definition. It's better this
  way.
  (3) I could use a review of the places where we MarkVTableUsed, to
  see if I missed any place where the language effectively requires a
  vtable.

Fixes PR7114 and PR6564.

llvm-svn: 103718
2010-05-13 16:44:06 +00:00
..
ackermann.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
ambiguous-ovl-print.cpp Improve the reporting of non-viable overload candidates by noting the reason 2010-01-13 00:25:19 +00:00
anonymous-union.cpp Add test case for PR5868, and improve location information slightly for implicit "this" expressions 2009-12-24 20:23:34 +00:00
canonical-expr-type-0x.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
canonical-expr-type.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
class-template-ctor-initializer.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
class-template-decl.cpp Fix a crash-on-invalid involving name lookup of tag names, where we 2010-04-12 16:00:01 +00:00
class-template-id-2.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
class-template-id.cpp Switch the initialization required by return statements over to the 2009-12-18 05:02:21 +00:00
class-template-spec.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
constructor-template.cpp Improve our handling of user-defined conversions as part of overload 2010-04-17 22:01:05 +00:00
copy-ctor-assign.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
current-instantiation.cpp Static data members intialized in-class that have constant values are 2010-05-11 16:41:27 +00:00
deduction.cpp Require a complete type before examining base classes during template argument 2010-02-07 21:33:28 +00:00
default-arguments-cxx0x.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
default-arguments.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
default-expr-arguments-2.cpp Be sure to instantiate the parameters of a function, even when the 2010-04-12 07:48:19 +00:00
default-expr-arguments.cpp Ensure that we have completed a type before attempting initialization 2010-04-26 14:36:57 +00:00
dependent-base-classes.cpp Improve diagnostics when an elaborated-type-specifer containing a 2010-03-31 23:17:41 +00:00
dependent-base-member-init.cpp Another test case for PR6062 2010-01-19 06:47:24 +00:00
dependent-expr.cpp When determining whether a DeclRefExpr is value-dependent when it 2010-01-15 16:21:02 +00:00
dependent-names.cpp Turn access control on by default in -cc1. 2010-04-09 19:03:51 +00:00
dependent-sized_array.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
dependent-type-identity.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
destructor-template.cpp Strip cv-qualifiers when building C++ constructor and destructor 2010-04-23 04:51:46 +00:00
elaborated-type-specifier.cpp Tweak test case slightly 2010-04-24 16:40:35 +00:00
enum-argument.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
example-dynarray.cpp Update tests to use %clang instead of 'clang', and forcibly disable use of ' 2009-12-15 22:01:24 +00:00
example-typelist.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
explicit-instantiation.cpp Skip implicit instantiation of templated variables where a more recent 2010-02-13 10:17:50 +00:00
explicit-specialization-member.cpp Fix some redundant errors by changing CXXScopeSpec::isSet calls into 2010-04-07 23:29:58 +00:00
ext-vector-type.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
extern-templates.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
fibonacci.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
friend-template.cpp When computing the template arguments for the instantiation of a 2010-05-03 23:29:10 +00:00
friend.cpp Fix a crash-on-invalid involving name lookup of tag names, where we 2010-04-12 16:00:01 +00:00
fun-template-def.cpp Improve diagnostics when we fail to convert from a source type to a 2010-04-09 00:35:39 +00:00
function-template-specialization.cpp When performing name lookup into a scope, check that its entity is 2010-01-11 22:40:45 +00:00
implicit-instantiation-1.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
injected-class-name.cpp When we start the definition of a class template, set the 2010-04-30 04:39:27 +00:00
instantiate-anonymous-union.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-array.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-attr.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-c99.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-call.cpp Introduce a centralized routine in Sema for diagnosing failed lookups (when 2009-12-16 08:11:27 +00:00
instantiate-case.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-cast.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiate-clang.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-complete.cpp Reapply the reference-binding patch applied below, along with a fix to 2010-05-07 19:42:26 +00:00
instantiate-decl-dtor.cpp Make sure we instantiate the destructor for variables initialized by 2009-12-20 22:29:11 +00:00
instantiate-decl-init.cpp A dependent initializer with zero arguments should return a NULL 2010-02-05 07:56:11 +00:00
instantiate-declref-ice.cpp Migrate the mish-mash of declaration checks in 2010-02-09 07:26:29 +00:00
instantiate-declref.cpp Improve diagnostics when an elaborated-type-specifer containing a 2010-03-31 23:17:41 +00:00
instantiate-deeply.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-default-assignment-operator.cpp Complete reimplementation of the synthesis for implicitly-defined copy 2010-05-01 20:49:11 +00:00
instantiate-dependent-nested-name.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-elab-type-specifier.cpp Change the representation of dependent elaborated-type-specifiers 2010-03-31 22:19:08 +00:00
instantiate-enum-2.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-enum.cpp When instantiating a function-scoped enum, make sure that it and its 2010-03-01 19:00:07 +00:00
instantiate-exception-spec.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiate-expr-1.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiate-expr-2.cpp Collapse the three separate initialization paths in 2010-04-16 22:09:46 +00:00
instantiate-expr-3.cpp When instantiating statements that involve conditions (if, while, do, 2010-05-08 22:20:28 +00:00
instantiate-expr-4.cpp Re-bind non-dependent CXXTemporaryObjectExpr nodes as temporaries when 2010-03-31 18:34:58 +00:00
instantiate-expr-5.cpp Fix template instantiation for __builtin_offfsetof expressions that refer to members of anonymous structs/unions 2010-04-28 22:43:14 +00:00
instantiate-expr-basic.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-field.cpp Whenever we instantiate a function definition or class, enter a new 2010-05-12 17:27:19 +00:00
instantiate-friend-class.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-function-1.cpp When instantiating a function-local variable definition, introduce the 2010-05-03 20:22:41 +00:00
instantiate-function-1.mm Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-function-2.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-function-params.cpp When instantiating a function that was declared via a typedef, e.g., 2010-05-04 18:18:31 +00:00
instantiate-init.cpp When pulling apart an initializer that involves a CXXConstructExpr, do 2010-03-24 21:22:47 +00:00
instantiate-invalid.cpp Robustify instantiation of templates when there are errors in the 2010-03-01 18:27:54 +00:00
instantiate-local-class.cpp Turn access control on by default in -cc1. 2010-04-09 19:03:51 +00:00
instantiate-member-class.cpp Turn access control on by default in -cc1. 2010-04-09 19:03:51 +00:00
instantiate-member-expr.cpp Improve the diagnostic you get when making a qualified member access 2010-04-27 01:43:38 +00:00
instantiate-member-initializers.cpp Diagnose misordered initializers in constructor templates immediately instead of 2010-04-10 07:37:23 +00:00
instantiate-member-pointers.cpp A DeclRefExpr that refers to a member function or a static data member 2010-05-11 08:41:30 +00:00
instantiate-member-template.cpp Whenever we complain about a failed initialization of a function or 2010-04-22 00:20:18 +00:00
instantiate-method.cpp When instantiating a member function declared via a typedef, don't try 2010-05-03 15:32:18 +00:00
instantiate-non-dependent-types.cpp When we encounter a non-dependent type during template instantiation, 2010-05-07 23:12:07 +00:00
instantiate-non-type-template-parameter.cpp After substituting a template argument for a non-type template 2010-04-30 21:46:38 +00:00
instantiate-objc-1.mm Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-overload-candidates.cpp Add a test for a subtle instantiation pattern that showed up within a Boost 2010-05-11 08:02:08 +00:00
instantiate-overloaded-arrow.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-static-var.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiate-subscript.cpp Improve the lead diagnostic for C++ object subscript expressions with 2010-01-07 02:04:15 +00:00
instantiate-template-template-parm.cpp In Sema::CheckInitializerTypes, replace a use of CheckReferenceInit with an InitializationSequence 2009-12-16 16:54:16 +00:00
instantiate-try-catch.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-type.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiate-typedef.cpp Make CXXScopeSpec invalid when incomplete, and propagate that into any 2010-04-08 16:38:48 +00:00
instantiate-using-decl.cpp Turn access control on by default in -cc1. 2010-04-09 19:03:51 +00:00
instantiation-backtrace.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiation-default-1.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
instantiation-default-2.cpp Overhaul checking of non-type template arguments that should refer to 2010-04-01 18:32:35 +00:00
instantiation-default-3.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
instantiation-depth.cpp Reword the note we emit when suppressing template instantiation contexts, per John's advice 2010-04-21 05:40:43 +00:00
member-access-expr.cpp Use CXXPseudoDestructorExpr as the stored representation for dependent 2010-02-25 01:56:36 +00:00
member-function-template.cpp Fix two issues with the substitution of template template parameters 2010-02-05 19:54:12 +00:00
member-initializers.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
member-template-access-expr.cpp When determining whether the type is the current instantiation, strip 2010-01-15 16:05:33 +00:00
metafun-apply.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
nested-linkage.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
nested-name-spec-template.cpp Rebuild the nested name specifiers in member-pointer declarator chunks when 2010-04-29 23:50:39 +00:00
nested-template.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
operator-function-id-template.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
operator-template.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
overload-candidates.cpp Record template argument deduction failures for member function 2010-05-08 20:18:54 +00:00
overload-uneval.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
partial-spec-instantiate.cpp Partial and full specializations of a class template may have a 2010-05-06 00:28:52 +00:00
qualified-id.cpp Turn access control on by default in -cc1. 2010-04-09 19:03:51 +00:00
qualified-names-diag.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
recursive-template-instantiation.cpp Note that an overload candidate was non-viable because template argument 2010-02-01 18:53:26 +00:00
temp.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_arg.cpp Explain that a template needs arguments to make it into a type, for 2010-04-08 21:04:54 +00:00
temp_arg_nontype.cpp It turns out that we *can* end up having to display template argument 2010-04-29 04:55:13 +00:00
temp_arg_template.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_arg_type.cpp When instantiating a typedef of an anonymous tag type, note in the tag 2010-04-23 16:25:07 +00:00
temp_class_order.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_class_spec.cpp Implement a specific diagnostic when a class template partial 2010-02-09 00:37:32 +00:00
temp_class_spec_blocks.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_class_spec_neg.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_explicit.cpp The C++98/03 standard is disturbingly silent about out-of-scope 2010-05-11 17:39:34 +00:00
temp_explicit_cxx0x.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
temp_func_order.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
template-class-traits.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
template-decl-fail.cpp It's okay to reference an enum in a template definition, even though 2010-05-03 17:48:54 +00:00
template-id-expr.cpp Support for 'template' as a disambiguator (PR7030) 2010-05-05 05:58:24 +00:00
template-id-printing.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
typename-specifier-2.cpp Switch file-scope assignment initialization over to InitializationSequence. 2009-12-22 02:10:53 +00:00
typename-specifier-3.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
typename-specifier-4.cpp Rebuild the nested name specifiers in member-pointer declarator chunks when 2010-04-29 23:50:39 +00:00
typename-specifier.cpp Make CXXScopeSpec invalid when incomplete, and propagate that into any 2010-04-08 16:38:48 +00:00
typo-dependent-name.cpp When determining whether a given name is a template in a dependent 2010-01-12 17:06:20 +00:00
unused-variables.cpp Improve our handling of the -Wunused-variable warning in templates. In 2010-05-08 23:05:03 +00:00
value-dependent-null-pointer-constant.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
variadic-class-template-1.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
variadic-class-template-2.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
variadic-parse.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
variadic-unsupported.cpp Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'. 2009-12-15 20:14:24 +00:00
virtual-member-functions.cpp Rework when and how vtables are emitted, by tracking where vtables are 2010-05-13 16:44:06 +00:00