Skip to content

Commit 84d7f29

Browse files
committed
[flang] Tidy uses of raw_string_ostream (NFC)
As specified in the docs, 1) raw_string_ostream is always unbuffered and 2) the underlying buffer may be used directly ( 65b1361 for further reference ) Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
1 parent 36192fd commit 84d7f29

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ void PrintPreprocessedAction::executeAction() {
425425
// If a pre-defined output stream exists, dump the preprocessed content there
426426
if (!ci.isOutputStreamNull()) {
427427
// Send the output to the pre-defined output buffer.
428-
ci.writeOutputStream(outForPP.str());
428+
ci.writeOutputStream(buf);
429429
return;
430430
}
431431

@@ -436,7 +436,7 @@ void PrintPreprocessedAction::executeAction() {
436436
return;
437437
}
438438

439-
(*os) << outForPP.str();
439+
(*os) << buf;
440440
}
441441

442442
void DebugDumpProvenanceAction::executeAction() {
@@ -756,7 +756,7 @@ getRISCVVScaleRange(CompilerInstance &ci) {
756756
outputErrMsg << errMsg.getMessage();
757757
});
758758
ci.getDiagnostics().Report(clang::diag::err_invalid_feature_combination)
759-
<< outputErrMsg.str();
759+
<< buffer;
760760
return std::nullopt;
761761
}
762762

@@ -1091,8 +1091,7 @@ class BackendRemarkConsumer : public llvm::DiagnosticHandler {
10911091
msgStream << diagInfo.getMsg();
10921092

10931093
// Emit message.
1094-
diags.Report(diagID) << clang::AddFlagValue(diagInfo.getPassName())
1095-
<< msgStream.str();
1094+
diags.Report(diagID) << clang::AddFlagValue(diagInfo.getPassName()) << msg;
10961095
}
10971096

10981097
void optimizationRemarkHandler(

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,8 @@ int getTypeCode(mlir::Type ty, const fir::KindMapping &kindMap) {
533533

534534
std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
535535
llvm::StringRef prefix) {
536-
std::string buf;
536+
std::string buf = prefix.str();
537537
llvm::raw_string_ostream name{buf};
538-
name << prefix.str();
539538
if (!prefix.empty())
540539
name << "_";
541540
while (ty) {
@@ -606,7 +605,7 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
606605
llvm::report_fatal_error("unsupported type");
607606
}
608607
}
609-
return name.str();
608+
return buf;
610609
}
611610

612611
mlir::Type changeElementType(mlir::Type type, mlir::Type newElementType,

flang/lib/Parser/parsing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
4242
sourceFile =
4343
allSources.Open(path, fileError, "."s /*prepend to search path*/);
4444
}
45-
if (!fileError.str().empty()) {
45+
if (!buf.empty()) {
4646
ProvenanceRange range{allSources.AddCompilerInsertion(path)};
47-
messages_.Say(range, "%s"_err_en_US, fileError.str());
47+
messages_.Say(range, "%s"_err_en_US, buf);
4848
return sourceFile;
4949
}
5050
CHECK(sourceFile);

0 commit comments

Comments
 (0)