]> granicus.if.org Git - clang/commitdiff
CodeGen: Don't form weak dllexport aliases
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 24 Oct 2014 22:05:27 +0000 (22:05 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 24 Oct 2014 22:05:27 +0000 (22:05 +0000)
The MS linker cannot do anything interesting with these, it doesn't make
sense to emit them.

This fixes PR21373.

Differential Revision: http://reviews.llvm.org/D5986

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220595 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
test/CodeGenCXX/dllexport.cpp

index 93e17601cc61d9b6f2239e6192590ddbcf00c36a..a590afae0b3f8734261590af71752cbc7a91cf15 100644 (file)
@@ -119,6 +119,11 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl,
   if (!llvm::GlobalAlias::isValidLinkage(Linkage))
     return true;
 
+  // Don't create a weak alias for a dllexport'd symbol.
+  if (AliasDecl.getDecl()->hasAttr<DLLExportAttr>() &&
+      llvm::GlobalValue::isWeakForLinker(Linkage))
+    return true;
+
   llvm::GlobalValue::LinkageTypes TargetLinkage =
       getFunctionLinkage(TargetDecl);
 
index a2b35c0900ef4cb4557c16ce3f44e79f961acb07..0e6e989846cfdb3c804f32ecd3d2698e3bfc427b 100644 (file)
@@ -3,8 +3,6 @@
 // RUN: %clang_cc1 -triple i686-windows-gnu    -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G32 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu  -emit-llvm -std=c++1y -O0 -o - %s | FileCheck --check-prefix=GNU --check-prefix=G64 %s
 
-// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -mconstructor-aliases -disable-llvm-optzns -std=c++1y -emit-llvm -o - %s | FileCheck %s --check-prefix=MSC --check-prefix=M32
-
 // Helper structs to make templates more expressive.
 struct ImplicitInst_Exported {};
 struct ExplicitDecl_Exported {};
@@ -607,6 +605,15 @@ template struct __declspec(dllexport) ExplicitlyInstantiatedWithDifferentAttr<in
 USEMEMFUNC(ExplicitlyInstantiatedWithDifferentAttr<int>, f);
 // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?f@?$ExplicitlyInstantiatedWithDifferentAttr@H@@QAEXXZ"
 
+// Don't create weak dllexport aliases. (PR21373)
+struct NonExportedBaseClass {
+  virtual ~NonExportedBaseClass();
+};
+NonExportedBaseClass::~NonExportedBaseClass() {}
+
+struct __declspec(dllexport) ExportedDerivedClass : NonExportedBaseClass {};
+// M32-DAG: weak_odr dllexport x86_thiscallcc void @"\01??1ExportedDerivedClass@@UAE@XZ"
+
 
 //===----------------------------------------------------------------------===//
 // Classes with template base classes