Skip to content

Commit 10d4306

Browse files
authored
[rtsan][NFC] Refactor to scoped bypasser for __rtsan::Context (#111438)
1 parent 00989f4 commit 10d4306

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

compiler-rt/lib/rtsan/rtsan_assertions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ template <typename OnViolationAction>
2121
void ExpectNotRealtime(Context &context, OnViolationAction &&OnViolation) {
2222
CHECK(__rtsan_is_initialized());
2323
if (context.InRealtimeContext() && !context.IsBypassed()) {
24-
context.BypassPush();
24+
ScopedBypass sb{context};
2525
OnViolation();
26-
context.BypassPop();
2726
}
2827
}
2928

compiler-rt/lib/rtsan/rtsan_context.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,22 @@ class Context {
3535
int bypass_depth_{0};
3636
};
3737

38+
class ScopedBypass {
39+
public:
40+
[[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) {
41+
context_.BypassPush();
42+
}
43+
44+
~ScopedBypass() { context_.BypassPop(); }
45+
46+
ScopedBypass(const ScopedBypass &) = delete;
47+
ScopedBypass &operator=(const ScopedBypass &) = delete;
48+
ScopedBypass(ScopedBypass &&) = delete;
49+
ScopedBypass &operator=(ScopedBypass &&) = delete;
50+
51+
private:
52+
Context &context_;
53+
};
54+
3855
Context &GetContextForThisThread();
3956
} // namespace __rtsan

0 commit comments

Comments
 (0)