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

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 14:06:22 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Chris Apple (cjappl)

<details>
<summary>Changes</summary>

In an upcoming review, this code block in rtsan_assertions is going to get a lot messier.

Getting this in as a quick early refactor

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


2 Files Affected:

- (modified) compiler-rt/lib/rtsan/rtsan_assertions.h (+1-2) 
- (modified) compiler-rt/lib/rtsan/rtsan_context.h (+12) 


``````````diff
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..2d906259e1fe35 100644
--- a/compiler-rt/lib/rtsan/rtsan_context.h
+++ b/compiler-rt/lib/rtsan/rtsan_context.h
@@ -35,5 +35,17 @@ class Context {
   int bypass_depth_{0};
 };
 
+class ScopedBypass {
+public:
+  [[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) {
+    context_.BypassPush();
+  }
+
+  ~ScopedBypass() { context_.BypassPop(); }
+
+private:
+  Context &context_;
+};
+
 Context &GetContextForThisThread();
 } // namespace __rtsan

``````````

</details>


https://github.com/llvm/llvm-project/pull/111438


More information about the llvm-commits mailing list