diff options
author | Anders Carlsson <andersca@mac.com> | 2011-01-30 20:45:54 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-01-30 20:45:54 +0000 |
commit | a03f3a85cb8d7ed86943c12030088fddc05ba1b3 (patch) | |
tree | f05b7b39bc94045d4e2dd8f8ac46b4cc732b7b9c /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 9af7afcb7f834ff7a4b78a284051c53db984007c (diff) | |
download | bcm5719-llvm-a03f3a85cb8d7ed86943c12030088fddc05ba1b3.tar.gz bcm5719-llvm-a03f3a85cb8d7ed86943c12030088fddc05ba1b3.zip |
When building with optimizations, emit vtables where the key is not in the
current translation unit as available_externally.
This helps devirtualize the second example in PR3100, comment 18:
struct S { S() {}; virtual void xyzzy(); };
inline void foo(S *s) { s->xyzzy(); }
void bar() { S s; foo(&s); }
This involved four major changes:
1. In DefineUsedVTables, always mark virtual member functions as referenced for
non-template classes and class template specializations.
2. In CodeGenVTables::ShouldEmitVTableInThisTU return true if optimizations are
enabled, even if the key function is not implemented in this translation
unit. We don't ever do this for code compiled with -fapple-kext, because we
don't ever want to devirtualize virtual member function calls in that case.
3. Give the correct linkage for vtables where the key function is not defined.
4. Update the linkage for RTTI structures when necessary.
llvm-svn: 124565
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index acf2592c249..b8f91b464dd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1082,6 +1082,12 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { switch (KeyFunction->getTemplateSpecializationKind()) { case TSK_Undeclared: case TSK_ExplicitSpecialization: + // When compiling with optimizations turned on, we emit all vtables, + // even if the key function is not defined in the current translation + // unit. If this is the case, use available_externally linkage. + if (!Def && CodeGenOpts.OptimizationLevel) + return llvm::GlobalVariable::AvailableExternallyLinkage; + if (KeyFunction->isInlined()) return llvm::GlobalVariable::LinkOnceODRLinkage; |