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-14 00:44:06 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o %t
|
2010-08-13 07:36:15 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o %t.hidden
|
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-14 00:44:06 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-1 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-2 %s < %t
|
2010-08-13 07:36:15 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-2-HIDDEN %s < %t.hidden
|
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-14 00:44:06 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-3 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-4 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-5 %s < %t
|
2010-08-13 07:36:15 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-5-HIDDEN %s < %t.hidden
|
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-14 00:44:06 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-6 %s < %t
|
2010-08-13 07:36:15 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-6-HIDDEN %s < %t.hidden
|
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-14 00:44:06 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-7 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-8 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-9 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
|
2010-08-04 14:38:15 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-13 %s < %t
|
2009-12-06 01:04:47 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct A {
|
|
|
|
virtual void f() { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-12-06 06:19:10 +08:00
|
|
|
void f() { A b; }
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
B();
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
B::B() { }
|
|
|
|
|
2011-01-30 03:34:19 +08:00
|
|
|
struct C : virtual B {
|
2009-12-06 06:24:38 +08:00
|
|
|
C();
|
|
|
|
virtual void f() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
C::C() { }
|
|
|
|
|
2009-12-06 08:53:22 +08:00
|
|
|
struct D {
|
|
|
|
virtual void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
void D::f() { }
|
|
|
|
|
2009-12-12 04:48:18 +08:00
|
|
|
static struct : D { } e;
|
|
|
|
|
2010-01-06 05:40:05 +08:00
|
|
|
// The destructor is the key function.
|
2010-01-06 03:06:31 +08:00
|
|
|
template<typename T>
|
|
|
|
struct E {
|
|
|
|
virtual ~E();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> E<T>::~E() { }
|
|
|
|
|
2010-01-06 05:40:05 +08:00
|
|
|
// Anchor is the key function
|
2010-01-06 03:06:31 +08:00
|
|
|
template<>
|
|
|
|
struct E<char> {
|
|
|
|
virtual void anchor();
|
|
|
|
};
|
|
|
|
|
|
|
|
void E<char>::anchor() { }
|
|
|
|
|
|
|
|
template struct E<short>;
|
|
|
|
extern template struct E<int>;
|
|
|
|
|
|
|
|
void use_E() {
|
|
|
|
E<int> ei;
|
|
|
|
(void)ei;
|
|
|
|
E<long> el;
|
|
|
|
(void)el;
|
|
|
|
}
|
|
|
|
|
2010-01-06 05:40:05 +08:00
|
|
|
// No key function
|
|
|
|
template<typename T>
|
|
|
|
struct F {
|
|
|
|
virtual void foo() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
// No key function
|
|
|
|
template<>
|
|
|
|
struct F<char> {
|
|
|
|
virtual void foo() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct F<short>;
|
|
|
|
extern template struct F<int>;
|
|
|
|
|
2010-08-04 14:38:15 +08:00
|
|
|
void use_F() {
|
|
|
|
F<char> fc;
|
|
|
|
fc.foo();
|
2010-01-06 05:40:05 +08:00
|
|
|
F<int> fi;
|
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-14 00:44:06 +08:00
|
|
|
fi.foo();
|
2010-01-06 05:40:05 +08:00
|
|
|
F<long> fl;
|
|
|
|
(void)fl;
|
|
|
|
}
|
|
|
|
|
2009-12-06 06:19:10 +08:00
|
|
|
// B has a key function that is not defined in this translation unit so its vtable
|
|
|
|
// has external linkage.
|
2011-01-15 16:23:14 +08:00
|
|
|
// CHECK-1: @_ZTV1B = external unnamed_addr constant
|
2009-12-06 06:19:10 +08:00
|
|
|
|
2010-08-03 15:24:12 +08:00
|
|
|
// C has no key function, so its vtable should have weak_odr linkage
|
|
|
|
// and hidden visibility (rdar://problem/7523229).
|
2011-01-24 08:46:19 +08:00
|
|
|
// CHECK-2: @_ZTV1C = linkonce_odr unnamed_addr constant
|
|
|
|
// CHECK-2: @_ZTS1C = linkonce_odr constant
|
|
|
|
// CHECK-2: @_ZTI1C = linkonce_odr unnamed_addr constant
|
2011-01-30 03:34:19 +08:00
|
|
|
// CHECK-2: @_ZTT1C = linkonce_odr unnamed_addr constant
|
2011-01-24 08:46:19 +08:00
|
|
|
// CHECK-2-HIDDEN: @_ZTV1C = linkonce_odr hidden unnamed_addr constant
|
|
|
|
// CHECK-2-HIDDEN: @_ZTS1C = linkonce_odr constant
|
|
|
|
// CHECK-2-HIDDEN: @_ZTI1C = linkonce_odr hidden unnamed_addr constant
|
2011-01-30 03:34:19 +08:00
|
|
|
// CHECK-2-HIDDEN: @_ZTT1C = linkonce_odr hidden unnamed_addr constant
|
2009-12-06 06:24:38 +08:00
|
|
|
|
2009-12-06 08:53:22 +08:00
|
|
|
// D has a key function that is defined in this translation unit so its vtable is
|
|
|
|
// defined in the translation unit.
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-3: @_ZTV1D = unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-3: @_ZTS1D = constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-3: @_ZTI1D = unnamed_addr constant
|
2009-12-06 08:53:22 +08:00
|
|
|
|
2010-01-06 03:06:31 +08:00
|
|
|
// E<char> is an explicit specialization with a key function defined
|
|
|
|
// in this translation unit, so its vtable should have external
|
|
|
|
// linkage.
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-4: @_ZTV1EIcE = unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-4: @_ZTS1EIcE = constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-4: @_ZTI1EIcE = unnamed_addr constant
|
2010-01-06 03:06:31 +08:00
|
|
|
|
|
|
|
// E<short> is an explicit template instantiation with a key function
|
|
|
|
// defined in this translation unit, so its vtable should have
|
|
|
|
// weak_odr linkage.
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-5: @_ZTV1EIsE = weak_odr unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-5: @_ZTS1EIsE = weak_odr constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-5: @_ZTI1EIsE = weak_odr unnamed_addr constant
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-5-HIDDEN: @_ZTV1EIsE = weak_odr unnamed_addr constant
|
2010-08-13 07:36:15 +08:00
|
|
|
// CHECK-5-HIDDEN: @_ZTS1EIsE = weak_odr constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-5-HIDDEN: @_ZTI1EIsE = weak_odr unnamed_addr constant
|
2010-01-06 03:06:31 +08:00
|
|
|
|
2010-01-06 05:40:05 +08:00
|
|
|
// F<short> is an explicit template instantiation without a key
|
|
|
|
// function, so its vtable should have weak_odr linkage
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-6: @_ZTV1FIsE = weak_odr unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-6: @_ZTS1FIsE = weak_odr constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-6: @_ZTI1FIsE = weak_odr unnamed_addr constant
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-6-HIDDEN: @_ZTV1FIsE = weak_odr unnamed_addr constant
|
2010-08-13 07:36:15 +08:00
|
|
|
// CHECK-6-HIDDEN: @_ZTS1FIsE = weak_odr constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-6-HIDDEN: @_ZTI1FIsE = weak_odr unnamed_addr constant
|
2010-01-06 05:40:05 +08:00
|
|
|
|
2010-01-06 03:06:31 +08:00
|
|
|
// E<long> is an implicit template instantiation with a key function
|
|
|
|
// defined in this translation unit, so its vtable should have
|
2011-01-24 08:46:19 +08:00
|
|
|
// linkonce_odr linkage.
|
|
|
|
// CHECK-7: @_ZTV1EIlE = linkonce_odr unnamed_addr constant
|
|
|
|
// CHECK-7: @_ZTS1EIlE = linkonce_odr constant
|
|
|
|
// CHECK-7: @_ZTI1EIlE = linkonce_odr unnamed_addr constant
|
2010-01-06 03:06:31 +08:00
|
|
|
|
2010-01-06 05:40:05 +08:00
|
|
|
// F<long> is an implicit template instantiation with no key function,
|
2011-01-24 08:46:19 +08:00
|
|
|
// so its vtable should have linkonce_odr linkage.
|
|
|
|
// CHECK-8: @_ZTV1FIlE = linkonce_odr unnamed_addr constant
|
|
|
|
// CHECK-8: @_ZTS1FIlE = linkonce_odr constant
|
|
|
|
// CHECK-8: @_ZTI1FIlE = linkonce_odr unnamed_addr constant
|
2010-01-06 05:40:05 +08:00
|
|
|
|
|
|
|
// F<int> is an explicit template instantiation declaration without a
|
2010-04-03 12:26:42 +08:00
|
|
|
// key function, so its vtable should have external linkage.
|
2011-01-15 16:23:14 +08:00
|
|
|
// CHECK-9: @_ZTV1FIiE = external unnamed_addr constant
|
2010-01-06 05:40:05 +08:00
|
|
|
|
2010-01-06 03:06:31 +08:00
|
|
|
// E<int> is an explicit template instantiation declaration. It has a
|
2010-01-07 12:09:30 +08:00
|
|
|
// key function that is not instantiated, so we should only reference
|
2010-01-06 03:06:31 +08:00
|
|
|
// its vtable, not define it.
|
2011-01-15 16:23:14 +08:00
|
|
|
// CHECK-10: @_ZTV1EIiE = external unnamed_addr constant
|
2010-01-06 03:06:31 +08:00
|
|
|
|
2010-01-08 08:50:11 +08:00
|
|
|
// The anonymous struct for e has no linkage, so the vtable should have
|
|
|
|
// internal linkage.
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-11: @"_ZTV3$_0" = internal unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-11: @"_ZTS3$_0" = internal constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-11: @"_ZTI3$_0" = internal unnamed_addr constant
|
2010-01-08 08:50:11 +08:00
|
|
|
|
2009-12-06 06:19:10 +08:00
|
|
|
// The A vtable should have internal linkage since it is inside an anonymous
|
|
|
|
// namespace.
|
2011-01-12 05:10:26 +08:00
|
|
|
// CHECK-12: @_ZTVN12_GLOBAL__N_11AE = internal unnamed_addr constant
|
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-14 00:44:06 +08:00
|
|
|
// CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant
|
2011-01-12 07:55:05 +08:00
|
|
|
// CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal unnamed_addr constant
|
2010-01-06 03:06:31 +08:00
|
|
|
|
2010-08-04 14:38:15 +08:00
|
|
|
// F<char> is an explicit specialization without a key function, so
|
2011-01-24 08:46:19 +08:00
|
|
|
// its vtable should have linkonce_odr linkage.
|
|
|
|
// CHECK-13: @_ZTV1FIcE = linkonce_odr unnamed_addr constant
|
|
|
|
// CHECK-13: @_ZTS1FIcE = linkonce_odr constant
|
|
|
|
// CHECK-13: @_ZTI1FIcE = linkonce_odr unnamed_addr constant
|
2010-08-04 14:38:15 +08:00
|
|
|
|
2010-05-25 08:33:13 +08:00
|
|
|
// RUN: FileCheck --check-prefix=CHECK-G %s < %t
|
|
|
|
//
|
2011-01-24 08:46:19 +08:00
|
|
|
// CHECK-G: @_ZTV1GIiE = linkonce_odr unnamed_addr constant
|
2010-05-25 08:33:13 +08:00
|
|
|
template <typename T>
|
|
|
|
class G {
|
|
|
|
public:
|
|
|
|
G() {}
|
|
|
|
virtual void f0();
|
|
|
|
virtual void f1();
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
void G<int>::f1() {}
|
|
|
|
template <typename T>
|
|
|
|
void G<T>::f0() {}
|
|
|
|
void G_f0() { new G<int>(); }
|
2010-10-11 11:25:57 +08:00
|
|
|
|
|
|
|
// RUN: FileCheck --check-prefix=CHECK-H %s < %t
|
|
|
|
|
|
|
|
// H<int> has a key function without a body but it's a template instantiation
|
2011-04-15 13:22:18 +08:00
|
|
|
// so its VTable must be emitted.
|
2011-01-24 08:46:19 +08:00
|
|
|
// CHECK-H: @_ZTV1HIiE = linkonce_odr unnamed_addr constant
|
2010-10-11 11:25:57 +08:00
|
|
|
template <typename T>
|
|
|
|
class H {
|
|
|
|
public:
|
|
|
|
virtual ~H();
|
|
|
|
};
|
|
|
|
|
|
|
|
void use_H() {
|
|
|
|
H<int> h;
|
|
|
|
}
|