https://github.com/cjappl updated https://github.com/llvm/llvm-project/pull/107707
>From e3e211f65afbc923299c0f413d2c50c7b00884b6 Mon Sep 17 00:00:00 2001 From: Chris Apple <cja-priv...@pm.me> Date: Sat, 7 Sep 2024 08:38:06 -0700 Subject: [PATCH 1/3] [NFC][rtsan] Docs of how to disable rtsan --- clang/docs/RealtimeSanitizer.rst | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst index 799cd43509c6e6..7854cd3c0331a4 100644 --- a/clang/docs/RealtimeSanitizer.rst +++ b/clang/docs/RealtimeSanitizer.rst @@ -83,3 +83,53 @@ non-zero exit code. #13 0x00010230dd64 in main main.cpp:9 #14 0x0001958960dc (<unknown module>) #15 0x2f557ffffffffffc (<unknown module>) + +Disabling +--------- + +In some circumstances, you may want to suppress RealtimeSanitizer violations in a specific scope. + +In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer-reported violations are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively. + +.. code-block:: c++ + + #include <sanitizer/rtsan_interface.h> + + void process(const std::vector<float>& buffer) [[clang::nonblocking]] { + { + __rtsan::ScopedDisabler d; + ... + } + } + +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. + +In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks. + +.. code-block:: c++ + + #include <sanitizer/rtsan_interface.h> + + int process(const float* buffer) [[clang::nonblocking]] + { + { + __rtsan_disable(); + + ... + + __rtsan_enable(); + } + } + +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, undefined behavior may result, potentially leaving the sanitizer permanently disabled for the rest of the program's execution. + +Compile-time sanitizer detection +-------------------------------- + +Clang provides the pre-processor macro ``__has_feature`` which may be used to detect if RealtimeSanitizer is enabled at compile-time. + +.. code-block:: c++ + + #if defined(__has_feature) && __has_feature(realtime_sanitizer) + ... + #endif >From e6fe535a6453c8599c5325d12adeed48e39a2c65 Mon Sep 17 00:00:00 2001 From: Chris Apple <cja-priv...@pm.me> Date: Mon, 9 Sep 2024 12:51:11 -0700 Subject: [PATCH 2/3] [PR] david - better wording of what is suppressed --- clang/docs/RealtimeSanitizer.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst index 7854cd3c0331a4..b08bd30a83434f 100644 --- a/clang/docs/RealtimeSanitizer.rst +++ b/clang/docs/RealtimeSanitizer.rst @@ -87,9 +87,9 @@ non-zero exit code. Disabling --------- -In some circumstances, you may want to suppress RealtimeSanitizer violations in a specific scope. +In some circumstances, you may want to suppress error reporting in a specific scope. -In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer-reported violations are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively. +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. .. code-block:: c++ >From 84232e61c504c279eac7555a852e1d11d7253407 Mon Sep 17 00:00:00 2001 From: Chris Apple <cja-priv...@pm.me> Date: Mon, 9 Sep 2024 14:06:16 -0700 Subject: [PATCH 3/3] [PR] vitalybuka - leaving undefined behaviour ACTUALLY undefined --- clang/docs/RealtimeSanitizer.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst index b08bd30a83434f..5e281a2a357907 100644 --- a/clang/docs/RealtimeSanitizer.rst +++ b/clang/docs/RealtimeSanitizer.rst @@ -121,7 +121,7 @@ In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to } } -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, undefined behavior may result, potentially leaving the sanitizer permanently disabled for the rest of the program's execution. +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. Compile-time sanitizer detection -------------------------------- _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits