Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] Add erase function to blockstore #97641

Merged
merged 2 commits into from
Jul 12, 2024

Conversation

michaelrj-google
Copy link
Contributor

This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.

@llvmbot llvmbot added the libc label Jul 3, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 3, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.


Full diff: https://github.com/llvm/llvm-project/pull/97641.diff

2 Files Affected:

  • (modified) libc/src/__support/blockstore.h (+53-2)
  • (modified) libc/test/src/__support/blockstore_test.cpp (+98)
diff --git a/libc/src/__support/blockstore.h b/libc/src/__support/blockstore.h
index bcab7504dbd6e..e022a6ae22b0d 100644
--- a/libc/src/__support/blockstore.h
+++ b/libc/src/__support/blockstore.h
@@ -9,8 +9,10 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_BLOCKSTORE_H
 #define LLVM_LIBC_SRC___SUPPORT_BLOCKSTORE_H
 
-#include <src/__support/CPP/new.h>
-#include <src/__support/libc_assert.h>
+#include "src/__support/CPP/array.h"
+#include "src/__support/CPP/new.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/libc_assert.h"
 
 #include <stddef.h>
 #include <stdint.h>
@@ -97,6 +99,16 @@ class BlockStore {
       return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index);
     }
 
+    LIBC_INLINE Iterator operator+(int i) {
+      LIBC_ASSERT(i >= 0 &&
+                  "BlockStore iterators only support incrementation.");
+      auto other = *this;
+      for (int j = 0; j < i; ++j)
+        ++other;
+
+      return other;
+    }
+
     LIBC_INLINE bool operator==(const Iterator &rhs) const {
       return block == rhs.block && index == rhs.index;
     }
@@ -175,6 +187,45 @@ class BlockStore {
     else
       return Iterator(current, fill_count);
   }
+
+  // Removes and the element at pos, then moves all the objects after back by
+  // one to fill the hole. It's assumed that pos is a valid iterator to
+  // somewhere in this block_store.
+  LIBC_INLINE void erase(Iterator pos) {
+    const Iterator last_item = Iterator(current, fill_count);
+    if (pos == last_item) {
+      pop_back();
+      return;
+    }
+
+    if constexpr (REVERSE_ORDER) {
+      // REVERSE: Iterate from begin to pos
+      const Iterator range_end = pos;
+      Iterator cur = begin();
+      T prev_val = *cur;
+      ++cur;
+      T cur_val = *cur;
+
+      for (; cur != range_end; ++cur) {
+        cur_val = *cur;
+        *cur = prev_val;
+        prev_val = cur_val;
+      }
+      // We will always need to move at least one item (since we know that pos
+      // isn't the last item due to the check above).
+      *cur = prev_val;
+    } else {
+      // FORWARD: Iterate from pos to end
+      const Iterator range_end = end();
+      Iterator cur = pos;
+      Iterator prev = cur;
+      ++cur;
+
+      for (; cur != range_end; prev = cur, ++cur)
+        *prev = *cur;
+    }
+    pop_back();
+  }
 };
 
 template <typename T, size_t BLOCK_SIZE, bool REVERSE_ORDER>
diff --git a/libc/test/src/__support/blockstore_test.cpp b/libc/test/src/__support/blockstore_test.cpp
index 5fe8fef1b6edc..dd74ea18f2c02 100644
--- a/libc/test/src/__support/blockstore_test.cpp
+++ b/libc/test/src/__support/blockstore_test.cpp
@@ -64,6 +64,99 @@ class LlvmLibcBlockStoreTest : public LIBC_NAMESPACE::testing::Test {
     }
     block_store.destroy(&block_store);
   }
