Skip to content

Conversation

frobtech
Copy link
Contributor

@frobtech frobtech commented Sep 6, 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 marked this pull request as ready for review September 6, 2025 00:09
@llvmbot
Copy link
Member

llvmbot commented Sep 6, 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/157207.diff

1 Files Affected:

  • (modified) compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp (+13-9)
diff --git a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
index 972c98d510a90..54d42edc374e5 100644
--- a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp
@@ -6,16 +6,18 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "tests/scudo_unit_test.h"
-
 #include "quarantine.h"
 
 #include <pthread.h>
 #include <stdlib.h>
 
-static void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);
-static const scudo::uptr BlockSize = 8UL;
-static const scudo::uptr LargeBlockSize = 16384UL;
+#include "tests/scudo_unit_test.h"
+
+namespace {
+
+void *FakePtr = reinterpret_cast<void *>(0xFA83FA83);
+const scudo::uptr BlockSize = 8UL;
+const scudo::uptr LargeBlockSize = 16384UL;
 
 struct QuarantineCallback {
   void recycle(void *P) { EXPECT_EQ(P, FakePtr); }
@@ -26,9 +28,9 @@ struct QuarantineCallback {
 typedef scudo::GlobalQuarantine<QuarantineCallback, void> QuarantineT;
 typedef typename QuarantineT::CacheT CacheT;
 
-static QuarantineCallback Cb;
+QuarantineCallback Cb;
 
-static void deallocateCache(CacheT *Cache) {
+void deallocateCache(CacheT *Cache) {
   while (scudo::QuarantineBatch *Batch = Cache->dequeueBatch())
     Cb.deallocate(Batch);
 }
@@ -187,8 +189,8 @@ TEST(ScudoQuarantineTest, QuarantineCacheMergeBatchesALotOfBatches) {
   deallocateCache(&ToDeallocate);
 }
 
-static const scudo::uptr MaxQuarantineSize = 1024UL << 10; // 1MB
-static const scudo::uptr MaxCacheSize = 256UL << 10;       // 256KB
+const scudo::uptr MaxQuarantineSize = 1024UL << 10; // 1MB
+const scudo::uptr MaxCacheSize = 256UL << 10;       // 256KB
 
 TEST(ScudoQuarantineTest, GlobalQuarantine) {
   QuarantineT Quarantine;
@@ -253,3 +255,5 @@ TEST(ScudoQuarantineTest, ThreadedGlobalQuarantine) {
   for (scudo::uptr I = 0; I < NumberOfThreads; I++)
     Quarantine.drainAndRecycle(&T[I].Cache, Cb);
 }
+
+} // namespace

@frobtech frobtech merged commit 8ddd804 into llvm:main Sep 8, 2025
15 checks passed
@frobtech frobtech deleted the p/scudo-test-namespace branch September 8, 2025 18:29
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.

4 participants