Skip to content

Commit 387bee9

Browse files
committed
[llvm][unittests] Strip unneeded uses of raw_string_ostream::str() (NFC)
Avoid excess layer of indirection.
1 parent 6be9be5 commit 387bee9

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

llvm/unittests/Bitcode/BitReaderTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
3838

3939
// A failure here means that the test itself is buggy.
4040
if (!M)
41-
report_fatal_error(OS.str().c_str());
41+
report_fatal_error(ErrMsg.c_str());
4242

4343
return M;
4444
}

llvm/unittests/CodeGen/GlobalISel/GISelMITest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ operator<<(std::ostream &OS, const LLT Ty) {
1414
std::string Repr;
1515
raw_string_ostream SS{Repr};
1616
Ty.print(SS);
17-
OS << SS.str();
17+
OS << Repr;
1818
return OS;
1919
}
2020

@@ -23,7 +23,7 @@ operator<<(std::ostream &OS, const MachineFunction &MF) {
2323
std::string Repr;
2424
raw_string_ostream SS{Repr};
2525
MF.print(SS);
26-
OS << SS.str();
26+
OS << Repr;
2727
return OS;
2828
}
2929

llvm/unittests/CodeGen/GlobalISel/LegalizerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ::testing::AssertionResult isNullMIPtr(const MachineInstr *MI) {
2727
MI->print(MISStream, /*IsStandalone=*/true, /*SkipOpers=*/false,
2828
/*SkipDebugLoc=*/false, /*AddNewLine=*/false);
2929
return ::testing::AssertionFailure()
30-
<< "unable to legalize instruction: " << MISStream.str();
30+
<< "unable to legalize instruction: " << MIBuffer;
3131
}
3232

