diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2546,6 +2546,9 @@ llvm::Function::Create(FnTy, getThreadLocalWrapperLinkage(VD, CGM), WrapperName.str(), &CGM.getModule()); + if (CGM.supportsCOMDAT() && Wrapper->isWeakForLinker()) + Wrapper->setComdat(CGM.getModule().getOrInsertComdat(Wrapper->getName())); + CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Wrapper); // Always resolve references to the wrapper at link time. diff --git a/clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp b/clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp --- a/clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp +++ b/clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp @@ -21,7 +21,7 @@ // DARWIN: call cxx_fast_tlscc i32* @_ZTW1r() // CHECK: ret i32* %{{.*}} -// LINUX: define weak_odr hidden i32* @_ZTW1r() [[ATTR0:#[0-9]+]] { +// LINUX: define weak_odr hidden i32* @_ZTW1r() [[ATTR0:#[0-9]+]] comdat { // DARWIN: define cxx_fast_tlscc i32* @_ZTW1r() [[ATTR1:#[0-9]+]] { // LINUX: call void @_ZTH1r() // DARWIN: call cxx_fast_tlscc void @_ZTH1r() diff --git a/clang/test/CodeGenCXX/cxx11-thread-local.cpp b/clang/test/CodeGenCXX/cxx11-thread-local.cpp --- a/clang/test/CodeGenCXX/cxx11-thread-local.cpp +++ b/clang/test/CodeGenCXX/cxx11-thread-local.cpp @@ -204,22 +204,19 @@ // DARWIN: declare i32 @_tlv_atexit(void (i8*)*, i8*, i8*) // DARWIN: declare cxx_fast_tlscc i32* @_ZTWN1VIcE1mE() -// LINUX: define linkonce_odr hidden i32* @_ZTWN1VIcE1mE() -// LINUX-NOT: comdat +// LINUX: define linkonce_odr hidden i32* @_ZTWN1VIcE1mE() {{#[0-9]+}} comdat { // LINUX: br i1 icmp ne (void ()* @_ZTHN1VIcE1mE, // LINUX: call void @_ZTHN1VIcE1mE() // LINUX: ret i32* @_ZN1VIcE1mE // DARWIN: declare cxx_fast_tlscc i32* @_ZTWN1WIcE1mE() -// LINUX: define linkonce_odr hidden i32* @_ZTWN1WIcE1mE() -// LINUX-NOT: comdat +// LINUX: define linkonce_odr hidden i32* @_ZTWN1WIcE1mE() {{#[0-9]+}} comdat { // LINUX: br i1 icmp ne (void ()* @_ZTHN1WIcE1mE, // LINUX: call void @_ZTHN1WIcE1mE() // LINUX: ret i32* @_ZN1WIcE1mE // DARWIN: declare cxx_fast_tlscc {{.*}}* @_ZTWN1XIcE1mE() -// LINUX: define linkonce_odr hidden {{.*}}* @_ZTWN1XIcE1mE() -// LINUX-NOT: comdat +// LINUX: define linkonce_odr hidden {{.*}}* @_ZTWN1XIcE1mE() {{#[0-9]+}} comdat { // LINUX: br i1 icmp ne (void ()* @_ZTHN1XIcE1mE, // LINUX: call void @_ZTHN1XIcE1mE() // LINUX: ret {{.*}}* @_ZN1XIcE1mE diff --git a/clang/test/CodeGenCXX/tls-init-funcs.cpp b/clang/test/CodeGenCXX/tls-init-funcs.cpp --- a/clang/test/CodeGenCXX/tls-init-funcs.cpp +++ b/clang/test/CodeGenCXX/tls-init-funcs.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.8 -std=c++1y -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-windows-gnu -std=c++1y -S -emit-llvm %s -o - | FileCheck %s --check-prefix=MINGW // CHECK: @a = internal thread_local global // CHECK: @_Z2vtIiE = linkonce_odr thread_local global i32 5 @@ -10,6 +11,9 @@ // CHECK-DAG: define weak_odr hidden cxx_fast_tlscc i32* @_ZTW2vtIvE() // CHECK-DAG: define {{.*}} @_ZTW1a +// MINGW-DAG: define weak_odr hidden i32* @_ZTW2vtIiE() {{.*}} comdat +// MINGW-DAG: define weak_odr hidden i32* @_ZTW2vtIvE() {{.*}} comdat + struct A { ~A(); }; diff --git a/clang/test/OpenMP/threadprivate_codegen.cpp b/clang/test/OpenMP/threadprivate_codegen.cpp --- a/clang/test/OpenMP/threadprivate_codegen.cpp +++ b/clang/test/OpenMP/threadprivate_codegen.cpp @@ -648,15 +648,15 @@ // CHECK-TLS: call void [[ARR_X_TLS_INIT]] // CHECK-TLS: ret [2 x [3 x [[S1]]]]* [[ARR_X]] // CHECK-TLS: } -// CHECK-TLS: define {{.*}} i32* [[ST_INT_ST_TLS_INITD]] {{#[0-9]+}} { +// CHECK-TLS: define {{.*}} i32* [[ST_INT_ST_TLS_INITD]] {{#[0-9]+}} comdat { // CHECK-TLS-NOT: call // CHECK-TLS: ret i32* [[ST_INT_ST]] // CHECK-TLS: } -// CHECK-TLS: define {{.*}} float* [[ST_FLOAT_ST_TLS_INITD]] {{#[0-9]+}} { +// CHECK-TLS: define {{.*}} float* [[ST_FLOAT_ST_TLS_INITD]] {{#[0-9]+}} comdat { // CHECK-TLS-NOT: call // CHECK-TLS: ret float* [[ST_FLOAT_ST]] // CHECK-TLS: } -// CHECK-TLS: define {{.*}} [[S4]]* [[ST_S4_ST_TLS_INITD]] {{#[0-9]+}} { +// CHECK-TLS: define {{.*}} [[S4]]* [[ST_S4_ST_TLS_INITD]] {{#[0-9]+}} comdat { // CHECK-TLS: call void [[ST_S4_ST_TLS_INIT]] // CHECK-TLS: ret [[S4]]* [[ST_S4_ST]] // CHECK-TLS: }