]> granicus.if.org Git - clang/commitdiff
MS ABI: Let guard variables be present in COMDATs
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 21 Jan 2015 01:04:30 +0000 (01:04 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 21 Jan 2015 01:04:30 +0000 (01:04 +0000)
A guard variable in a COMDAT'd function should also be in a COMDAT.

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

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

index 12029bc13b1df02a5018be845be0bf24cd180e6a..71d6e7800d7c37b6ebde0b915e93523dd78f8296 100644 (file)
@@ -1923,6 +1923,9 @@ void MicrosoftCXXABI::EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
                                  GV->getLinkage(), Zero, GuardName.str());
     GI->Guard->setVisibility(GV->getVisibility());
     GI->Guard->setDLLStorageClass(GV->getDLLStorageClass());
+    if (GI->Guard->isWeakForLinker())
+      GI->Guard->setComdat(
+          CGM.getModule().getOrInsertComdat(GI->Guard->getName()));
   } else {
     assert(GI->Guard->getLinkage() == GV->getLinkage() &&
            "static local from the same function had different linkage");
index 53c7de2ee21a01d8c59b8faa8f4158e44337c860..0845c6dd7fc08006b0a4718f8bdf09fce0bedb24 100644 (file)
@@ -82,8 +82,8 @@ int __declspec(dllexport) nonInlineStaticLocalsFunc() {
   return x++;
 };
 
-// MSC-DAG: @"\01?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = weak_odr dllexport global i32 0
-// MSC-DAG: @"\01??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = weak_odr dllexport global i32 0
+// MSC-DAG: @"\01?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = weak_odr dllexport global i32 0, comdat
+// MSC-DAG: @"\01??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = weak_odr dllexport global i32 0, comdat
 // Note: MinGW doesn't seem to export the static local here.
 inline int __declspec(dllexport) inlineStaticLocalsFunc() {
   static int x = f();