[llvm] 52b48a7 - [llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 16:01:31 PDT 2024


Author: JOE1994
Date: 2024-09-13T19:01:08-04:00
New Revision: 52b48a70d3752f9db36ddcfd26d0451c009b19fc

URL: https://github.com/llvm/llvm-project/commit/52b48a70d3752f9db36ddcfd26d0451c009b19fc
DIFF: https://github.com/llvm/llvm-project/commit/52b48a70d3752f9db36ddcfd26d0451c009b19fc.diff

LOG: [llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)

Avoid excess layer of indirection.

Added: 
    

Modified: 
    llvm/unittests/ADT/Interleave.cpp
    llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
    llvm/unittests/Analysis/CFGTest.cpp
    llvm/unittests/Analysis/DXILResourceTest.cpp
    llvm/unittests/Analysis/LazyCallGraphTest.cpp
    llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
    llvm/unittests/Analysis/ValueTrackingTest.cpp
    llvm/unittests/Analysis/VectorUtilsTest.cpp
    llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
    llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp
    llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp
    llvm/unittests/Transforms/Utils/MemTransferLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ADT/Interleave.cpp b/llvm/unittests/ADT/Interleave.cpp
index bc1ab1fae725e0..6c1be881497d10 100644
--- a/llvm/unittests/ADT/Interleave.cpp
+++ b/llvm/unittests/ADT/Interleave.cpp
@@ -25,7 +25,7 @@ TEST(InterleaveTest, Interleave) {
   interleave(
       Doodles, OS, [&](const char *Name) { OS << Name << "doodle"; }, ", ");
 
-  EXPECT_EQ(OS.str(), "goldendoodle, bernadoodle, labradoodle");
+  EXPECT_EQ(Str, "goldendoodle, bernadoodle, labradoodle");
 }
 
 TEST(InterleaveTest, InterleaveComma) {
@@ -36,7 +36,7 @@ TEST(InterleaveTest, InterleaveComma) {
   const StringRef LongDogs[] = {"dachshund", "doxie", "dackel", "teckel"};
   interleaveComma(LongDogs, OS);
 
-  EXPECT_EQ(OS.str(), "dachshund, doxie, dackel, teckel");
+  EXPECT_EQ(Str, "dachshund, doxie, dackel, teckel");
 }
 
 } // anonymous namespace

diff  --git a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
index 0b340c43e31f86..6437e0c9491f7f 100644
--- a/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
+++ b/llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
@@ -462,7 +462,7 @@ static void RunRandTest(uint64_t Seed, int Size, int MinCount, int MaxCount,
     if (count > 1)
       Args.push_back(ConstantInt::get(Type::getInt32Ty(C), value));
 
-    OpBundle.push_back(OperandBundleDef{ss.str().c_str(), std::move(Args)});
+    OpBundle.push_back(OperandBundleDef{str.c_str(), std::move(Args)});
   }
 
   auto *Assume = cast<AssumeInst>(CallInst::Create(

diff  --git a/llvm/unittests/Analysis/CFGTest.cpp b/llvm/unittests/Analysis/CFGTest.cpp
index 46164268468628..352ee6a1bf43ed 100644
--- a/llvm/unittests/Analysis/CFGTest.cpp
+++ b/llvm/unittests/Analysis/CFGTest.cpp
@@ -39,7 +39,7 @@ class IsPotentiallyReachableTest : public testing::Test {
 
     // A failure here means that the test itself is buggy.
     if (!M)
-      report_fatal_error(os.str().c_str());
+      report_fatal_error(errMsg.c_str());
 
     Function *F = M->getFunction("test");
     if (F == nullptr)

diff  --git a/llvm/unittests/Analysis/DXILResourceTest.cpp b/llvm/unittests/Analysis/DXILResourceTest.cpp
index 7bbb4170978820..e24018457dabec 100644
--- a/llvm/unittests/Analysis/DXILResourceTest.cpp
+++ b/llvm/unittests/Analysis/DXILResourceTest.cpp
@@ -90,10 +90,10 @@ testing::AssertionResult MDTupleEq(const char *LHSExpr, const char *RHSExpr,
   return testing::AssertionFailure() << "Expected equality:\n"
                                      << "  " << LHSExpr << "\n"
                                      << "Which is:\n"
-                                     << "  " << LHSS.str() << "\n\n"
+                                     << "  " << LHSRepr << "\n\n"
                                      << "  " << RHSExpr << "\n"
                                      << "Which is:\n"
-                                     << "  " << RHSS.str();
+                                     << "  " << RHSRepr;
 }
 #define EXPECT_MDEQ(X, Y) EXPECT_PRED_FORMAT2(MDTupleEq, X, Y)
 } // namespace

diff  --git a/llvm/unittests/Analysis/LazyCallGraphTest.cpp b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
index 6cfc01ed81102f..6ca233a50f31fb 100644
--- a/llvm/unittests/Analysis/LazyCallGraphTest.cpp
+++ b/llvm/unittests/Analysis/LazyCallGraphTest.cpp
@@ -34,7 +34,7 @@ std::unique_ptr<Module> parseAssembly(LLVMContext &Context,
 
   // A failure here means that the test itself is buggy.
   if (!M)
-    report_fatal_error(OS.str().c_str());
+    report_fatal_error(ErrMsg.c_str());
 
   return M;
 }

diff  --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
index abaedf9c210b8c..c081c44ed35d00 100644
--- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
+++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
@@ -37,7 +37,7 @@ class TargetLibraryInfoTest : public testing::Test {
     Error.print("", os);
 
     if (!M)
-      report_fatal_error(Twine(os.str()));
+      report_fatal_error(Twine(errMsg));
   }
 
   ::testing::AssertionResult isLibFunc(const Function *FDecl,

diff  --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 34e682cd23e290..77d966155dceff 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -52,7 +52,7 @@ class ValueTrackingTest : public testing::Test {
     std::string errMsg;
     raw_string_ostream os(errMsg);
     Error.print("", os);
-    EXPECT_TRUE(M) << os.str();
+    EXPECT_TRUE(M) << errMsg;
 
     return M;
   }
@@ -3003,7 +3003,7 @@ TEST_P(IsBytewiseValueTest, IsBytewiseValue) {
   raw_string_ostream S(Buff);
   if (Actual)
     S << *Actual;
-  EXPECT_EQ(GetParam().first, S.str());
+  EXPECT_EQ(GetParam().first, Buff);
 }
 
 TEST_F(ValueTrackingTest, ComputeConstantRange) {

diff  --git a/llvm/unittests/Analysis/VectorUtilsTest.cpp b/llvm/unittests/Analysis/VectorUtilsTest.cpp
index fca1ecff9ea8d0..b4d74f715b2db0 100644
--- a/llvm/unittests/Analysis/VectorUtilsTest.cpp
+++ b/llvm/unittests/Analysis/VectorUtilsTest.cpp
@@ -35,7 +35,7 @@ class VectorUtilsTest : public testing::Test {
 
     // A failure here means that the test itself is buggy.
     if (!M)
-      report_fatal_error(Twine(os.str()));
+      report_fatal_error(Twine(errMsg));
 
     Function *F = M->getFunction("test");
     if (F == nullptr)

diff  --git a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
index f18eea07508187..39aec132db8617 100644
--- a/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
+++ b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
@@ -237,7 +237,6 @@ TEST(ElfYamlTextAPI, YAMLWritesTBESymbols) {
   std::string Result;
   raw_string_ostream OS(Result);
   ASSERT_THAT_ERROR(writeIFSToOutputStream(OS, Moved), Succeeded());
-  Result = OS.str();
   compareByLine(Result.c_str(), Expected);
 }
 
@@ -267,6 +266,5 @@ TEST(ElfYamlTextAPI, YAMLWritesNoTBESyms) {
   std::string Result;
   raw_string_ostream OS(Result);
   ASSERT_THAT_ERROR(writeIFSToOutputStream(OS, Stub), Succeeded());
-  Result = OS.str();
   compareByLine(Result.c_str(), Expected);
 }

diff  --git a/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp b/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp
index da78c151e7f68d..9aab3cfd9cf10f 100644
--- a/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp
+++ b/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp
@@ -63,7 +63,7 @@ struct ExtraRematTest : public testing::Test {
 
     // A failure here means that the test itself is buggy.
     if (!M)
-      report_fatal_error(os.str().c_str());
+      report_fatal_error(errMsg.c_str());
   }
 };
 

diff  --git a/llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp b/llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp
index 8c649d3a5ab885..9ccb13934cbd38 100644
--- a/llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp
+++ b/llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp
@@ -137,7 +137,7 @@ struct PGOInstrumentationGenTest
 
     // A failure here means that the test itself is buggy.
     if (!M)
-      report_fatal_error(OS.str().c_str());
+      report_fatal_error(ErrMsg.c_str());
   }
 };
 

diff  --git a/llvm/unittests/Transforms/Utils/MemTransferLowering.cpp b/llvm/unittests/Transforms/Utils/MemTransferLowering.cpp
index acb61170549197..68c6364c1e585b 100644
--- a/llvm/unittests/Transforms/Utils/MemTransferLowering.cpp
+++ b/llvm/unittests/Transforms/Utils/MemTransferLowering.cpp
@@ -88,7 +88,7 @@ struct MemTransferLowerTest : public testing::Test {
 
     // A failure here means that the test itself is buggy.
     if (!M)
-      report_fatal_error(os.str().c_str());
+      report_fatal_error(errMsg.c_str());
   }
 };
 


        


More information about the llvm-commits mailing list