diff --git a/lib/IR/Mangler.cpp b/lib/IR/Mangler.cpp index d3b53a9bddc..c067f0f3923 100644 --- a/lib/IR/Mangler.cpp +++ b/lib/IR/Mangler.cpp @@ -81,7 +81,9 @@ void Mangler::getNameWithPrefix(SmallVectorImpl &OutName, PrefixTy = Mangler::Private; else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage()) PrefixTy = Mangler::LinkerPrivate; - + + size_t NameBegin = OutName.size(); + // If this global has a name, handle it simply. if (GV->hasName()) { StringRef Name = GV->getName(); @@ -106,13 +108,10 @@ void Mangler::getNameWithPrefix(SmallVectorImpl &OutName, if (const Function *F = dyn_cast(GV)) { CallingConv::ID CC = F->getCallingConv(); - // fastcall functions need to start with @. - // FIXME: This logic seems unlikely to be right. + // fastcall functions need to start with @ instead of _. if (CC == CallingConv::X86_FastCall) { - if (OutName[0] == '_') - OutName[0] = '@'; - else - OutName.insert(OutName.begin(), '@'); + assert(OutName[NameBegin] == '_' && DL->getGlobalPrefix() == '_'); + OutName[NameBegin] = '@'; } // fastcall and stdcall functions usually need @42 at the end to specify