From f3fce80bb2eafaa556779c84f38104003bddb0ea Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 3 Aug 2012 08:39:58 +0000 Subject: [PATCH] Fix failed to generate vtables in certain cases. 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 | 3 +++ test/CodeGenCXX/cxx11-vtable-key-function.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/CodeGenCXX/cxx11-vtable-key-function.cpp diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 86a881481c..747b3529ce 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -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 index 0000000000..705a4addf6 --- /dev/null +++ b/test/CodeGenCXX/cxx11-vtable-key-function.cpp @@ -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 -- 2.50.1