From: Reid Kleckner Date: Fri, 18 Jul 2014 01:48:10 +0000 (+0000) Subject: Mark the vtable used when defining implicit copy and move ctors X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d06d6c87a18c59527795652d7bfc19708c1af2f;p=clang Mark the vtable used when defining implicit copy and move ctors I don't think other implicit members like copy assignment and move assignment require this treatment, because they should already be operating on a constructed object. Fixes PR20351. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213346 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 14be51111d..3f9e63fc95 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -10384,6 +10384,8 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation, } CopyConstructor->markUsed(Context); + MarkVTableUsed(CurrentLocation, ClassDecl); + if (ASTMutationListener *L = getASTMutationListener()) { L->CompletedImplicitDefinition(CopyConstructor); } @@ -10542,6 +10544,7 @@ void Sema::DefineImplicitMoveConstructor(SourceLocation CurrentLocation, } MoveConstructor->markUsed(Context); + MarkVTableUsed(CurrentLocation, ClassDecl); if (ASTMutationListener *L = getASTMutationListener()) { L->CompletedImplicitDefinition(MoveConstructor); diff --git a/test/CodeGenCXX/microsoft-abi-structors.cpp b/test/CodeGenCXX/microsoft-abi-structors.cpp index 04227e311b..7d3992b994 100644 --- a/test/CodeGenCXX/microsoft-abi-structors.cpp +++ b/test/CodeGenCXX/microsoft-abi-structors.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=i386-pc-win32 -fno-rtti > %t +// RUN: %clang_cc1 -emit-llvm -fno-rtti %s -std=c++11 -o - -mconstructor-aliases -triple=i386-pc-win32 -fno-rtti > %t // RUN: FileCheck %s < %t // vftables are emitted very late, so do another pass to try to keep the checks // in source order. @@ -406,6 +406,26 @@ void construct_b() { // CHECK: (%"struct.test1::B"* {{.*}}, i32 1, i8* {{.*}}, i32 1, i32 2) } +namespace implicit_copy_vtable { +// This was a crash that only reproduced in ABIs without key functions. +struct ImplicitCopy { + // implicit copy ctor + virtual ~ImplicitCopy(); +}; +void CreateCopy(ImplicitCopy *a) { + new ImplicitCopy(*a); +} +// CHECK: store {{.*}} @"\01??_7ImplicitCopy@implicit_copy_vtable@@6B@" + +struct MoveOnly { + MoveOnly(MoveOnly &&o) = default; + virtual ~MoveOnly(); +}; +MoveOnly &&f(); +void g() { new MoveOnly(f()); } +// CHECK: store {{.*}} @"\01??_7MoveOnly@implicit_copy_vtable@@6B@" +} + // Dtor thunks for classes in anonymous namespaces should be internal, not // linkonce_odr. namespace {