[llvm] r342386 - Use createTemporaryFile in SampleProfTest

Alexander Kornienko via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 05:11:02 PDT 2018


Author: alexfh
Date: Mon Sep 17 05:11:01 2018
New Revision: 342386

URL: http://llvm.org/viewvc/llvm-project?rev=342386&view=rev
Log:
Use createTemporaryFile in SampleProfTest

Create a temporary file in the system temporary directory instead of creating a
file in the current directory, which may be not writable. (Fix for an issue
introduced in r342283.)

Modified:
    llvm/trunk/unittests/ProfileData/SampleProfTest.cpp

Modified: llvm/trunk/unittests/ProfileData/SampleProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/SampleProfTest.cpp?rev=342386&r1=342385&r2=342386&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/SampleProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/SampleProfTest.cpp Mon Sep 17 05:11:01 2018
@@ -42,7 +42,7 @@ struct SampleProfTest : ::testing::Test
 
   SampleProfTest() : Writer(), Reader() {}
 
-  void createWriter(SampleProfileFormat Format, const std::string &Profile) {
+  void createWriter(SampleProfileFormat Format, StringRef Profile) {
     std::error_code EC;
     std::unique_ptr<raw_ostream> OS(
         new raw_fd_ostream(Profile, EC, sys::fs::F_None));
@@ -51,7 +51,7 @@ struct SampleProfTest : ::testing::Test
     Writer = std::move(WriterOrErr.get());
   }
 
-  void readProfile(const Module &M, const std::string &Profile) {
+  void readProfile(const Module &M, StringRef Profile) {
     auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
     ASSERT_TRUE(NoError(ReaderOrErr.getError()));
     Reader = std::move(ReaderOrErr.get());
@@ -59,7 +59,9 @@ struct SampleProfTest : ::testing::Test
   }
 
   void testRoundTrip(SampleProfileFormat Format) {
-    std::string Profile = std::string("profile.") + std::to_string(Format);
+    SmallVector<char, 128> ProfilePath;
+    ASSERT_TRUE(NoError(llvm::sys::fs::createTemporaryFile("profile", "", ProfilePath)));
+    StringRef Profile(ProfilePath.data(), ProfilePath.size());
     createWriter(Format, Profile);
 
     StringRef FooName("_Z3fooi");




More information about the llvm-commits mailing list