[llvm] [CAS] Add MappedFileRegionBumpPtr (PR #114099)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 16:08:51 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- llvm/include/llvm/CAS/MappedFileRegionBumpPtr.h llvm/lib/CAS/MappedFileRegionBumpPtr.cpp llvm/lib/CAS/OnDiskCommon.cpp llvm/lib/CAS/OnDiskCommon.h llvm/unittests/CAS/ProgramTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CAS/MappedFileRegionBumpPtr.cpp b/llvm/lib/CAS/MappedFileRegionBumpPtr.cpp
index e38068f3b..9c2d15e4c 100644
--- a/llvm/lib/CAS/MappedFileRegionBumpPtr.cpp
+++ b/llvm/lib/CAS/MappedFileRegionBumpPtr.cpp
@@ -152,7 +152,7 @@ Expected<MappedFileRegionBumpPtr> MappedFileRegionBumpPtr::create(
     // Retrieve the current size now that we have exclusive access.
     FileSize = FileSizeInfo::get(File);
     if (!FileSize)
-        return createFileError(Result.Path, FileSize.getError());
+      return createFileError(Result.Path, FileSize.getError());
   }
 
   // At this point either the file is still under-sized, or we have the size for
@@ -282,7 +282,8 @@ Expected<int64_t> MappedFileRegionBumpPtr::allocateOffset(uint64_t AllocSize) {
     int64_t NewSize;
     // The minimum increment is a page, but allocate more to amortize the cost.
     constexpr int64_t Increment = 1 * 1024 * 1024; // 1 MB
-    if (Error E = preallocateFileTail(*FD, DiskSize, DiskSize + Increment).moveInto(NewSize))
+    if (Error E = preallocateFileTail(*FD, DiskSize, DiskSize + Increment)
+                      .moveInto(NewSize))
       return std::move(E);
     assert(NewSize >= DiskSize + Increment);
     // FIXME: on Darwin this can under-count the size if there is a race to
diff --git a/llvm/lib/CAS/OnDiskCommon.cpp b/llvm/lib/CAS/OnDiskCommon.cpp
index 079954bc0..d17ab0c15 100644
--- a/llvm/lib/CAS/OnDiskCommon.cpp
+++ b/llvm/lib/CAS/OnDiskCommon.cpp
@@ -79,21 +79,22 @@ cas::ondisk::tryLockFileThreadSafe(int FD, std::chrono::milliseconds Timeout,
 #endif
 }
 
-Expected<size_t> cas::ondisk::preallocateFileTail(int FD, size_t CurrentSize, size_t NewSize) {
+Expected<size_t> cas::ondisk::preallocateFileTail(int FD, size_t CurrentSize,
+                                                  size_t NewSize) {
   auto CreateError = [&](std::error_code EC) -> Expected<size_t> {
     if (EC == std::errc::not_supported)
       // Ignore ENOTSUP in case the filesystem cannot preallocate.
       return NewSize;
 #if defined(HAVE_POSIX_FALLOCATE)
-    if (EC == std::errc::invalid_argument &&
-        CurrentSize < NewSize && // len > 0
+    if (EC == std::errc::invalid_argument && CurrentSize < NewSize && // len > 0
         NewSize < std::numeric_limits<off_t>::max()) // 0 <= offset, len < max
       // Prior to 2024, POSIX required EINVAL for cases that should be ENOTSUP,
       // so handle it the same as above if it is not one of the other ways to
       // get EINVAL.
       return NewSize;
 #endif
-    return createStringError(EC, "failed to allocate to CAS file: " + EC.message());
+    return createStringError(EC,
+                             "failed to allocate to CAS file: " + EC.message());
   };
 #if defined(HAVE_POSIX_FALLOCATE)
   // Note: posix_fallocate returns its error directly, not via errno.
diff --git a/llvm/lib/CAS/OnDiskCommon.h b/llvm/lib/CAS/OnDiskCommon.h
index 3fef23ace..9c78cde6b 100644
--- a/llvm/lib/CAS/OnDiskCommon.h
+++ b/llvm/lib/CAS/OnDiskCommon.h
@@ -37,7 +37,8 @@ std::error_code tryLockFileThreadSafe(
 /// \c std::errc::no_space_on_device are detected before we write data.
 ///
 /// \returns the new size of the file, or an \c Error.
-Expected<size_t> preallocateFileTail(int FD, size_t CurrentSize, size_t NewSize);
+Expected<size_t> preallocateFileTail(int FD, size_t CurrentSize,
+                                     size_t NewSize);
 
 } // namespace llvm::cas::ondisk
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/114099


More information about the llvm-commits mailing list