Skip to content

Commit 82f9a5b

Browse files
committed
[llvm] Avoid 'raw_string_ostream::str' (NFC)
Since `raw_string_ostream` doesn't own the string buffer, it is desirable (in terms of memory safety) for users to directly reference the string buffer rather than use `raw_string_ostream::str()`. Work towards TODO comment to remove `raw_string_ostream::str()`.
1 parent d37e7ec commit 82f9a5b

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6238,7 +6238,7 @@ bool AsmParser::parseMSInlineAsm(
62386238
if (AsmStart != AsmEnd)
62396239
OS << StringRef(AsmStart, AsmEnd - AsmStart);
62406240

6241-
AsmString = OS.str();
6241+
AsmString = AsmStringIR;
62426242
return false;
62436243
}
62446244

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@ bool MasmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
28432843
raw_string_ostream LocalName(Name);
28442844
LocalName << "??"
28452845
<< format_hex_no_prefix(LocalCounter++, 4, /*Upper=*/true);
2846-
LocalSymbols.insert({Local, LocalName.str()});
2846+
LocalSymbols.insert({Local, Name});
28472847
Name.clear();
28482848
}
28492849

llvm/lib/Support/JSON.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ Error Path::Root::getError() const {
239239
OS << '[' << S.index() << ']';
240240
}
241241
}
242-
return createStringError(llvm::inconvertibleErrorCode(), OS.str());
242+
return createStringError(llvm::inconvertibleErrorCode(), S);
243243
}
244244

245245
std::vector<const Object::value_type *> sortedElements(const Object &O) {

llvm/lib/Support/LockFileManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ LockFileManager::LockFileManager(StringRef FileName)
228228
std::string S("failed to create link ");
229229
raw_string_ostream OSS(S);
230230
OSS << LockFileName.str() << " to " << UniqueLockFileName.str();
231-
setError(EC, OSS.str());
231+
setError(EC, S);
232232
return;
233233
}
234234

@@ -274,7 +274,7 @@ std::string LockFileManager::getErrorMessage() const {
274274
raw_string_ostream OSS(Str);
275275
if (!ErrCodeMsg.empty())
276276
OSS << ": " << ErrCodeMsg;
277-
return OSS.str();
277+
return Str;
278278
}
279279
return "";
280280
}

llvm/lib/TableGen/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int llvm::TableGenMain(const char *argv0,
159159
// aren't any.
160160
if (auto ExistingOrErr =
161161
MemoryBuffer::getFile(OutputFilename, /*IsText=*/true))
162-
if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
162+
if (std::move(ExistingOrErr.get())->getBuffer() == OutString)
163163
WriteFile = false;
164164
}
165165
if (WriteFile) {
@@ -168,7 +168,7 @@ int llvm::TableGenMain(const char *argv0,
168168
if (EC)
169169
return reportError(argv0, "error opening " + OutputFilename + ": " +
170170
EC.message() + "\n");
171-
OutFile.os() << Out.str();
171+
OutFile.os() << OutString;
172172
if (ErrorsPrinted == 0)
173173
OutFile.keep();
174174
}

llvm/lib/TableGen/SetTheory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct SequenceOp : public SetTheory::Operator {
221221
std::string Name;
222222
raw_string_ostream OS(Name);
223223
OS << format(Format.c_str(), unsigned(From));
224-
Record *Rec = Records.getDef(OS.str());
224+
Record *Rec = Records.getDef(Name);
225225
if (!Rec)
226226
PrintFatalError(Loc, "No def named '" + Name + "': " +
227227
Expr->getAsString());

0 commit comments

Comments
 (0)