[cfe-commits] r90645 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/virt-template-vtable.cpp
Eli Friedman
eli.friedman at gmail.com
Fri Dec 4 20:55:57 PST 2009
Author: efriedma
Date: Fri Dec 4 22:55:55 2009
New Revision: 90645
URL: http://llvm.org/viewvc/llvm-project?rev=90645&view=rev
Log:
Tweak "key function" rules so that they work for templates with virtual
inline functions.
Added:
cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=90645&r1=90644&r2=90645&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Dec 4 22:55:55 2009
@@ -663,6 +663,20 @@
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 @@
continue;
const FunctionDecl *fn;
- if (MD->getBody(fn) && !fn->isOutOfLine())
+ if (MethodHasBody(MD, fn) && !fn->isOutOfLine())
continue;
// We found it.
Added: cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp?rev=90645&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/virt-template-vtable.cpp Fri Dec 4 22:55:55 2009
@@ -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
More information about the cfe-commits
mailing list