From cc1aa268ed3e30a66e118a21df2b9edf39034907 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 14 Aug 2014 20:30:52 +0000 Subject: [PATCH] [modules] Turn off a broken optimization: we need to pick up implicit special members from all redefinitions of a class that have them, in case the special member is defined in one module but only declared in another. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215675 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 7 ++++-- test/Modules/Inputs/templates-left.h | 6 +++++ test/Modules/Inputs/templates-top.h | 13 ++++++++++ test/Modules/templates-2.mm | 36 ++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 test/Modules/templates-2.mm diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index dcb747fe8d..38837e2c06 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1301,8 +1301,11 @@ void ASTDeclReader::MergeDefinitionData( // If the new definition has new special members, let the name lookup // code know that it needs to look in the new definition too. - if ((MergeDD.DeclaredSpecialMembers & ~DD.DeclaredSpecialMembers) && - DD.Definition != MergeDD.Definition) { + // + // FIXME: We only need to do this if the merged definition declares members + // that this definition did not declare, or if it defines members that this + // definition did not define. + if (MergeDD.DeclaredSpecialMembers && DD.Definition != MergeDD.Definition) { Reader.MergedLookups[DD.Definition].push_back(MergeDD.Definition); DD.Definition->setHasExternalVisibleStorage(); } diff --git a/test/Modules/Inputs/templates-left.h b/test/Modules/Inputs/templates-left.h index 2bd79be945..7ca5cc52a1 100644 --- a/test/Modules/Inputs/templates-left.h +++ b/test/Modules/Inputs/templates-left.h @@ -60,3 +60,9 @@ template void testDelayUpdates(DelayUpdates *p = 0) {} void outOfLineInlineUseLeftF(void (OutOfLineInline::*)() = &OutOfLineInline::f); void outOfLineInlineUseLeftG(void (OutOfLineInline::*)() = &OutOfLineInline::g); void outOfLineInlineUseLeftH(void (OutOfLineInline::*)() = &OutOfLineInline::h); + +namespace EmitDefaultedSpecialMembers { + inline void f() { + SmallString<256> SS; + }; +} diff --git a/test/Modules/Inputs/templates-top.h b/test/Modules/Inputs/templates-top.h index 1216266f34..b1e0548d41 100644 --- a/test/Modules/Inputs/templates-top.h +++ b/test/Modules/Inputs/templates-top.h @@ -40,3 +40,16 @@ template struct OutOfLineInline { template inline void OutOfLineInline::f() {} template inline void OutOfLineInline::g() {} template inline void OutOfLineInline::h() {} + +namespace EmitDefaultedSpecialMembers { + template struct SmallVectorImpl { + SmallVectorImpl() {} + ~SmallVectorImpl() {} // non-trivial dtor + }; + template struct SmallVector : SmallVectorImpl { + // trivial dtor + }; + template struct SmallString : SmallVector { + // trivial dtor + }; +} diff --git a/test/Modules/templates-2.mm b/test/Modules/templates-2.mm new file mode 100644 index 0000000000..b7ceafbbc5 --- /dev/null +++ b/test/Modules/templates-2.mm @@ -0,0 +1,36 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs -verify %s -Wno-objc-root-class +// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | FileCheck %s +// expected-no-diagnostics + +@import templates_top; + +struct TestEmitDefaultedSpecialMembers { + EmitDefaultedSpecialMembers::SmallVector V; +}; + +@import templates_left; + +void testEmitDefaultedSpecialMembers() { + EmitDefaultedSpecialMembers::SmallString<256> V; + // CHECK: call {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EEC1Ev( + // CHECK: call {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EED1Ev( +} + +// CHECK-LABEL: define {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EEC1Ev( +// CHECK: call {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EEC2Ev( + +// CHECK-LABEL: define {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EED1Ev( +// CHECK: call {{.*}} @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EED2Ev( + +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EED2Ev( +// CHECK: call void @_ZN27EmitDefaultedSpecialMembers11SmallVectorIcLj256EED2Ev( +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers11SmallVectorIcLj256EED2Ev( +// CHECK: call void @_ZN27EmitDefaultedSpecialMembers15SmallVectorImplIcED2Ev( +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers15SmallVectorImplIcED2Ev( + +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers11SmallStringILj256EEC2Ev( +// CHECK: call void @_ZN27EmitDefaultedSpecialMembers11SmallVectorIcLj256EEC2Ev( +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers11SmallVectorIcLj256EEC2Ev( +// CHECK: call void @_ZN27EmitDefaultedSpecialMembers15SmallVectorImplIcEC2Ev( +// CHECK-LABEL: define linkonce_odr void @_ZN27EmitDefaultedSpecialMembers15SmallVectorImplIcEC2Ev( -- 2.50.1