[compiler-rt] r177077 - [Sanitizer] Fix compiler warnings and style issues in sanitizer_common tests. Use -Werror=sign-compare when building them.
Alexey Samsonov
samsonov at google.com
Thu Mar 14 08:15:35 PDT 2013
Author: samsonov
Date: Thu Mar 14 10:15:35 2013
New Revision: 177077
URL: http://llvm.org/viewvc/llvm-project?rev=177077&view=rev
Log:
[Sanitizer] Fix compiler warnings and style issues in sanitizer_common tests. Use -Werror=sign-compare when building them.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc?rev=177077&r1=177076&r2=177077&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.cc Thu Mar 14 10:15:35 2013
@@ -80,6 +80,8 @@ void ThreadContextBase::Reset(void *arg)
// ThreadRegistry implementation.
+const u32 ThreadRegistry::kUnknownTid = -1U;
+
ThreadRegistry::ThreadRegistry(ThreadContextFactory factory, u32 max_threads,
u32 thread_quarantine_size)
: context_factory_(factory),
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h?rev=177077&r1=177076&r2=177077&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_thread_registry.h Thu Mar 14 10:15:35 2013
@@ -77,7 +77,6 @@ class ThreadRegistry {
const u32 max_threads_;
const u32 thread_quarantine_size_;
- static const u32 kUnknownTid = -1U;
BlockingMutex mtx_;
u32 n_contexts_; // Number of created thread contexts,
@@ -92,6 +91,8 @@ class ThreadRegistry {
IntrusiveList<ThreadContextBase> dead_threads_;
public:
+ static const u32 kUnknownTid;
+
ThreadRegistry(ThreadContextFactory factory, u32 max_threads,
u32 thread_quarantine_size);
void GetNumberOfThreads(uptr *total = 0, uptr *running = 0, uptr *alive = 0);
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=177077&r1=177076&r2=177077&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Thu Mar 14 10:15:35 2013
@@ -56,7 +56,7 @@ macro(add_sanitizer_tests_for_arch arch)
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
- -O2 -g -Wall -Werror ${TARGET_FLAGS})
+ -O2 -g -Wall -Werror -Werror=sign-compare ${TARGET_FLAGS})
set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread -ldl ${TARGET_FLAGS})
set(SANITIZER_TEST_OBJECTS)
foreach(source ${SANITIZER_TEST_SOURCES})
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc?rev=177077&r1=177076&r2=177077&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc Thu Mar 14 10:15:35 2013
@@ -118,7 +118,7 @@ void ThreadListerTest::SpawnTidReporter(
*tid = thread_arg.reported_tid;
}
-std::vector<pid_t> ReadTidsToVector(ThreadLister *thread_lister) {
+static std::vector<pid_t> ReadTidsToVector(ThreadLister *thread_lister) {
std::vector<pid_t> listed_tids;
pid_t tid;
while ((tid = thread_lister->GetNextTID()) >= 0)
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc?rev=177077&r1=177076&r2=177077&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc Thu Mar 14 10:15:35 2013
@@ -39,11 +39,11 @@ static void CheckThreadQuantity(ThreadRe
EXPECT_EQ(exp_alive, alive);
}
-static bool is_detached(int tid) {
+static bool is_detached(u32 tid) {
return (tid % 2 == 0);
}
-static uptr get_uid(int tid) {
+static uptr get_uid(u32 tid) {
return tid * 2;
}
@@ -64,50 +64,52 @@ static void MarkUidAsPresent(ThreadConte
static void TestRegistry(ThreadRegistry *registry, bool has_quarantine) {
// Create and start a main thread.
- EXPECT_EQ(0, registry->CreateThread(get_uid(0), true, -1, 0));
+ EXPECT_EQ(0U, registry->CreateThread(get_uid(0), true, -1, 0));
registry->StartThread(0, 0, 0);
// Create a bunch of threads.
- for (int i = 1; i <= 10; i++) {
+ for (u32 i = 1; i <= 10; i++) {
EXPECT_EQ(i, registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
}
CheckThreadQuantity(registry, 11, 1, 11);
// Start some of them.
- for (int i = 1; i <= 5; i++) {
+ for (u32 i = 1; i <= 5; i++) {
registry->StartThread(i, 0, 0);
}
CheckThreadQuantity(registry, 11, 6, 11);
// Finish, create and start more threads.
- for (int i = 1; i <= 5; i++) {
+ for (u32 i = 1; i <= 5; i++) {
registry->FinishThread(i);
if (!is_detached(i))
registry->JoinThread(i, 0);
}
- for (int i = 6; i <= 10; i++) {
+ for (u32 i = 6; i <= 10; i++) {
registry->StartThread(i, 0, 0);
}
- std::vector<int> new_tids;
- for (int i = 11; i <= 15; i++) {
+ std::vector<u32> new_tids;
+ for (u32 i = 11; i <= 15; i++) {
new_tids.push_back(
registry->CreateThread(get_uid(i), is_detached(i), 0, 0));
}
- ASSERT_LE(kRegistryQuarantine, 5);
- int exp_total = 16 - (has_quarantine ? 5 - kRegistryQuarantine : 0);
+ ASSERT_LE(kRegistryQuarantine, 5U);
+ u32 exp_total = 16 - (has_quarantine ? 5 - kRegistryQuarantine : 0);
CheckThreadQuantity(registry, exp_total, 6, 11);
// Test SetThreadName and FindThread.
registry->SetThreadName(6, "six");
registry->SetThreadName(7, "seven");
- EXPECT_EQ(7, registry->FindThread(HasName, (void*)"seven"));
- EXPECT_EQ(-1, registry->FindThread(HasName, (void*)"none"));
- EXPECT_EQ(0, registry->FindThread(HasUid, (void*)get_uid(0)));
- EXPECT_EQ(10, registry->FindThread(HasUid, (void*)get_uid(10)));
- EXPECT_EQ(-1, registry->FindThread(HasUid, (void*)0x1234));
+ EXPECT_EQ(7U, registry->FindThread(HasName, (void*)"seven"));
+ EXPECT_EQ(ThreadRegistry::kUnknownTid,
+ registry->FindThread(HasName, (void*)"none"));
+ EXPECT_EQ(0U, registry->FindThread(HasUid, (void*)get_uid(0)));
+ EXPECT_EQ(10U, registry->FindThread(HasUid, (void*)get_uid(10)));
+ EXPECT_EQ(ThreadRegistry::kUnknownTid,
+ registry->FindThread(HasUid, (void*)0x1234));
// Detach and finish and join remaining threads.
- for (int i = 6; i <= 10; i++) {
+ for (u32 i = 6; i <= 10; i++) {
registry->DetachThread(i);
registry->FinishThread(i);
}
- for (int i = 0; i < new_tids.size(); i++) {
- int tid = new_tids[i];
+ for (u32 i = 0; i < new_tids.size(); i++) {
+ u32 tid = new_tids[i];
registry->StartThread(tid, 0, 0);
registry->DetachThread(tid);
registry->FinishThread(tid);
@@ -120,7 +122,7 @@ static void TestRegistry(ThreadRegistry
ThreadRegistryLock l(registry);
registry->RunCallbackForEachThreadLocked(MarkUidAsPresent, &has_tid[0]);
}
- for (int i = 0; i < exp_total; i++) {
+ for (u32 i = 0; i < exp_total; i++) {
EXPECT_TRUE(has_tid[i]);
}
{
@@ -130,7 +132,7 @@ static void TestRegistry(ThreadRegistry
EXPECT_EQ(main_thread, registry->FindThreadContextLocked(
HasUid, (void*)get_uid(0)));
}
- EXPECT_EQ(11, registry->GetMaxAliveThreads());
+ EXPECT_EQ(11U, registry->GetMaxAliveThreads());
}
TEST(SanitizerCommon, ThreadRegistryTest) {
@@ -195,7 +197,7 @@ void *RunThread(void *arg) {
static void ThreadedTestRegistry(ThreadRegistry *registry) {
// Create and start a main thread.
- EXPECT_EQ(0, registry->CreateThread(0, true, -1, 0));
+ EXPECT_EQ(0U, registry->CreateThread(0, true, -1, 0));
registry->StartThread(0, 0, 0);
pthread_t threads[kNumShards];
RunThreadArgs args[kNumShards];
More information about the llvm-commits
mailing list