MS ABI: Add tests, other cleanups for r204562

This commit cleans up a few accidents:
- Do not rely on the order in which StringLiteral lays out bytes.
- Use a more efficient mechanism for handling so-called
  "special-mappings" when mangling string literals.
- There is no need to allocate a copy of the mangled name.
- Add the test written for r204562.

Thanks to Richard Smith for pointing these out!

llvm-svn: 204586
This commit is contained in:
David Majnemer
2014-03-24 05:53:08 +00:00
parent 016d69d29f
commit 96bc4b0367
3 changed files with 783 additions and 63 deletions

View File

@@ -2595,21 +2595,17 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S) {
}
if (!GV) {
SmallString<256> MangledNameBuffer;
StringRef GlobalVariableName;
llvm::GlobalValue::LinkageTypes LT;
if (!LangOpts.WritableStrings &&
getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) {
LT = llvm::GlobalValue::LinkOnceODRLinkage;
SmallString<256> Buffer;
llvm::raw_svector_ostream Out(Buffer);
llvm::raw_svector_ostream Out(MangledNameBuffer);
getCXXABI().getMangleContext().mangleStringLiteral(S, Out);
Out.flush();
size_t Length = Buffer.size();
char *Name = MangledNamesAllocator.Allocate<char>(Length);
std::copy(Buffer.begin(), Buffer.end(), Name);
GlobalVariableName = StringRef(Name, Length);
LT = llvm::GlobalValue::LinkOnceODRLinkage;
GlobalVariableName = MangledNameBuffer;
} else {
LT = llvm::GlobalValue::PrivateLinkage;;
GlobalVariableName = ".str";