Skip to content

Conversation

frobtech
Copy link
Contributor

@frobtech frobtech commented Sep 5, 2025

Tests can be at top-level or inside an anonymous namespace,
doesn't matter. But putting their helper code inside anonymous
namespaces both makes the code compatible with compiling using
-Wmissing-declarations and might let the compiler optimize the
test good a bit better.

Tests can be at top-level or inside an anonymous namespace,
doesn't matter.  But putting their helper code inside anonymous
namespaces both makes the code compatible with compiling using
-Wmissing-declarations and might let the compiler optimize the
test good a bit better.
@frobtech frobtech requested review from hctim and PiJoules September 5, 2025 23:57
@frobtech frobtech marked this pull request as ready for review September 5, 2025 23:57
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Roland McGrath (frobtech)

Changes

Tests can be at top-level or inside an anonymous namespace,
doesn't matter. But putting their helper code inside anonymous
namespaces both makes the code compatible with compiling using
-Wmissing-declarations and might let the compiler optimize the
test good a bit better.


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

3 Files Affected:

  • (modified) compiler-rt/lib/gwp_asan/tests/compression.cpp (+3)
  • (modified) compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp (+5-1)
  • (modified) compiler-rt/lib/gwp_asan/tests/thread_contention.cpp (+4)
diff --git a/compiler-rt/lib/gwp_asan/tests/compression.cpp b/compiler-rt/lib/gwp_asan/tests/compression.cpp
index 2423c866a531d..91b09770836a1 100644
--- a/compiler-rt/lib/gwp_asan/tests/compression.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/compression.cpp
@@ -11,6 +11,7 @@
 
 namespace gwp_asan {
 namespace compression {
+namespace {
 
 TEST(GwpAsanCompressionTest, SingleByteVarInt) {
   uint8_t Compressed[1];
@@ -263,5 +264,7 @@ TEST(GwpAsanCompressionTest, CompressPartiallySucceedsWithTooSmallBuffer) {
   EXPECT_EQ(pack(Uncompressed, 3u, Compressed, 6u), 5u);
   EXPECT_EQ(pack(Uncompressed, 3u, Compressed, 3 * kBytesForLargestVarInt), 5u);
 }
+
+} // namespace
 } // namespace compression
 } // namespace gwp_asan
diff --git a/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp b/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
index f2a77b094a899..010d29a233820 100644
--- a/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/slot_reuse.cpp
@@ -6,9 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <set>
+
 #include "gwp_asan/tests/harness.h"
 
-#include <set>
+namespace {
 
 void singleByteGoodAllocDealloc(gwp_asan::GuardedPoolAllocator *GPA) {
   void *Ptr = GPA->allocate(1);
@@ -72,3 +74,5 @@ TEST_F(CustomGuardedPoolAllocator, NoReuseBeforeNecessary129) {
   InitNumSlots(kPoolSize);
   runNoReuseBeforeNecessary(&GPA, kPoolSize);
 }
+
+} // namespace
diff --git a/compiler-rt/lib/gwp_asan/tests/thread_contention.cpp b/compiler-rt/lib/gwp_asan/tests/thread_contention.cpp
index 26ccd8e605066..311d0c0666b34 100644
--- a/compiler-rt/lib/gwp_asan/tests/thread_contention.cpp
+++ b/compiler-rt/lib/gwp_asan/tests/thread_contention.cpp
@@ -15,6 +15,8 @@
 #include <thread>
 #include <vector>
 
+namespace {
+
 void asyncTask(gwp_asan::GuardedPoolAllocator *GPA,
                std::atomic<bool> *StartingGun, unsigned NumIterations) {
   while (!*StartingGun) {
@@ -63,3 +65,5 @@ TEST_F(CustomGuardedPoolAllocator, ThreadContention) {
   InitNumSlots(NumThreads);
   runThreadContentionTest(NumThreads, NumIterations, &GPA);
 }
+
+} // namespace

@frobtech frobtech merged commit 1f39435 into llvm:main Sep 8, 2025
14 checks passed
@frobtech frobtech deleted the p/gwp_asan-test-namespace branch September 8, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants