[compiler-rt] 10d4306 - [rtsan][NFC] Refactor to scoped bypasser for __rtsan::Context (#111438)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 14:24:57 PDT 2024


Author: Chris Apple
Date: 2024-10-07T14:24:54-07:00
New Revision: 10d43061aa1c95facea397a900d9ce4f65fa03da

URL: https://github.com/llvm/llvm-project/commit/10d43061aa1c95facea397a900d9ce4f65fa03da
DIFF: https://github.com/llvm/llvm-project/commit/10d43061aa1c95facea397a900d9ce4f65fa03da.diff

LOG: [rtsan][NFC] Refactor to scoped bypasser for __rtsan::Context (#111438)

Added: 
    

Modified: 
    compiler-rt/lib/rtsan/rtsan_assertions.h
    compiler-rt/lib/rtsan/rtsan_context.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/rtsan/rtsan_assertions.h b/compiler-rt/lib/rtsan/rtsan_assertions.h
index 1a653d198ab88b..4646e750b6796e 100644
--- a/compiler-rt/lib/rtsan/rtsan_assertions.h
+++ b/compiler-rt/lib/rtsan/rtsan_assertions.h
@@ -21,9 +21,8 @@ template <typename OnViolationAction>
 void ExpectNotRealtime(Context &context, OnViolationAction &&OnViolation) {
   CHECK(__rtsan_is_initialized());
   if (context.InRealtimeContext() && !context.IsBypassed()) {
-    context.BypassPush();
+    ScopedBypass sb{context};
     OnViolation();
-    context.BypassPop();
   }
 }
 

diff  --git a/compiler-rt/lib/rtsan/rtsan_context.h b/compiler-rt/lib/rtsan/rtsan_context.h
index cb0c2eb0a5e0d7..97fd9b48062ece 100644
--- a/compiler-rt/lib/rtsan/rtsan_context.h
+++ b/compiler-rt/lib/rtsan/rtsan_context.h
@@ -35,5 +35,22 @@ class Context {
   int bypass_depth_{0};
 };
 
+class ScopedBypass {
+public:
+  [[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) {
+    context_.BypassPush();
+  }
+
+  ~ScopedBypass() { context_.BypassPop(); }
+
+  ScopedBypass(const ScopedBypass &) = delete;
+  ScopedBypass &operator=(const ScopedBypass &) = delete;
+  ScopedBypass(ScopedBypass &&) = delete;
+  ScopedBypass &operator=(ScopedBypass &&) = delete;
+
+private:
+  Context &context_;
+};
+
 Context &GetContextForThisThread();
 } // namespace __rtsan


        


More information about the llvm-commits mailing list