]> granicus.if.org Git - clang/commitdiff
MS ABI: Disambiguate the manglings for global guard variables
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 6 Mar 2014 19:57:36 +0000 (19:57 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 6 Mar 2014 19:57:36 +0000 (19:57 +0000)
If a guard variable will be created for an entity at global scope,
then we cannot rely on the scope depth to disambiguate names for us.

Instead, mangle the entire variable into the guard to ensure it's uniqueness.

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

lib/AST/MicrosoftMangle.cpp
test/CodeGenCXX/microsoft-abi-static-initializers.cpp

index 6ef9a39e847285a7cd0abb7a93b01fc5d7b4a6ee..4321777a8b7f3f35a2150029e9ea9ca8c7421dd4 100644 (file)
@@ -2280,13 +2280,17 @@ void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD,
   bool Visible = VD->isExternallyVisible();
   // <operator-name> ::= ?_B # local static guard
   Mangler.getStream() << (Visible ? "\01??_B" : "\01?$S1@");
-  Mangler.mangleNestedName(VD);
+  unsigned ScopeDepth = 0;
+  if (Visible && !getNextDiscriminator(VD, ScopeDepth))
+    // If we do not have a discriminator and are emitting a guard variable for
+    // use at global scope, then mangling the nested name will not be enough to
+    // remove ambiguities.
+    Mangler.mangle(VD, "");
+  else
+    Mangler.mangleNestedName(VD);
   Mangler.getStream() << (Visible ? "@5" : "@4IA");
-  if (Visible) {
-    unsigned ScopeDepth;
-    getNextDiscriminator(VD, ScopeDepth);
+  if (ScopeDepth)
     Mangler.mangleNumber(ScopeDepth);
-  }
 }
 
 void MicrosoftMangleContextImpl::mangleInitFiniStub(const VarDecl *D,
index 4f44bb8acc7f74c14c9df21117e4f8c4d2eb4cac..021356e8fa22ae87fd8f65bb01ae6caa3d5c2e48 100644 (file)
@@ -135,6 +135,8 @@ void force_usage() {
 }
 
 // CHECK: define internal void @"\01??__Efoo@?$B@H@@2VA@@A@YAXXZ"() [[NUW]]
+// CHECK: load i32* @"\01??_Bfoo@?$B@H@@2VA@@A@5"
+// CHECK: store i32 {{.*}}, i32* @"\01??_Bfoo@?$B@H@@2VA@@A@5"
 // CHECK: %{{[.0-9A-Z_a-z]+}} = call x86_thiscallcc %class.A* @"\01??0A@@QAE@XZ"
 // CHECK: call i32 @atexit(void ()* @"\01??__Ffoo@?$B@H@@2VA@@A@YAXXZ")
 // CHECK: ret void