From 96bc4b03676655383766ca2337245a8d82f58403 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 24 Mar 2014 05:53:08 +0000 Subject: 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 --- clang/lib/CodeGen/CodeGenModule.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 097e30c7..e5a0fa5 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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(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"; -- cgit v1.1