r215675 - [modules] Turn off a broken optimization: we need to pick up implicit special

Richard Smith richard-llvm at metafoo.co.uk
Thu Aug 14 13:30:52 PDT 2014


Author: rsmith
Date: Thu Aug 14 15:30:52 2014
New Revision: 215675

URL: http://llvm.org/viewvc/llvm-project?rev=215675&view=rev
Log:
[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.

Added:
    cfe/trunk/test/Modules/templates-2.mm
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/Modules/Inputs/templates-left.h
    cfe/trunk/test/Modules/Inputs/templates-top.h

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=215675&r1=215674&r2=215675&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Aug 14 15:30:52 2014
@@ -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();
   }

Modified: cfe/trunk/test/Modules/Inputs/templates-left.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/templates-left.h?rev=215675&r1=215674&r2=215675&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/templates-left.h (original)
+++ cfe/trunk/test/Modules/Inputs/templates-left.h Thu Aug 14 15:30:52 2014
@@ -60,3 +60,9 @@ template<typename T> void testDelayUpdat
 void outOfLineInlineUseLeftF(void (OutOfLineInline<int>::*)() = &OutOfLineInline<int>::f);
 void outOfLineInlineUseLeftG(void (OutOfLineInline<int>::*)() = &OutOfLineInline<int>::g);
 void outOfLineInlineUseLeftH(void (OutOfLineInline<int>::*)() = &OutOfLineInline<int>::h);
+
+namespace EmitDefaultedSpecialMembers {
+  inline void f() {
+    SmallString<256> SS;
+  };
+}

Modified: cfe/trunk/test/Modules/Inputs/templates-top.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/templates-top.h?rev=215675&r1=215674&r2=215675&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/templates-top.h (original)
+++ cfe/trunk/test/Modules/Inputs/templates-top.h Thu Aug 14 15:30:52 2014
@@ -40,3 +40,16 @@ template<typename T> struct OutOfLineInl
 template<typename T> inline void OutOfLineInline<T>::f() {}
 template<typename T> inline void OutOfLineInline<T>::g() {}
 template<typename T> inline void OutOfLineInline<T>::h() {}
+
+namespace EmitDefaultedSpecialMembers {
+  template<typename T> struct SmallVectorImpl {
+    SmallVectorImpl() {}
+    ~SmallVectorImpl() {} // non-trivial dtor
+  };
+  template<typename T, unsigned N> struct SmallVector : SmallVectorImpl<T> {
+    // trivial dtor
+  };
+  template<unsigned N> struct SmallString : SmallVector<char, N> {
+    // trivial dtor
+  };
+}

Added: cfe/trunk/test/Modules/templates-2.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/templates-2.mm?rev=215675&view=auto
==============================================================================
--- cfe/trunk/test/Modules/templates-2.mm (added)
+++ cfe/trunk/test/Modules/templates-2.mm Thu Aug 14 15:30:52 2014
@@ -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
+
+ at import templates_top;
+
+struct TestEmitDefaultedSpecialMembers {
+  EmitDefaultedSpecialMembers::SmallVector<char, 256> V;
+};
+
+ at 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(





More information about the cfe-commits mailing list