From: David Majnemer Date: Thu, 6 Mar 2014 19:57:36 +0000 (+0000) Subject: MS ABI: Disambiguate the manglings for global guard variables X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27d09acf9e883691288d8a21c10f4a5d6e293242;p=clang MS ABI: Disambiguate the manglings for global guard variables 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 --- diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 6ef9a39e84..4321777a8b 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -2280,13 +2280,17 @@ void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD, bool Visible = VD->isExternallyVisible(); // ::= ?_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, diff --git a/test/CodeGenCXX/microsoft-abi-static-initializers.cpp b/test/CodeGenCXX/microsoft-abi-static-initializers.cpp index 4f44bb8acc..021356e8fa 100644 --- a/test/CodeGenCXX/microsoft-abi-static-initializers.cpp +++ b/test/CodeGenCXX/microsoft-abi-static-initializers.cpp @@ -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