Skip to content

Commit 1b913cd

Browse files
committed
[clang][CodeGen] Strip unneeded calls to raw_string_ostream::str() (NFC)
Try to avoid excess layer of indirection when possible. p.s. Remove a call to raw_string_ostream::flush() which is a no-op.
1 parent d3cdf0f commit 1b913cd

File tree

6 files changed

+7
-10
lines changed

6 files changed

+7
-10
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
23842384
TA.getAsTemplate().getAsTemplateDecl()->printQualifiedName(
23852385
OS, getPrintingPolicy());
23862386
TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2387-
TheCU, Name, nullptr, OS.str(), defaultParameter));
2387+
TheCU, Name, nullptr, QualName, defaultParameter));
23882388
break;
23892389
}
23902390
case TemplateArgument::Pack:
@@ -5653,7 +5653,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
56535653
std::string CanonicalOriginalName;
56545654
llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
56555655
ND->getNameForDiagnostic(OriginalOS, PP, Qualified);
5656-
assert(EncodedOriginalNameOS.str() == OriginalOS.str());
5656+
assert(EncodedOriginalName == CanonicalOriginalName);
56575657
#endif
56585658
}
56595659
}

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8864,7 +8864,6 @@ emitMappingInformation(CodeGenFunction &CGF, llvm::OpenMPIRBuilder &OMPBuilder,
88648864
PrintingPolicy P(CGF.getContext().getLangOpts());
88658865
llvm::raw_string_ostream OS(ExprName);
88668866
MapExprs.getMapExpr()->printPretty(OS, nullptr, P);
8867-
OS.flush();
88688867
} else {
88698868
ExprName = MapExprs.getMapDecl()->getNameAsString();
88708869
}

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ void BackendConsumer::UnsupportedDiagHandler(
654654
auto DiagType = D.getSeverity() == llvm::DS_Error
655655
? diag::err_fe_backend_unsupported
656656
: diag::warn_fe_backend_unsupported;
657-
Diags.Report(Loc, DiagType) << MsgStream.str();
657+
Diags.Report(Loc, DiagType) << Msg;
658658

659659
if (BadDebugInfo)
660660
// If we were not able to translate the file:line:col information
@@ -691,9 +691,7 @@ void BackendConsumer::EmitOptimizationMessage(
691691
if (D.getHotness())
692692
MsgStream << " (hotness: " << *D.getHotness() << ")";
693693

694-
Diags.Report(Loc, DiagID)
695-
<< AddFlagValue(D.getPassName())
696-
<< MsgStream.str();
694+
Diags.Report(Loc, DiagID) << AddFlagValue(D.getPassName()) << Msg;
697695

698696
if (BadDebugInfo)
699697
// If we were not able to translate the file:line:col information

clang/lib/CodeGen/MacroPPCallbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void MacroPPCallbacks::MacroDefined(const Token &MacroNameTok,
185185
writeMacroDefinition(*Id, *MD->getMacroInfo(), PP, Name, Value);
186186
Gen->getCGDebugInfo()->CreateMacro(getCurrentScope(),
187187
llvm::dwarf::DW_MACINFO_define, location,
188-
Name.str(), Value.str());
188+
NameBuffer, ValueBuffer);
189189
}
190190

191191
void MacroPPCallbacks::MacroUndefined(const Token &MacroNameTok,

clang/lib/CodeGen/SanitizerMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV, const VarDecl &D,
9494
return NoSanitizeMask;
9595
};
9696

97-
reportGlobal(GV, D.getLocation(), OS.str(), D.getType(), getNoSanitizeMask(D),
97+
reportGlobal(GV, D.getLocation(), QualName, D.getType(), getNoSanitizeMask(D),
9898
IsDynInit);
9999
}
100100

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static void rewriteInputConstraintReferences(unsigned FirstIn,
284284
Pos = DigitEnd;
285285
}
286286
}
287-
AsmString = std::move(OS.str());
287+
AsmString = std::move(Buf);
288288
}
289289

290290
/// Add output constraints for EAX:EDX because they are return registers.

0 commit comments

Comments
 (0)