[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()`.
This commit is contained in:
Youngsuk Kim 2024-07-03 05:34:28 -05:00
parent d37e7ec2c5
commit 82f9a5ba96
6 changed files with 8 additions and 8 deletions

View File

@ -6238,7 +6238,7 @@ bool AsmParser::parseMSInlineAsm(
if (AsmStart != AsmEnd)
OS << StringRef(AsmStart, AsmEnd - AsmStart);
AsmString = OS.str();
AsmString = AsmStringIR;
return false;
}

View File

@ -2843,7 +2843,7 @@ bool MasmParser::expandMacro(raw_svector_ostream &OS, StringRef Body,
raw_string_ostream LocalName(Name);
LocalName << "??"
<< format_hex_no_prefix(LocalCounter++, 4, /*Upper=*/true);
LocalSymbols.insert({Local, LocalName.str()});
LocalSymbols.insert({Local, Name});
Name.clear();
}

View File

@ -239,7 +239,7 @@ Error Path::Root::getError() const {
OS << '[' << S.index() << ']';
}
}
return createStringError(llvm::inconvertibleErrorCode(), OS.str());
return createStringError(llvm::inconvertibleErrorCode(), S);
}
std::vector<const Object::value_type *> sortedElements(const Object &O) {

View File

@ -228,7 +228,7 @@ LockFileManager::LockFileManager(StringRef FileName)
std::string S("failed to create link ");
raw_string_ostream OSS(S);
OSS << LockFileName.str() << " to " << UniqueLockFileName.str();
setError(EC, OSS.str());
setError(EC, S);
return;
}
@ -274,7 +274,7 @@ std::string LockFileManager::getErrorMessage() const {
raw_string_ostream OSS(Str);
if (!ErrCodeMsg.empty())
OSS << ": " << ErrCodeMsg;
return OSS.str();
return Str;
}
return "";
}

View File

@ -159,7 +159,7 @@ int llvm::TableGenMain(const char *argv0,
// aren't any.
if (auto ExistingOrErr =
MemoryBuffer::getFile(OutputFilename, /*IsText=*/true))
if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
if (std::move(ExistingOrErr.get())->getBuffer() == OutString)
WriteFile = false;
}
if (WriteFile) {
@ -168,7 +168,7 @@ int llvm::TableGenMain(const char *argv0,
if (EC)
return reportError(argv0, "error opening " + OutputFilename + ": " +
EC.message() + "\n");
OutFile.os() << Out.str();
OutFile.os() << OutString;
if (ErrorsPrinted == 0)
OutFile.keep();
}

View File

@ -221,7 +221,7 @@ struct SequenceOp : public SetTheory::Operator {
std::string Name;
raw_string_ostream OS(Name);
OS << format(Format.c_str(), unsigned(From));
Record *Rec = Records.getDef(OS.str());
Record *Rec = Records.getDef(Name);
if (!Rec)
PrintFatalError(Loc, "No def named '" + Name + "': " +
Expr->getAsString());