[compiler-rt] [scudo] Avoid deprecated-volatile warning in HybridMutex::delayLoop (PR #67135)

Fabio D'Urso via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 09:57:18 PDT 2023


https://github.com/fabio-d updated https://github.com/llvm/llvm-project/pull/67135

>From b6df00aebf63bd64bfa3923dca54717500fc4f8f Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <fdurso at google.com>
Date: Fri, 22 Sep 2023 15:10:40 +0200
Subject: [PATCH 1/2] [scudo] Avoid deprecated-volatile warning in
 HybridMutex::delayLoop

That can prevent compilation with -Werror and -std=c++20:
mutex.h:63:7: error: increment of object of volatile-qualified type 'volatile u32' (aka 'volatile unsigned int') is deprecated [-Werror,-Wdeprecated-volatile]
---
 compiler-rt/lib/scudo/standalone/mutex.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/mutex.h b/compiler-rt/lib/scudo/standalone/mutex.h
index 38108397b1654bb..1563cdb3fb109cb 100644
--- a/compiler-rt/lib/scudo/standalone/mutex.h
+++ b/compiler-rt/lib/scudo/standalone/mutex.h
@@ -58,9 +58,13 @@ class CAPABILITY("mutex") HybridMutex {
     // are the fastest operations) so that we are unlikely to wait too long for
     // fast operations.
     constexpr u32 SpinTimes = 16;
-    volatile u32 V = 0;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+    volatile u32 V;
     for (u32 I = 0; I < SpinTimes; ++I)
-      ++V;
+      V = 0;
+#pragma GCC diagnostic pop
   }
 
   void assertHeldImpl();

>From 619693914b1f07a248aa8c128ef00a4f59cdd9af Mon Sep 17 00:00:00 2001
From: Fabio D'Urso <fdurso at google.com>
Date: Fri, 22 Sep 2023 18:53:01 +0200
Subject: [PATCH 2/2] Incorporate feedback

---
 compiler-rt/lib/scudo/standalone/mutex.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/mutex.h b/compiler-rt/lib/scudo/standalone/mutex.h
index 1563cdb3fb109cb..4caa945219b5233 100644
--- a/compiler-rt/lib/scudo/standalone/mutex.h
+++ b/compiler-rt/lib/scudo/standalone/mutex.h
@@ -58,13 +58,11 @@ class CAPABILITY("mutex") HybridMutex {
     // are the fastest operations) so that we are unlikely to wait too long for
     // fast operations.
     constexpr u32 SpinTimes = 16;
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
-    volatile u32 V;
-    for (u32 I = 0; I < SpinTimes; ++I)
-      V = 0;
-#pragma GCC diagnostic pop
+    volatile u32 V = 0;
+    for (u32 I = 0; I < SpinTimes; ++I) {
+      u32 Tmp = V + 1;
+      V = Tmp;
+    }
   }
 
   void assertHeldImpl();



More information about the llvm-commits mailing list