+
+  template <bool REVERSE> void erase_test() {
+    using LIBC_NAMESPACE::BlockStore;
+    BlockStore<int, 2, REVERSE> block_store;
+    int i;
+
+    constexpr int ARR_SIZE = 6;
+
+    ASSERT_TRUE(block_store.empty());
+    for (int i = 0; i < ARR_SIZE; i++) {
+      ASSERT_TRUE(block_store.push_back(i + 1));
+    }
+
+    // block_store state should be {1,2,3,4,5,6}
+
+    block_store.erase(block_store.begin());
+
+    // FORWARD: block_store state should be {2,3,4,5,6}
+    // REVERSE: block_store state should be {1,2,3,4,5}
+
+    auto iter = block_store.begin();
+    for (i = 0; iter != block_store.end(); ++i, ++iter) {
+      if (!REVERSE) {
+        ASSERT_EQ(*iter, i + 2);
+      } else {
+        ASSERT_EQ(*iter, (ARR_SIZE - 1) - i);
+      }
+    }
+
+    // Assert that there were the correct number of elements
+    ASSERT_EQ(i, ARR_SIZE - 1);
+
+    block_store.erase(block_store.end());
+
+    // BOTH: block_store state should be {2,3,4,5}
+
+    iter = block_store.begin();
+    for (i = 0; iter != block_store.end(); ++i, ++iter) {
+      if (!REVERSE) {
+        ASSERT_EQ(*iter, i + 2);
+      } else {
+        ASSERT_EQ(*iter, (ARR_SIZE - 1) - i);
+      }
+    }
+
+    ASSERT_EQ(i, ARR_SIZE - 2);
+
+    block_store.erase(block_store.begin() + 1);
+
+    // FORWARD: block_store state should be {2,4,5}
+    // REVERSE: block_store state should be {2,3,5}
+
+    const int FORWARD_RESULTS[] = {2, 4, 5};
+    const int REVERSE_RESULTS[] = {2, 3, 5};
+
+    iter = block_store.begin();
+    for (i = 0; iter != block_store.end(); ++i, ++iter) {
+      if (!REVERSE) {
+        ASSERT_EQ(*iter, FORWARD_RESULTS[i]);
+      } else {
+        ASSERT_EQ(*iter, REVERSE_RESULTS[ARR_SIZE - 4 - i]); // reversed
+      }
+    }
+
+    ASSERT_EQ(i, ARR_SIZE - 3);
+
+    block_store.erase(block_store.begin() + 1);
+    // BOTH: block_store state should be {2,5}
+
+    iter = block_store.begin();
+    if (!REVERSE) {
+      ASSERT_EQ(*iter, 2);
+      ASSERT_EQ(*(iter + 1), 5);
+    } else {
+      ASSERT_EQ(*iter, 5);
+      ASSERT_EQ(*(iter + 1), 2);
+    }
+
+    block_store.erase(block_store.begin());
+    // FORWARD: block_store state should be {5}
+    // REVERSE: block_store state should be {2}
+    iter = block_store.begin();
+    if (!REVERSE) {
+      ASSERT_EQ(*iter, 5);
+    } else {
+      ASSERT_EQ(*iter, 2);
+    }
+
+    block_store.erase(block_store.begin());
+    // BOTH: block_store state should be {}
+
+    block_store.destroy(&block_store);
+  }
 };
 
 TEST_F(LlvmLibcBlockStoreTest, PopulateAndIterate4) {
@@ -100,3 +193,8 @@ TEST_F(LlvmLibcBlockStoreTest, Empty) {
   empty_test<false>();
   empty_test<true>();
 }
+
+TEST_F(LlvmLibcBlockStoreTest, Erase) {
+  erase_test<false>();
+  erase_test<true>();
+}

This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.
@michaelrj-google michaelrj-google merged commit 9e452c1 into llvm:main Jul 12, 2024
4 of 5 checks passed
@michaelrj-google michaelrj-google deleted the libcBlockstoreErase branch July 12, 2024 17:44
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-dbg-asan running on libc-x86_64-debian while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/147/builds/1942

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcStrtouint32Test.CleanBaseSixteenDecode
[       OK ] LlvmLibcStrtouint32Test.CleanBaseSixteenDecode (8 us)
[ RUN      ] LlvmLibcStrtouint32Test.MessyBaseSixteenDecode
[       OK ] LlvmLibcStrtouint32Test.MessyBaseSixteenDecode (3 us)
[ RUN      ] LlvmLibcStrtouint32Test.AutomaticBaseSelection
[       OK ] LlvmLibcStrtouint32Test.AutomaticBaseSelection (4 us)
Ran 14 tests.  PASS: 14  FAIL: 0
[744/746] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__.__build__.dir/blockstore_test.cpp.o
[745/746] Linking CXX executable projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[746/746] Running unit test libc.test.src.__support.blockstore_test.__unit__
FAILED: projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[==========] Running 10 tests from 1 test suite.
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate4 (11 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate8 (5 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate10 (10 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4 (3 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8 (4 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10 (5 us)
[ RUN      ] LlvmLibcBlockStoreTest.Back
[       OK ] LlvmLibcBlockStoreTest.Back (11 us)
[ RUN      ] LlvmLibcBlockStoreTest.BackReverse
[       OK ] LlvmLibcBlockStoreTest.BackReverse (14 us)
[ RUN      ] LlvmLibcBlockStoreTest.Empty
[       OK ] LlvmLibcBlockStoreTest.Empty (16 us)
[ RUN      ] LlvmLibcBlockStoreTest.Erase
=================================================================
==2512717==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd995a3b1c at pc 0x557ea964a5c5 bp 0x7ffd995a3990 sp 0x7ffd995a3988
WRITE of size 4 at 0x7ffd995a3b1c thread T0
    #0 0x557ea964a5c4 in __llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::erase(__llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::Iterator) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/blockstore.h:217:12
    #1 0x557ea964a5c4 in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:99:17
    #2 0x557ea963f925 in LlvmLibcBlockStoreTest_Erase::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:199:3
    #3 0x557ea964d570 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:166:8
    #4 0x557ea9667e41 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #5 0x7f0c4c046249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #6 0x7f0c4c046304 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #7 0x557ea957f660 in _start (/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__+0x25660) (BuildId: 2f17b92160e143b234e7403a792d0f73a9a33825)

Address 0x7ffd995a3b1c is located in stack of thread T0 at offset 380 in frame
    #0 0x557ea9648cff in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:68

  This frame has 12 object(s):
    [32, 48) 'agg.tmp130560'
Step 7 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[ RUN      ] LlvmLibcStrtouint32Test.CleanBaseSixteenDecode
[       OK ] LlvmLibcStrtouint32Test.CleanBaseSixteenDecode (8 us)
[ RUN      ] LlvmLibcStrtouint32Test.MessyBaseSixteenDecode
[       OK ] LlvmLibcStrtouint32Test.MessyBaseSixteenDecode (3 us)
[ RUN      ] LlvmLibcStrtouint32Test.AutomaticBaseSelection
[       OK ] LlvmLibcStrtouint32Test.AutomaticBaseSelection (4 us)
Ran 14 tests.  PASS: 14  FAIL: 0
[744/746] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__.__build__.dir/blockstore_test.cpp.o
[745/746] Linking CXX executable projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[746/746] Running unit test libc.test.src.__support.blockstore_test.__unit__
FAILED: projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[==========] Running 10 tests from 1 test suite.
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate4 (11 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate8 (5 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate10 (10 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4 (3 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8 (4 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10 (5 us)
[ RUN      ] LlvmLibcBlockStoreTest.Back
[       OK ] LlvmLibcBlockStoreTest.Back (11 us)
[ RUN      ] LlvmLibcBlockStoreTest.BackReverse
[       OK ] LlvmLibcBlockStoreTest.BackReverse (14 us)
[ RUN      ] LlvmLibcBlockStoreTest.Empty
[       OK ] LlvmLibcBlockStoreTest.Empty (16 us)
[ RUN      ] LlvmLibcBlockStoreTest.Erase
=================================================================
==2512717==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd995a3b1c at pc 0x557ea964a5c5 bp 0x7ffd995a3990 sp 0x7ffd995a3988
WRITE of size 4 at 0x7ffd995a3b1c thread T0
    #0 0x557ea964a5c4 in __llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::erase(__llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::Iterator) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/src/__support/blockstore.h:217:12
    #1 0x557ea964a5c4 in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:99:17
    #2 0x557ea963f925 in LlvmLibcBlockStoreTest_Erase::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:199:3
    #3 0x557ea964d570 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:166:8
    #4 0x557ea9667e41 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #5 0x7f0c4c046249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #6 0x7f0c4c046304 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)
    #7 0x557ea957f660 in _start (/home/llvm-libc-buildbot/home/sivachandra/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__+0x25660) (BuildId: 2f17b92160e143b234e7403a792d0f73a9a33825)

Address 0x7ffd995a3b1c is located in stack of thread T0 at offset 380 in frame
    #0 0x557ea9648cff in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:68

  This frame has 12 object(s):
    [32, 48) 'agg.tmp130560'

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 12, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-fullbuild-dbg-asan running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/171/builds/1975

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock (2 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[818/822] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__.__build__.dir/blockstore_test.cpp.o
[819/822] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (54 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[820/822] Linking CXX executable projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[821/822] Running unit test libc.test.src.__support.blockstore_test.__unit__
FAILED: projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[==========] Running 10 tests from 1 test suite.
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate4 (14 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate8 (12 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate10 (26 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4 (3 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8 (18 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10 (12 us)
[ RUN      ] LlvmLibcBlockStoreTest.Back
[       OK ] LlvmLibcBlockStoreTest.Back (7 us)
[ RUN      ] LlvmLibcBlockStoreTest.BackReverse
[       OK ] LlvmLibcBlockStoreTest.BackReverse (6 us)
[ RUN      ] LlvmLibcBlockStoreTest.Empty
[       OK ] LlvmLibcBlockStoreTest.Empty (24 us)
[ RUN      ] LlvmLibcBlockStoreTest.Erase
=================================================================
==998118==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd1f84c5dc at pc 0x561231ac9967 bp 0x7ffd1f84c450 sp 0x7ffd1f84c448
WRITE of size 4 at 0x7ffd1f84c5dc thread T0
    #0 0x561231ac9966 in __llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::erase(__llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::Iterator) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/blockstore.h:217:12
    #1 0x561231ac9966 in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:99:17
    #2 0x561231abdc65 in LlvmLibcBlockStoreTest_Erase::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:199:3
    #3 0x561231acc8d0 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:166:8
    #4 0x561231ae71a1 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #5 0x7f02f7a46249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)

Address 0x7ffd1f84c5dc is located in stack of thread T0 at offset 380 in frame
    #0 0x561231ac7f3f in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:68

  This frame has 12 object(s):
    [32, 48) 'agg.tmp130562'
    [64, 80) 'agg.tmp118544'
    [96, 112) 'agg.tmp108509'
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[       OK ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock (2 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[818/822] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__.__build__.dir/blockstore_test.cpp.o
[819/822] Running unit test libc.test.src.time.nanosleep_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcNanosleep.SmokeTest
[       OK ] LlvmLibcNanosleep.SmokeTest (54 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[820/822] Linking CXX executable projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[821/822] Running unit test libc.test.src.__support.blockstore_test.__unit__
FAILED: projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.blockstore_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/build/projects/libc/test/src/__support/libc.test.src.__support.blockstore_test.__unit__.__build__
[==========] Running 10 tests from 1 test suite.
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate4 (14 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate8 (12 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterate10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterate10 (26 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse4 (3 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse8 (18 us)
[ RUN      ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10
[       OK ] LlvmLibcBlockStoreTest.PopulateAndIterateReverse10 (12 us)
[ RUN      ] LlvmLibcBlockStoreTest.Back
[       OK ] LlvmLibcBlockStoreTest.Back (7 us)
[ RUN      ] LlvmLibcBlockStoreTest.BackReverse
[       OK ] LlvmLibcBlockStoreTest.BackReverse (6 us)
[ RUN      ] LlvmLibcBlockStoreTest.Empty
[       OK ] LlvmLibcBlockStoreTest.Empty (24 us)
[ RUN      ] LlvmLibcBlockStoreTest.Erase
=================================================================
==998118==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffd1f84c5dc at pc 0x561231ac9967 bp 0x7ffd1f84c450 sp 0x7ffd1f84c448
WRITE of size 4 at 0x7ffd1f84c5dc thread T0
    #0 0x561231ac9966 in __llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::erase(__llvm_libc_19_0_0_git::BlockStore<int, 2ul, true>::Iterator) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/src/__support/blockstore.h:217:12
    #1 0x561231ac9966 in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:99:17
    #2 0x561231abdc65 in LlvmLibcBlockStoreTest_Erase::Run() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:199:3
    #3 0x561231acc8d0 in __llvm_libc_19_0_0_git::testing::Test::runTests(__llvm_libc_19_0_0_git::testing::TestOptions const&) /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTest.cpp:166:8
    #4 0x561231ae71a1 in main /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/UnitTest/LibcTestMain.cpp:51:10
    #5 0x7f02f7a46249  (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId: 58254ca972028402bc40624f81388d85ec95f70d)

Address 0x7ffd1f84c5dc is located in stack of thread T0 at offset 380 in frame
    #0 0x561231ac7f3f in void LlvmLibcBlockStoreTest::erase_test<true>() /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg-asan/llvm-project/libc/test/src/__support/blockstore_test.cpp:68

  This frame has 12 object(s):
    [32, 48) 'agg.tmp130562'
    [64, 80) 'agg.tmp118544'
    [96, 112) 'agg.tmp108509'

michaelrj-google added a commit that referenced this pull request Jul 12, 2024
@michaelrj-google michaelrj-google restored the libcBlockstoreErase branch July 12, 2024 17:51
michaelrj-google added a commit that referenced this pull request Jul 12, 2024
michaelrj-google added a commit that referenced this pull request Jul 12, 2024
Reland of #97641 with sanitizer fixes

This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Reland of llvm#97641 with sanitizer fixes

This adds the ability to erase a value from a blockstore based on an
iterator. For usability/testing purposes it also includes an addition
operator for blockstore's iterator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants