diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 7c687135fc6..af8cd8eb141 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -85,12 +85,11 @@ MCSymbol *MCContext::CreateSymbol(StringRef Name) { StringMapEntry *NameEntry = &UsedNames.GetOrCreateValue(Name); if (NameEntry->getValue()) { assert(isTemporary && "Cannot rename non temporary symbols"); - SmallString<128> NewName; + SmallString<128> NewName = Name; do { - Twine T = Name + Twine(NextUniqueID++); - T.toVector(NewName); - StringRef foo = NewName; - NameEntry = &UsedNames.GetOrCreateValue(foo); + NewName.resize(Name.size()); + raw_svector_ostream(NewName) << NextUniqueID++; + NameEntry = &UsedNames.GetOrCreateValue(NewName); } while (NameEntry->getValue()); } NameEntry->setValue(true); @@ -110,9 +109,8 @@ MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) { MCSymbol *MCContext::CreateTempSymbol() { SmallString<128> NameSV; - Twine Name = Twine(MAI.getPrivateGlobalPrefix()) + "tmp" + - Twine(NextUniqueID++); - Name.toVector(NameSV); + raw_svector_ostream(NameSV) + << MAI.getPrivateGlobalPrefix() << "tmp" << NextUniqueID++; return CreateSymbol(NameSV); } diff --git a/test/MC/AsmParser/rename.s b/test/MC/AsmParser/rename.s index 64ca5153812..934cee808bd 100644 --- a/test/MC/AsmParser/rename.s +++ b/test/MC/AsmParser/rename.s @@ -1,10 +1,14 @@ // RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s .size bar, . - bar +.Ltmp01: + .size foo, .Ltmp01 - foo .Ltmp0: - .size foo, .Ltmp0 - foo + .size qux, .Ltmp0 - qux // CHECK: .Ltmp0: // CHECK: .size bar, .Ltmp0-bar // CHECK: .Ltmp01 // CHECK: .size foo, .Ltmp01-foo +// CHECK: .Ltmp02 +// CHECK: .size qux, .Ltmp02-qux