diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-12-05 04:55:55 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-12-05 04:55:55 +0000 |
commit | 0846d52f70b8173096fd1f7d4a3acc2edf680b65 (patch) | |
tree | 6e50556b8b5f83d454838d2a6d2587098432f374 /clang | |
parent | 455c5776e24fca3daab9135741bf456dad8633ba (diff) | |
download | bcm5719-llvm-0846d52f70b8173096fd1f7d4a3acc2edf680b65.tar.gz bcm5719-llvm-0846d52f70b8173096fd1f7d4a3acc2edf680b65.zip |
Tweak "key function" rules so that they work for templates with virtual
inline functions.
llvm-svn: 90645
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/AST/RecordLayoutBuilder.cpp | 16 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/virt-template-vtable.cpp | 12 |
2 files changed, 27 insertions, 1 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index 3a1e248dbc0..4c7b9119348 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -663,6 +663,20 @@ void ASTRecordLayoutBuilder::UpdateAlignment(unsigned NewAlignment) { Alignment = NewAlignment; } +static bool MethodHasBody(const CXXMethodDecl *MD, const FunctionDecl *&fn) { + // Simple case: function has a body + if (MD->getBody(fn)) + return true; + + // Complex case: function is an instantiation of a function which has a + // body, but the definition hasn't been instantiated. + const FunctionDecl *PatternDecl = MD->getTemplateInstantiationPattern(); + if (PatternDecl && PatternDecl->getBody(fn)) + return true; + + return false; +} + static const CXXMethodDecl *GetKeyFunction(const CXXRecordDecl *RD) { if (!RD->isDynamicClass()) return 0; @@ -683,7 +697,7 @@ static const CXXMethodDecl *GetKeyFunction(const CXXRecordDecl *RD) { continue; const FunctionDecl *fn; - if (MD->getBody(fn) && !fn->isOutOfLine()) + if (MethodHasBody(MD, fn) && !fn->isOutOfLine()) continue; // We found it. diff --git a/clang/test/CodeGenCXX/virt-template-vtable.cpp b/clang/test/CodeGenCXX/virt-template-vtable.cpp new file mode 100644 index 00000000000..478daa75cb0 --- /dev/null +++ b/clang/test/CodeGenCXX/virt-template-vtable.cpp @@ -0,0 +1,12 @@ +// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s + +template<class T> class A { + A() {} + virtual void a() {} +}; +class B : A<int> { + B(); +}; +B::B() {} + +// CHECK: @_ZTV1AIiE = linkonce_odr constant |