]> granicus.if.org Git - clang/commitdiff
Fix failed to generate vtables in certain cases.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 3 Aug 2012 08:39:58 +0000 (08:39 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 3 Aug 2012 08:39:58 +0000 (08:39 +0000)
By C++ standard, the vtable should be generated if the first non-inline
virtual function is defined in the TU.  Current version of clang doesn't
generate vtable if the first virtual function is defaulted, because the
key function is regarded as the defaulted function.

Patch by Li Kan!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161236 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/RecordLayoutBuilder.cpp
test/CodeGenCXX/cxx11-vtable-key-function.cpp [new file with mode: 0644]

index 86a881481c99fb1099337b7de5c80cdf753283d4..747b3529cebfab1adceec88ebc44e125f2fc8f86 100644 (file)
@@ -2351,6 +2351,9 @@ RecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
     if (MD->hasInlineBody())
       continue;
 
+    if (!MD->isUserProvided())
+      continue;
+
     // We found it.
     return MD;
   }
diff --git a/test/CodeGenCXX/cxx11-vtable-key-function.cpp b/test/CodeGenCXX/cxx11-vtable-key-function.cpp
new file mode 100644 (file)
index 0000000..705a4ad
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -std=c++11 | FileCheck %s
+// PR13424
+
+struct X {
+  virtual ~X() = default;
+  virtual void f();
+};
+
+void X::f() {}
+
+// CHECK: @_ZTV1X = unnamed_addr constant