[clang] 1b0ca81 - [clang-offload-bundler] use std::forward_list for storing temp file names [NFC]

Sergey Dmitriev via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 08:09:46 PST 2020


Author: Sergey Dmitriev
Date: 2020-11-24T08:07:31-08:00
New Revision: 1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26

URL: https://github.com/llvm/llvm-project/commit/1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26
DIFF: https://github.com/llvm/llvm-project/commit/1b0ca81a6c358d2d52d4f84b7f42e620ead1ed26.diff

LOG: [clang-offload-bundler] use std::forward_list for storing temp file names [NFC]

Use a different container that preserves existing elements on modification
for storing temporary file names. Current container can make StringRefs
returned earlier invalid on reallocation.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D92010

Added: 
    

Modified: 
    clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
index 44c46a89a859..a1b2fecb4a80 100644
--- a/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ b/clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -41,6 +41,7 @@
 #include <cassert>
 #include <cstddef>
 #include <cstdint>
+#include <forward_list>
 #include <memory>
 #include <string>
 #include <system_error>
@@ -394,7 +395,7 @@ class TempFileHandlerRAII {
     if (std::error_code EC =
             sys::fs::createTemporaryFile("clang-offload-bundler", "tmp", File))
       return createFileError(File, EC);
-    Files.push_back(File);
+    Files.push_front(File);
 
     if (Contents) {
       std::error_code EC;
@@ -403,11 +404,11 @@ class TempFileHandlerRAII {
         return createFileError(File, EC);
       OS.write(Contents->data(), Contents->size());
     }
-    return Files.back();
+    return Files.front();
   }
 
 private:
-  SmallVector<SmallString<128u>, 4u> Files;
+  std::forward_list<SmallString<128u>> Files;
 };
 
 } // end anonymous namespace


        


More information about the cfe-commits mailing list