[PATCH] Don't inherit dllimport to inline move assignment operators
Hans Wennborg
hans at chromium.org
Wed Jun 11 15:25:37 PDT 2014
Hi rnk,
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
Files:
lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/dllimport.cpp
Index: lib/Sema/SemaDeclCXX.cpp
===================================================================
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -4377,11 +4377,24 @@
// 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;
- if (isa<CXXMethodDecl>(Member) && cast<CXXMethodDecl>(Member)->isDeleted())
+
+ // Don't process deleted methods.
+ if (MD && MD->isDeleted())
continue;
+ 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() &&
!MemberAttr->isInherited()) {
Index: test/CodeGenCXX/dllimport.cpp
===================================================================
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -27,6 +27,8 @@
#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 @@
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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4105.10336.patch
Type: text/x-patch
Size: 2531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140611/7caf39e0/attachment.bin>
More information about the cfe-commits
mailing list