Skip to content

Commit 2051736

Browse files
committed
[llvm][Transforms] 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 d40768f commit 2051736

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8866,7 +8866,7 @@ struct AADenormalFPMathImpl : public AADenormalFPMath {
88668866
if (Known.ModeF32.isValid())
88678867
OS << " denormal-fp-math-f32=" << Known.ModeF32;
88688868
OS << ']';
8869-
return OS.str();
8869+
return Str;
88708870
}
88718871
};
88728872

@@ -8979,7 +8979,7 @@ struct AAValueConstantRangeImpl : AAValueConstantRange {
89798979
OS << " / ";
89808980
getAssumed().print(OS);
89818981
OS << ">";
8982-
return OS.str();
8982+
return Str;
89838983
}
89848984

89858985
/// Helper function to get a SCEV expr for the associated value at program
@@ -9656,7 +9656,7 @@ struct AAPotentialConstantValuesImpl : AAPotentialConstantValues {
96569656
std::string Str;
96579657
llvm::raw_string_ostream OS(Str);
96589658
OS << getState();
9659-
return OS.str();
9659+
return Str;
96609660
}
96619661

96629662
/// See AbstractAttribute::updateImpl(...).
@@ -10778,7 +10778,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
1077810778
std::string Str;
1077910779
llvm::raw_string_ostream OS(Str);
1078010780
OS << getState();
10781-
return OS.str();
10781+
return Str;
1078210782
}
1078310783

1078410784
template <typename AAType>

llvm/lib/Transforms/IPO/IROutliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ Function *IROutliner::createFunction(Module &M, OutlinableGroup &Group,
678678
Mg.getNameWithPrefix(MangledNameStream, F, false);
679679

680680
DISubprogram *OutlinedSP = DB.createFunction(
681-
Unit /* Context */, F->getName(), MangledNameStream.str(),
681+
Unit /* Context */, F->getName(), Dummy,
682682
Unit /* File */,
683683
0 /* Line 0 is reserved for compiler-generated code. */,
684684
DB.createSubroutineType(

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,21 +1667,21 @@ struct OpenMPOpt {
16671667
BP->print(Printer);
16681668
Printer << Separator;
16691669
}
1670-
LLVM_DEBUG(dbgs() << "\t\toffload_baseptrs: " << Printer.str() << "\n");
1670+
LLVM_DEBUG(dbgs() << "\t\toffload_baseptrs: " << ValuesStr << "\n");
16711671
ValuesStr.clear();
16721672

16731673
for (auto *P : OAs[1].StoredValues) {
16741674
P->print(Printer);
16751675
Printer << Separator;
16761676
}
1677-
LLVM_DEBUG(dbgs() << "\t\toffload_ptrs: " << Printer.str() << "\n");
1677+
LLVM_DEBUG(dbgs() << "\t\toffload_ptrs: " << ValuesStr << "\n");
16781678
ValuesStr.clear();
16791679

16801680
for (auto *S : OAs[2].StoredValues) {
16811681
S->print(Printer);
16821682
Printer << Separator;
16831683
}
1684-
LLVM_DEBUG(dbgs() << "\t\toffload_sizes: " << Printer.str() << "\n");
1684+
LLVM_DEBUG(dbgs() << "\t\toffload_sizes: " << ValuesStr << "\n");
16851685
}
16861686

16871687
/// Returns the instruction where the "wait" counterpart \p RuntimeCall can be

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ std::string DevirtModule::getGlobalName(VTableSlot Slot,
16161616
for (uint64_t Arg : Args)
16171617
OS << '_' << Arg;
16181618
OS << '_' << Name;
1619-
return OS.str();
1619+
return FullName;
16201620
}
16211621

16221622
bool DevirtModule::shouldExportConstantsAsAbsoluteSymbols() {

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5080,7 +5080,7 @@ bool InstCombinerImpl::run() {
50805080
#ifndef NDEBUG
50815081
std::string OrigI;
50825082
#endif
5083-
LLVM_DEBUG(raw_string_ostream SS(OrigI); I->print(SS); OrigI = SS.str(););
5083+
LLVM_DEBUG(raw_string_ostream SS(OrigI); I->print(SS););
50845084
LLVM_DEBUG(dbgs() << "IC: Visiting: " << OrigI << '\n');
50855085

50865086
if (Instruction *Result = visit(*I)) {

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ static std::string getSimpleNodeName(const BasicBlock *Node) {
22642264
std::string SimpleNodeName;
22652265
raw_string_ostream OS(SimpleNodeName);
22662266
Node->printAsOperand(OS, false);
2267-
return OS.str();
2267+
return SimpleNodeName;
22682268
}
22692269

22702270
void llvm::setProfMetadata(Module *M, Instruction *TI,

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16211,7 +16211,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R,
1621116211
Ty->print(rso);
1621216212
return OptimizationRemarkMissed(SV_NAME, "UnsupportedType", I0)
1621316213
<< "Cannot SLP vectorize list: type "
16214-
<< rso.str() + " is unsupported by vectorizer";
16214+
<< TypeStr + " is unsupported by vectorizer";
1621516215
});
1621616216
return false;
1621716217
}

0 commit comments

Comments
 (0)