Fix "bugprone-use-after-move" clang-tidy issues
Cherry picked from commit 87e94a7bd7cdb2fef51ac94eac70c1f507128f1b
Bug: 264654008
Test: atest ArtGtestsTargetChroot
Change-Id: I887cf75ab4fb12e2da1ac982f71878c5de762eaa
Merged-In: I450b73c1faccb5a06f8c99f8d9583ec58b39adba
diff --git a/build/Android.bp b/build/Android.bp
index 4569b55..a899328 100644
--- a/build/Android.bp
+++ b/build/Android.bp
@@ -36,6 +36,7 @@
"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 5f1b167..929c323 100644
--- a/libartbase/base/bit_vector_test.cc
+++ b/libartbase/base/bit_vector_test.cc
@@ -353,6 +353,7 @@
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 a87064f..32de97a 100644
--- a/libartbase/base/scoped_arena_allocator.cc
+++ b/libartbase/base/scoped_arena_allocator.cc
@@ -123,8 +123,10 @@
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 f593337..92f8308 100644
--- a/libartbase/base/unix_file/fd_file_test.cc
+++ b/libartbase/base/unix_file/fd_file_test.cc
@@ -196,7 +196,7 @@
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 f2da338..f7beece 100644
--- a/libartbase/base/variant_map_test.cc
+++ b/libartbase/base/variant_map_test.cc
@@ -126,6 +126,7 @@
// 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 @@
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 fe778e4..3d7ba53 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -810,6 +810,7 @@
compilation_kind_(compilation_kind),
scoped_compilation_(std::move(sc)) {
DCHECK(scoped_compilation_.OwnsCompilation());
+ // NOLINTNEXTLINE - OwnsCompilation is still valid after move constructor
DCHECK(!sc.OwnsCompilation());
}