3333
DefineLegalizerInfo(ALegalizer, {

llvm/unittests/CodeGen/MachineInstrTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ TEST(MachineInstrPrintingTest, DebugLocPrinting) {
223223
raw_string_ostream OS(str);
224224
MI->print(OS, /*IsStandalone*/true, /*SkipOpers*/false, /*SkipDebugLoc*/false,
225225
/*AddNewLine*/false);
226-
ASSERT_TRUE(
227-
StringRef(OS.str()).starts_with("$noreg = UNKNOWN debug-location "));
228-
ASSERT_TRUE(StringRef(OS.str()).ends_with("filename:1:5"));
226+
ASSERT_TRUE(StringRef(str).starts_with("$noreg = UNKNOWN debug-location "));
227+
ASSERT_TRUE(StringRef(str).ends_with("filename:1:5"));
229228
}
230229

231230
TEST(MachineInstrSpan, DistanceBegin) {

llvm/unittests/CodeGen/MachineOperandTest.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ TEST(MachineOperandTest, PrintRegisterMask) {
7373
std::string str;
7474
raw_string_ostream OS(str);
7575
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
76-
ASSERT_TRUE(OS.str() == "<regmask ...>");
76+
ASSERT_TRUE(str == "<regmask ...>");
7777
}
7878

7979
TEST(MachineOperandTest, PrintSubReg) {
@@ -94,7 +94,7 @@ TEST(MachineOperandTest, PrintSubReg) {
9494
std::string str;
9595
raw_string_ostream OS(str);
9696
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
97-
ASSERT_TRUE(OS.str() == "$physreg1.subreg5");
97+
ASSERT_TRUE(str == "$physreg1.subreg5");
9898
}
9999

100100
TEST(MachineOperandTest, PrintCImm) {
@@ -116,7 +116,7 @@ TEST(MachineOperandTest, PrintCImm) {
116116
std::string str;
117117
raw_string_ostream OS(str);
118118
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
119-
ASSERT_TRUE(OS.str() == "i128 18446744073709551616");
119+
ASSERT_TRUE(str == "i128 18446744073709551616");
120120
}
121121

122122
TEST(MachineOperandTest, PrintSubRegIndex) {
@@ -133,7 +133,7 @@ TEST(MachineOperandTest, PrintSubRegIndex) {
133133
std::string str;
134134
raw_string_ostream OS(str);
135135
MachineOperand::printSubRegIdx(OS, MO.getImm(), nullptr);
136-
ASSERT_TRUE(OS.str() == "%subreg.3");
136+
ASSERT_TRUE(str == "%subreg.3");
137137
}
138138

139139
TEST(MachineOperandTest, PrintCPI) {
@@ -152,7 +152,7 @@ TEST(MachineOperandTest, PrintCPI) {
152152
{
153153
raw_string_ostream OS(str);
154154
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
155-
ASSERT_TRUE(OS.str() == "%const.0 + 8");
155+
ASSERT_TRUE(str == "%const.0 + 8");
156156
}
157157

158158
str.clear();
@@ -164,7 +164,7 @@ TEST(MachineOperandTest, PrintCPI) {
164164
{
165165
raw_string_ostream OS(str);
166166
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
167-
ASSERT_TRUE(OS.str() == "%const.0 - 12");
167+
ASSERT_TRUE(str == "%const.0 - 12");
168168
}
169169
}
170170

@@ -183,7 +183,7 @@ TEST(MachineOperandTest, PrintTargetIndexName) {
183183
{
184184
raw_string_ostream OS(str);
185185
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
186-
ASSERT_TRUE(OS.str() == "target-index(<unknown>) + 8");
186+
ASSERT_TRUE(str == "target-index(<unknown>) + 8");
187187
}
188188

189189
str.clear();
@@ -194,7 +194,7 @@ TEST(MachineOperandTest, PrintTargetIndexName) {
194194
{
195195
raw_string_ostream OS(str);
196196
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
197-
ASSERT_TRUE(OS.str() == "target-index(<unknown>) - 12");
197+
ASSERT_TRUE(str == "target-index(<unknown>) - 12");
198198
}
199199
}
200200

@@ -211,7 +211,7 @@ TEST(MachineOperandTest, PrintJumpTableIndex) {
211211
std::string str;
212212
raw_string_ostream OS(str);
213213
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
214-
ASSERT_TRUE(OS.str() == "%jump-table.3");
214+
ASSERT_TRUE(str == "%jump-table.3");
215215
}
216216

217217
TEST(MachineOperandTest, PrintExternalSymbol) {
@@ -228,7 +228,7 @@ TEST(MachineOperandTest, PrintExternalSymbol) {
228228
{
229229
raw_string_ostream OS(str);
230230
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
231-
ASSERT_TRUE(OS.str() == "&foo");
231+
ASSERT_TRUE(str == "&foo");
232232
}
233233

234234
str.clear();
@@ -238,7 +238,7 @@ TEST(MachineOperandTest, PrintExternalSymbol) {
238238
{
239239
raw_string_ostream OS(str);
240240
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
241-
ASSERT_TRUE(OS.str() == "&foo + 12");
241+
ASSERT_TRUE(str == "&foo + 12");
242242
}
243243

244244
str.clear();
@@ -248,7 +248,7 @@ TEST(MachineOperandTest, PrintExternalSymbol) {
248248
{
249249
raw_string_ostream OS(str);
250250
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
251-
ASSERT_TRUE(OS.str() == "&foo - 12");
251+
ASSERT_TRUE(str == "&foo - 12");
252252
}
253253
}
254254

@@ -274,7 +274,7 @@ TEST(MachineOperandTest, PrintGlobalAddress) {
274274
{
275275
raw_string_ostream OS(str);
276276
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
277-
ASSERT_TRUE(OS.str() == "@foo + 12");
277+
ASSERT_TRUE(str == "@foo + 12");
278278
}
279279

280280
str.clear();
@@ -284,7 +284,7 @@ TEST(MachineOperandTest, PrintGlobalAddress) {
284284
{
285285
raw_string_ostream OS(str);
286286
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
287-
ASSERT_TRUE(OS.str() == "@foo - 12");
287+
ASSERT_TRUE(str == "@foo - 12");
288288
}
289289
}
290290

@@ -302,7 +302,7 @@ TEST(MachineOperandTest, PrintRegisterLiveOut) {
302302
// Print a MachineOperand containing a register live out list without a TRI.
303303
raw_string_ostream OS(str);
304304
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
305-
ASSERT_TRUE(OS.str() == "liveout(<unknown>)");
305+
ASSERT_TRUE(str == "liveout(<unknown>)");
306306
}
307307

308308
TEST(MachineOperandTest, PrintMetadata) {
@@ -328,7 +328,7 @@ TEST(MachineOperandTest, PrintMetadata) {
328328
MO.print(OS, MST, LLT{}, /*OpIdx*/~0U, /*PrintDef=*/false, /*IsStandalone=*/false,
329329
/*ShouldPrintRegisterTies=*/false, 0, /*TRI=*/nullptr,
330330
/*IntrinsicInfo=*/nullptr);
331-
ASSERT_TRUE(OS.str() == "!0");
331+
ASSERT_TRUE(str == "!0");
332332
}
333333

334334
TEST(MachineOperandTest, PrintMCSymbol) {
@@ -349,7 +349,7 @@ TEST(MachineOperandTest, PrintMCSymbol) {
349349
// Print a MachineOperand containing a metadata node.
350350
raw_string_ostream OS(str);
351351
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
352-
ASSERT_TRUE(OS.str() == "<mcsymbol foo>");
352+
ASSERT_TRUE(str == "<mcsymbol foo>");
353353
}
354354

355355
TEST(MachineOperandTest, PrintCFI) {
@@ -366,7 +366,7 @@ TEST(MachineOperandTest, PrintCFI) {
366366
// attached to it.
367367
raw_string_ostream OS(str);
368368
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
369-
ASSERT_TRUE(OS.str() == "<cfi directive>");
369+
ASSERT_TRUE(str == "<cfi directive>");
370370
}
371371

372372
TEST(MachineOperandTest, PrintIntrinsicID) {
@@ -383,7 +383,7 @@ TEST(MachineOperandTest, PrintIntrinsicID) {
383383
// Print a MachineOperand containing a generic intrinsic ID.
384384
raw_string_ostream OS(str);
385385
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
386-
ASSERT_TRUE(OS.str() == "intrinsic(@llvm.bswap)");
386+
ASSERT_TRUE(str == "intrinsic(@llvm.bswap)");
387387
}
388388

389389
str.clear();
@@ -394,7 +394,7 @@ TEST(MachineOperandTest, PrintIntrinsicID) {
394394
// IntrinsicInfo.
395395
raw_string_ostream OS(str);
396396
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
397-
ASSERT_TRUE(OS.str() == "intrinsic(4294967295)");
397+
ASSERT_TRUE(str == "intrinsic(4294967295)");
398398
}
399399
}
400400

@@ -411,7 +411,7 @@ TEST(MachineOperandTest, PrintPredicate) {
411411
// Print a MachineOperand containing a int predicate ICMP_EQ.
412412
raw_string_ostream OS(str);
413413
MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
414-
ASSERT_TRUE(OS.str() == "intpred(eq)");
414+
ASSERT_TRUE(str == "intpred(eq)");
415415
}
416416

417417
TEST(MachineOperandTest, HashValue) {

0 commit comments

Comments
 (0)