Skip to content

Commit 60efbe9

Browse files
authored
[NFC][rtsan] Docs of how to disable rtsan (#107707)
1 parent 63d8bd2 commit 60efbe9

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

clang/docs/RealtimeSanitizer.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,53 @@ non-zero exit code.
8383
#13 0x00010230dd64 in main main.cpp:9
8484
#14 0x0001958960dc (<unknown module>)
8585
#15 0x2f557ffffffffffc (<unknown module>)
86+
87+
Disabling
88+
---------
89+
90+
In some circumstances, you may want to suppress error reporting in a specific scope.
91+
92+
In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively.
93+
94+
.. code-block:: c++
95+
96+
#include <sanitizer/rtsan_interface.h>
97+
98+
void process(const std::vector<float>& buffer) [[clang::nonblocking]] {
99+
{
100+
__rtsan::ScopedDisabler d;
101+
...
102+
}
103+
}
104+
105+
If RealtimeSanitizer is not enabled at compile time (i.e., the code is not compiled with the ``-fsanitize=realtime`` flag), the ``ScopedDisabler`` is compiled as a no-op.
106+
107+
In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks.
108+
109+
.. code-block:: c++
110+
111+
#include <sanitizer/rtsan_interface.h>
112+
113+
int process(const float* buffer) [[clang::nonblocking]]
114+
{
115+
{
116+
__rtsan_disable();
117+
118+
...
119+
120+
__rtsan_enable();
121+
}
122+
}
123+
124+
Each call to ``__rtsan_disable()`` must be paired with a subsequent call to ``__rtsan_enable()`` to restore normal sanitizer functionality. If a corresponding ``rtsan_enable()`` call is not made, the behavior is undefined.
125+
126+
Compile-time sanitizer detection
127+
--------------------------------
128+
129+
Clang provides the pre-processor macro ``__has_feature`` which may be used to detect if RealtimeSanitizer is enabled at compile-time.
130+
131+
.. code-block:: c++
132+
133+
#if defined(__has_feature) && __has_feature(realtime_sanitizer)
134+
...
135+
#endif

0 commit comments

Comments
 (0)