summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Stefano Cianciulli <scianciulli@google.com> 2023-05-15 16:04:02 +0000
committer Stefano Cianciulli <scianciulli@google.com> 2023-06-09 08:59:15 +0000
commitc38f50bcd8529ef4a0bee47ba00e87a9df31d712 (patch)
tree8c0425401312a09382024a8b36d457930a8093e4
parentb770c6c8d9139d8adbf84cc831d6981b34583e02 (diff)
Fix "bugprone-use-after-move" clang-tidy issues
Cherry picked from commit 87e94a7bd7cdb2fef51ac94eac70c1f507128f1b Bug: 264654008 Test: atest ArtGtestsTargetChroot Change-Id: I887cf75ab4fb12e2da1ac982f71878c5de762eaa Merged-In: I450b73c1faccb5a06f8c99f8d9583ec58b39adba
-rw-r--r--build/Android.bp1
-rw-r--r--libartbase/base/bit_vector_test.cc1
-rw-r--r--libartbase/base/scoped_arena_allocator.cc2
-rw-r--r--libartbase/base/unix_file/fd_file_test.cc2
-rw-r--r--libartbase/base/variant_map_test.cc2
-rw-r--r--runtime/jit/jit.cc1
6 files changed, 8 insertions, 1 deletions
diff --git a/build/Android.bp b/build/Android.bp
index 4569b5523f..a8993288d9 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -36,6 +36,7 @@ art_clang_tidy_errors = [
"bugprone-macro-parentheses",
"bugprone-unused-raii", // Protect scoped things like MutexLock.
"bugprone-unused-return-value",
+ "bugprone-use-after-move",
"bugprone-virtual-near-miss",
"misc-unused-using-decls",
"modernize-use-bool-literals",
diff --git a/libartbase/base/bit_vector_test.cc b/libartbase/base/bit_vector_test.cc
index 5f1b167718..929c3237a0 100644
--- a/libartbase/base/bit_vector_test.cc
+++ b/libartbase/base/bit_vector_test.cc
@@ -353,6 +353,7 @@ TEST(BitVector, MovementFree) {
EXPECT_TRUE(bv.IsBitSet(13));
{
BitVector bv2(std::move(bv));
+ // NOLINTNEXTLINE - checking underlying storage has been freed
ASSERT_TRUE(bv.GetRawStorage() == nullptr);
EXPECT_TRUE(bv2.IsBitSet(13));
EXPECT_EQ(alloc.FreeCount(), 0u);
diff --git a/libartbase/base/scoped_arena_allocator.cc b/libartbase/base/scoped_arena_allocator.cc
index a87064fe40..32de97ad76 100644
--- a/libartbase/base/scoped_arena_allocator.cc
+++ b/libartbase/base/scoped_arena_allocator.cc
@@ -123,8 +123,10 @@ ScopedArenaAllocator::ScopedArenaAllocator(ScopedArenaAllocator&& other) noexcep
mark_arena_(other.mark_arena_),
mark_ptr_(other.mark_ptr_),
mark_end_(other.mark_end_) {
+ // NOLINTBEGIN - both ref_count_ and arena_stack_ are still valid after the move
other.DebugStackRefCounter::CheckNoRefs();
other.arena_stack_ = nullptr;
+ // NOLINTEND
}
ScopedArenaAllocator::ScopedArenaAllocator(ArenaStack* arena_stack)
diff --git a/libartbase/base/unix_file/fd_file_test.cc b/libartbase/base/unix_file/fd_file_test.cc
index f5933370da..92f8308b8c 100644
--- a/libartbase/base/unix_file/fd_file_test.cc
+++ b/libartbase/base/unix_file/fd_file_test.cc
@@ -196,7 +196,7 @@ TEST_F(FdFileTest, MoveConstructor) {
int old_fd = file.Fd();
FdFile file2(std::move(file));
- EXPECT_FALSE(file.IsOpened());
+ EXPECT_FALSE(file.IsOpened()); // NOLINT - checking file is no longer opened after move
EXPECT_TRUE(file2.IsOpened());
EXPECT_EQ(old_fd, file2.Fd());
diff --git a/libartbase/base/variant_map_test.cc b/libartbase/base/variant_map_test.cc
index f2da3389b1..f7beeceb71 100644
--- a/libartbase/base/variant_map_test.cc
+++ b/libartbase/base/variant_map_test.cc
@@ -126,6 +126,7 @@ TEST(VariantMaps, RuleOfFive) {
// Test move constructor
FruitMap fmMoved(std::move(fmFilledCopy));
+ // NOLINTNEXTLINE - checking underlying storage has been freed
EXPECT_EQ(size_t(0), fmFilledCopy.Size());
EXPECT_EQ(size_t(2), fmMoved.Size());
EXPECT_EQ(*fmFilled.Get(FruitMap::Apple), *fmMoved.Get(FruitMap::Apple));
@@ -136,6 +137,7 @@ TEST(VariantMaps, RuleOfFive) {
fmMoved2.Set(FruitMap::Apple, 12345); // This value will be clobbered after the move
fmMoved2 = std::move(fmFilledCopy2);
+ // NOLINTNEXTLINE - checking underlying storage has been freed
EXPECT_EQ(size_t(0), fmFilledCopy2.Size());
EXPECT_EQ(size_t(2), fmMoved2.Size());
EXPECT_EQ(*fmFilled.Get(FruitMap::Apple), *fmMoved2.Get(FruitMap::Apple));
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index fe778e4675..3d7ba535c2 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -810,6 +810,7 @@ class JitCompileTask final : public Task {
compilation_kind_(compilation_kind),
scoped_compilation_(std::move(sc)) {
DCHECK(scoped_compilation_.OwnsCompilation());
+ // NOLINTNEXTLINE - OwnsCompilation is still valid after move constructor
DCHECK(!sc.OwnsCompilation());
}