r210715 - Don't inherit dllimport to inline move assignment operators

Hans Wennborg hans at hanshq.net
Wed Jun 11 15:44:39 PDT 2014


Author: hans
Date: Wed Jun 11 17:44:39 2014
New Revision: 210715

URL: http://llvm.org/viewvc/llvm-project?rev=210715&view=rev
Log:
Don't inherit dllimport to inline move assignment operators

Current MSVC versions don't have move assignment operators, so we
can't rely on them being available in the dll. If we have the
definition, we can just use that directly. This breaks pointer
equality, but should work fine otherwise.

When there is an MSVC version that supports move assignment,
we can key this off the -fmsc-ver option.

http://reviews.llvm.org/D4105

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CodeGenCXX/dllimport.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=210715&r1=210714&r2=210715&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jun 11 17:44:39 2014
@@ -4377,10 +4377,23 @@ static void checkDLLAttribute(Sema &S, C
   // specialization bases.
 
   for (Decl *Member : Class->decls()) {
-    if (!isa<CXXMethodDecl>(Member) && !isa<VarDecl>(Member))
+    VarDecl *VD = dyn_cast<VarDecl>(Member);
+    CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member);
+
+    // Only methods and static fields inherit the attributes.
+    if (!VD && !MD)
+      continue;
+
+    // Don't process deleted methods.
+    if (MD && MD->isDeleted())
       continue;
-    if (isa<CXXMethodDecl>(Member) && cast<CXXMethodDecl>(Member)->isDeleted())
+
+    if (MD && MD->isMoveAssignmentOperator() && !ClassExported &&
+        MD->isInlined()) {
+      // Current MSVC versions don't export the move assignment operators, so
+      // don't attempt to import them if we have a definition.
       continue;
+    }
 
     if (InheritableAttr *MemberAttr = getDLLAttr(Member)) {
       if (S.Context.getTargetInfo().getCXXABI().isMicrosoft() &&

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=210715&r1=210714&r2=210715&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Wed Jun 11 17:44:39 2014
@@ -27,6 +27,8 @@ struct ExplicitSpec_NotImported {};
 #define USE(func) void UNIQ(use)() { func(); }
 #define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
 #define USECLASS(class) void UNIQ(USE)() { class x; }
+#define USECOPYASSIGN(class) class& (class::*UNIQ(use)())(class&) { return &class::operator=; }
+#define USEMOVEASSIGN(class) class& (class::*UNIQ(use)())(class&&) { return &class::operator=; }
 
 //===----------------------------------------------------------------------===//
 // Globals
@@ -518,9 +520,18 @@ struct __declspec(dllimport) T {
 
   static int b;
   // MO1-DAG: @"\01?b at T@@2HA" = external dllimport global i32
+
+  T& operator=(T&) = default;
+  // MO1-DAG: define available_externally dllimport x86_thiscallcc nonnull %struct.T* @"\01??4T@@QAEAAU0 at AAU0@@Z"
+
+  T& operator=(T&&) = default;
+  // Note: Don't mark inline move operators dllimport because current MSVC versions don't export them.
+  // MO1-DAG: define linkonce_odr x86_thiscallcc nonnull %struct.T* @"\01??4T@@QAEAAU0@$$QAU0@@Z"
 };
 USEMEMFUNC(T, a)
 USEVAR(T::b)
+USECOPYASSIGN(T)
+USEMOVEASSIGN(T)
 
 template <typename T> struct __declspec(dllimport) U { void foo() {} };
 // MO1-DAG: define available_externally dllimport x86_thiscallcc void @"\01?foo@?$U at H@@QAEXXZ"





More information about the cfe-commits mailing list