From b825c9784fd8079d1580802b1b68511d7f1b1b61 Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Mon, 7 Oct 2024 14:04:21 -0700 Subject: [PATCH 1/2] [rtsan][NFC] Refactor to scoped bypasser for Context --- compiler-rt/lib/rtsan/rtsan_assertions.h | 3 +-- compiler-rt/lib/rtsan/rtsan_context.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/rtsan/rtsan_assertions.h b/compiler-rt/lib/rtsan/rtsan_assertions.h index 1a653d198ab88..4646e750b6796 100644 --- a/compiler-rt/lib/rtsan/rtsan_assertions.h +++ b/compiler-rt/lib/rtsan/rtsan_assertions.h @@ -21,9 +21,8 @@ template 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 cb0c2eb0a5e0d..2d906259e1fe3 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 From a58aa86b7773e874c71e908de4597b8f5ccb4f81 Mon Sep 17 00:00:00 2001 From: Chris Apple Date: Mon, 7 Oct 2024 14:15:55 -0700 Subject: [PATCH 2/2] [PR] fmayer - delete other ctors, assignment ops --- compiler-rt/lib/rtsan/rtsan_context.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler-rt/lib/rtsan/rtsan_context.h b/compiler-rt/lib/rtsan/rtsan_context.h index 2d906259e1fe3..97fd9b48062ec 100644 --- a/compiler-rt/lib/rtsan/rtsan_context.h +++ b/compiler-rt/lib/rtsan/rtsan_context.h @@ -43,6 +43,11 @@ class ScopedBypass { ~ScopedBypass() { context_.BypassPop(); } + ScopedBypass(const ScopedBypass &) = delete; + ScopedBypass &operator=(const ScopedBypass &) = delete; + ScopedBypass(ScopedBypass &&) = delete; + ScopedBypass &operator=(ScopedBypass &&) = delete; + private: Context &context_; };