From 77abc3a7da62e72d93892280041294101e099ca3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 16 Jan 2015 16:04:45 +0000 Subject: [PATCH] Add comdats to dynamic init functions in the microsoft abi. llvm-svn: 226286 --- clang/lib/CodeGen/MicrosoftCXXABI.cpp | 4 +++- clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index a7671d8..7fe5ec5 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1861,7 +1861,9 @@ void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, if (!D.isStaticLocal()) { assert(GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()); // GlobalOpt is allowed to discard the initializer, so use linkonce_odr. - CGF.CurFn->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage); + llvm::Function *F = CGF.CurFn; + F->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage); + F->setComdat(CGM.getModule().getOrInsertComdat(F->getName())); CGF.EmitCXXGlobalVarDeclInit(D, GV, PerformInit); return; } diff --git a/clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp b/clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp index 749e655..0873592 100644 --- a/clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp +++ b/clang/test/CodeGenCXX/microsoft-abi-static-initializers.cpp @@ -28,11 +28,11 @@ S s; // See @llvm.global_ctors above. __declspec(selectany) S selectany1; __declspec(selectany) S selectany2; -// CHECK: define linkonce_odr void @"\01??__Eselectany1@@YAXXZ"() +// CHECK: define linkonce_odr void @"\01??__Eselectany1@@YAXXZ"() {{.*}} comdat // CHECK-NOT: @"\01??_Bselectany1 // CHECK: call x86_thiscallcc %struct.S* @"\01??0S@@QAE@XZ" // CHECK: ret void -// CHECK: define linkonce_odr void @"\01??__Eselectany2@@YAXXZ"() +// CHECK: define linkonce_odr void @"\01??__Eselectany2@@YAXXZ"() {{.*}} comdat // CHECK-NOT: @"\01??_Bselectany2 // CHECK: call x86_thiscallcc %struct.S* @"\01??0S@@QAE@XZ" // CHECK: ret void @@ -231,7 +231,7 @@ void force_usage() { DynamicDLLImportInitVSMangling::switch_test3(); } -// CHECK: define linkonce_odr void @"\01??__Efoo@?$B@H@@2VA@@A@YAXXZ"() +// CHECK: define linkonce_odr void @"\01??__Efoo@?$B@H@@2VA@@A@YAXXZ"() {{.*}} comdat // CHECK-NOT: and // CHECK-NOT: ?_Bfoo@ // CHECK: call x86_thiscallcc %class.A* @"\01??0A@@QAE@XZ" -- 2.7.4