[clang] [NFC][rtsan] Docs of how to disable rtsan (PR #107707)

2024-09-11 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/107707
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][rtsan] Docs of how to disable rtsan (PR #107707)

2024-09-09 Thread Chris Apple via cfe-commits

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 
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  ()
 #15 0x2f557ffc  ()
+
+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 
+
+void process(const std::vector& 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 
+
+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 
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 
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 
``__rts

[clang] [NFC][rtsan] Docs of how to disable rtsan (PR #107707)

2024-09-09 Thread Chris Apple via cfe-commits

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 
Date: Sat, 7 Sep 2024 08:38:06 -0700
Subject: [PATCH 1/2] [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  ()
 #15 0x2f557ffc  ()
+
+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 
+
+void process(const std::vector& 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 
+
+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 
Date: Mon, 9 Sep 2024 12:51:11 -0700
Subject: [PATCH 2/2] [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++
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][rtsan] Docs of how to disable rtsan (PR #107707)

2024-09-07 Thread Chris Apple via cfe-commits

cjappl wrote:

CC for review @davidtrevelyan 

https://github.com/llvm/llvm-project/pull/107707
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC][rtsan] Docs of how to disable rtsan (PR #107707)

2024-09-07 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/107707

None

>From e3e211f65afbc923299c0f413d2c50c7b00884b6 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Sat, 7 Sep 2024 08:38:06 -0700
Subject: [PATCH] [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  ()
 #15 0x2f557ffc  ()
+
+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 
+
+void process(const std::vector& 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 
+
+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

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-09-06 Thread Chris Apple via cfe-commits

cjappl wrote:

> My sense is that it would be weird for -Wall not to include 
> -Wfunction-effects, but that it would be OK for -Wfunction-effects not to be 
> enabled by default.

I do agree, it seems reasonable for it to be in `-Wall` or similar! That is 
absolutely what I'd expect as a user :)

> I do wonder, though, would it be that difficult to tell users to include 
> `-Wno-function-effects` with `-fsanitize=realtime` (or whatever it is)?

Yes, that is what we have been going with, telling users to disable this 
warning if they want the sanitizer without function effects. 

Our main concern is if users "missed" this advice of disabling function 
effects, they would think RTSan couldn't be run without fixing these 
compile-time warnings/errors, and people would be dissuaded from using the 
sanitizer. 

Our current thinking is it might (??) be clearer for both features to be opt-in 
via flag (-fsanitize=realtime needed to opt in to using RealtimeSanitizer, and 
-Wfunction-effects needed to opt in to using function effects) instead of one 
being opt-in and one being opt-out and being keyed off the same attribute.

I think the same question could also be asked in reversed -- would it be that 
difficult to tell users to enable -Wfunction-effects if they wanted the 
warnings? I think this gets to the root of our opt-in/opt-out differences. 
Where does the responsibility lie enabling these things? How are these features 
run separately, or together with minimal friction?

https://github.com/llvm/llvm-project/pull/99656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-06 Thread Chris Apple via cfe-commits


@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,

cjappl wrote:

But not merged yet, waiting for someone's eyes on it

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-06 Thread Chris Apple via cfe-commits


@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,

cjappl wrote:

https://github.com/llvm/llvm-project/pull/106650 That is done here, FYI

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-09-06 Thread Chris Apple via cfe-commits

cjappl wrote:

Hi @dougsonos 

We’re experiencing an unforeseen pain point trying to use rtsan without 
function effects, and wanted to ask **how you would feel about making function 
effect warnings opt-in rather than opt-out.** 

While users can easily opt in to function effects and not rtsan, the problem is 
that they can’t easily opt in to rtsan and not function effects. 

Here’s why: someone wanting to try out rtsan can add the `[[nonblocking]]` 
attribute, but this automatically opts them in to function effect warnings. For 
users who compile with `-Werror`, this means they will likely be unable to 
compile the code they wish to test with rtsan unless they explicitly turn off 
function effects warnings with -Wno-function-effects. If they’re not familiar 
with function effects they won’t know this, and we’re worried about an 
education gap causing them to blame rtsan and give up on it before realizing 
they can flick the function effects warnings off.

By disabling these warnings by default, both tools have the same "activation" 
of attribute + compile time flag, and it is equally easy to run either tool in 
isolation, or together.

https://github.com/llvm/llvm-project/pull/99656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-06 Thread Chris Apple via cfe-commits

cjappl wrote:

Weekly reviewer ping @vitalybuka @MaskRay @pcc 

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add realtime_sanitizer to Features.def (PR #106650)

2024-09-05 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited 
https://github.com/llvm/llvm-project/pull/106650
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add realtime_sanitizer to Features.def (PR #106650)

2024-09-05 Thread Chris Apple via cfe-commits

cjappl wrote:

Oh, also cc @davidtrevelyan 

https://github.com/llvm/llvm-project/pull/106650
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add realtime_sanitizer to Features.def (PR #106650)

2024-09-05 Thread Chris Apple via cfe-commits

cjappl wrote:

Weekly ping of reviewers - also added a couple more folks if they have time to 
take a look.

Current state: no reviews

https://github.com/llvm/llvm-project/pull/106650
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-03 Thread Chris Apple via cfe-commits

cjappl wrote:

Just saw the test failure, but it is unrelated:

```
_bk;t=1725300551284FAIL: lld :: ELF/avr-reloc.s (84796 of 87084)

_bk;t=1725300551284 TEST 'lld :: ELF/avr-reloc.s' FAILED 

```

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-02 Thread Chris Apple via cfe-commits


@@ -0,0 +1,117 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+void SANITIZER_CDECL __rtsan_enable(void);
+
+// Expect that the next call to a function with the given name will not be
+// called from a realtime context.
+void SANITIZER_CDECL
+__rtsan_expect_not_realtime(const char *intercepted_function_name);
+
+#ifdef __cplusplus
+} // extern "C"
+
+namespace __rtsan {
+#if (defined(__has_feature) && __has_feature(realtime_sanitizer)) ||   
\
+SANITIZE_REALTIME

cjappl wrote:

I reverted this after discussing with @davidtrevelyan , it is too confusing and 
has no precedent in the code so far. We can revisit later.

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-09-02 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/106736

>From c9d3d6c256b763bc99e7bf2d2dca43cb1e88adb8 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:16:37 -0700
Subject: [PATCH 1/6] [clang][rtsan] Add realtime sanitizer to Features.def

---
 clang/include/clang/Basic/Features.def  |  2 ++
 clang/test/Lexer/has_feature_realtime_sanitizer.cpp | 12 
 2 files changed, 14 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_realtime_sanitizer.cpp

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 10538f555b418e..7f5d26118bdc71 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,
+LangOpts.Sanitize.has(SanitizerKind::Realtime))
 FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
diff --git a/clang/test/Lexer/has_feature_realtime_sanitizer.cpp 
b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
new file mode 100644
index 00..76febeb6473a4b
--- /dev/null
+++ b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -fsanitize=realtime %s -o - | FileCheck 
--check-prefix=CHECK-RTSAN %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-RTSAN %s
+
+#if __has_feature(realtime_sanitizer)
+int RealtimeSanitizerEnabled();
+#else
+int RealtimeSanitizerDisabled();
+#endif
+
+// CHECK-RTSAN: RealtimeSanitizerEnabled
+
+// CHECK-NO-RTSAN: RealtimeSanitizerDisabled

>From 3d1598edfde8b349bb65d9f132fdfdae988a4aa5 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:17:12 -0700
Subject: [PATCH 2/6] [compiler-rt][rtsan] Introduce rtsan_interface.h and
 ScopedDisabler

---
 compiler-rt/include/CMakeLists.txt|   1 +
 .../include/sanitizer/rtsan_interface.h   | 115 ++
 compiler-rt/lib/rtsan/rtsan.h |  20 +--
 compiler-rt/test/rtsan/disabler.cpp   |  35 ++
 compiler-rt/test/rtsan/enabler.cpp|  35 ++
 5 files changed, 192 insertions(+), 14 deletions(-)
 create mode 100644 compiler-rt/include/sanitizer/rtsan_interface.h
 create mode 100644 compiler-rt/test/rtsan/disabler.cpp
 create mode 100644 compiler-rt/test/rtsan/enabler.cpp

diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index d598a94ee2e237..242d62b9b447b1 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -10,6 +10,7 @@ if (COMPILER_RT_BUILD_SANITIZERS)
 sanitizer/lsan_interface.h
 sanitizer/msan_interface.h
 sanitizer/netbsd_syscall_hooks.h
+sanitizer/rtsan_interface.h
 sanitizer/scudo_interface.h
 sanitizer/tsan_interface.h
 sanitizer/tsan_interface_atomic.h
diff --git a/compiler-rt/include/sanitizer/rtsan_interface.h 
b/compiler-rt/include/sanitizer/rtsan_interface.h
new file mode 100644
index 00..399cbfd294dacd
--- /dev/null
+++ b/compiler-rt/include/sanitizer/rtsan_interface.h
@@ -0,0 +1,115 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+

[clang] [compiler-rt] [llvm] [CMake][compiler-rt] Support for using compiler-rt atomic library (PR #106603)

2024-08-30 Thread Chris Apple via cfe-commits

cjappl wrote:

> but it'd be better if we handled atomic CAS spinlocks as well since we would 
> like to avoid the pthread dependency if possible.

Agreed, I have something in the works for this but it is a little ways off. 
(catching these unbound loops is a bit tricky)

My recommendation to make it work when using the builtins would be just 
extracting this test to another test, then #ifdefing it out in the situation 
where we are not using pthread

https://github.com/llvm/llvm-project/pull/106603
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake][compiler-rt] Support for using compiler-rt atomic library (PR #106603)

2024-08-30 Thread Chris Apple via cfe-commits

cjappl wrote:

Ok, it appears that on Apple systems, we would catch this, as we intercept 
OSSpinLockLock used by compiler-rt atomics:

https://github.com/llvm/llvm-project/blob/c55e24b8507d47a8cc04b5d9570e8e3d02be1ca3/compiler-rt/lib/builtins/atomic.c#L95-L102

But, in the non-darwin case this is an atomic CAS spinlock, which we do not 
intercept (but we are trying to figure out how to catch potentially unbound 
loops like this):

https://github.com/llvm/llvm-project/blob/c55e24b8507d47a8cc04b5d9570e8e3d02be1ca3/compiler-rt/lib/builtins/atomic.c#L112-L119

Would you please confirm that you end up in this area of atomic.c when you run 
this test? If so, I think it is adequate to #ifdef out this test under the 
circumstances that it is 
1. Compiling with the builtin atomics
2. Not on darwin

https://github.com/llvm/llvm-project/blob/d58d105cdaf366d7db3f60d356b21bc8e64666fb/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp#L164-L171

Or if you're feeling ambitious, you could pull this little bit into a new test 
and ifdef out that, might be cleaner.

Let me know if I can be of any assistance with any of this. 

https://github.com/llvm/llvm-project/pull/106603
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits


@@ -0,0 +1,117 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+void SANITIZER_CDECL __rtsan_enable(void);
+
+// Expect that the next call to a function with the given name will not be
+// called from a realtime context.
+void SANITIZER_CDECL
+__rtsan_expect_not_realtime(const char *intercepted_function_name);
+
+#ifdef __cplusplus
+} // extern "C"
+
+namespace __rtsan {
+#if (defined(__has_feature) && __has_feature(realtime_sanitizer)) ||   
\
+SANITIZE_REALTIME

cjappl wrote:

Envisioned use case:

```cpp
#define SANITIZE_REALTIME (MY_CUSTOM_RTSAN_ENABLED)
#include 

void main() {
  __rtsan::Initialize();
  ...
}

void process() {
  __rtsan::ScopedEnabler rtsan{};

  auto x = std::make_unique(3.0f);
}

```

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits


@@ -0,0 +1,117 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+void SANITIZER_CDECL __rtsan_enable(void);
+
+// Expect that the next call to a function with the given name will not be
+// called from a realtime context.
+void SANITIZER_CDECL
+__rtsan_expect_not_realtime(const char *intercepted_function_name);
+
+#ifdef __cplusplus
+} // extern "C"
+
+namespace __rtsan {
+#if (defined(__has_feature) && __has_feature(realtime_sanitizer)) ||   
\
+SANITIZE_REALTIME

cjappl wrote:

What do we think about this SANITIZE_REALTIME macro? 

It was my thought that someone who didn't have the latest clang could still use 
these classes if they linked the runtime and did:

```
#define RTSAN_ENABLED true
#include 
```

I know people will want to use the realtime sanitizer with other compilers, 
especially AppleClang and gcc.

Does the name of this define make sense? should it be __RTSAN_ENABLED, 
__SANITIZE_REALTIME? Is there a better name for it?

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits

https://github.com/cjappl deleted 
https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/106736

>From c9d3d6c256b763bc99e7bf2d2dca43cb1e88adb8 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:16:37 -0700
Subject: [PATCH 1/4] [clang][rtsan] Add realtime sanitizer to Features.def

---
 clang/include/clang/Basic/Features.def  |  2 ++
 clang/test/Lexer/has_feature_realtime_sanitizer.cpp | 12 
 2 files changed, 14 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_realtime_sanitizer.cpp

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 10538f555b418e..7f5d26118bdc71 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,
+LangOpts.Sanitize.has(SanitizerKind::Realtime))
 FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
diff --git a/clang/test/Lexer/has_feature_realtime_sanitizer.cpp 
b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
new file mode 100644
index 00..76febeb6473a4b
--- /dev/null
+++ b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -fsanitize=realtime %s -o - | FileCheck 
--check-prefix=CHECK-RTSAN %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-RTSAN %s
+
+#if __has_feature(realtime_sanitizer)
+int RealtimeSanitizerEnabled();
+#else
+int RealtimeSanitizerDisabled();
+#endif
+
+// CHECK-RTSAN: RealtimeSanitizerEnabled
+
+// CHECK-NO-RTSAN: RealtimeSanitizerDisabled

>From 3d1598edfde8b349bb65d9f132fdfdae988a4aa5 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:17:12 -0700
Subject: [PATCH 2/4] [compiler-rt][rtsan] Introduce rtsan_interface.h and
 ScopedDisabler

---
 compiler-rt/include/CMakeLists.txt|   1 +
 .../include/sanitizer/rtsan_interface.h   | 115 ++
 compiler-rt/lib/rtsan/rtsan.h |  20 +--
 compiler-rt/test/rtsan/disabler.cpp   |  35 ++
 compiler-rt/test/rtsan/enabler.cpp|  35 ++
 5 files changed, 192 insertions(+), 14 deletions(-)
 create mode 100644 compiler-rt/include/sanitizer/rtsan_interface.h
 create mode 100644 compiler-rt/test/rtsan/disabler.cpp
 create mode 100644 compiler-rt/test/rtsan/enabler.cpp

diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index d598a94ee2e237..242d62b9b447b1 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -10,6 +10,7 @@ if (COMPILER_RT_BUILD_SANITIZERS)
 sanitizer/lsan_interface.h
 sanitizer/msan_interface.h
 sanitizer/netbsd_syscall_hooks.h
+sanitizer/rtsan_interface.h
 sanitizer/scudo_interface.h
 sanitizer/tsan_interface.h
 sanitizer/tsan_interface_atomic.h
diff --git a/compiler-rt/include/sanitizer/rtsan_interface.h 
b/compiler-rt/include/sanitizer/rtsan_interface.h
new file mode 100644
index 00..399cbfd294dacd
--- /dev/null
+++ b/compiler-rt/include/sanitizer/rtsan_interface.h
@@ -0,0 +1,115 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+

[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits


@@ -0,0 +1,117 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+void SANITIZER_CDECL __rtsan_enable(void);
+
+// Expect that the next call to a function with the given name will not be
+// called from a realtime context.
+void SANITIZER_CDECL
+__rtsan_expect_not_realtime(const char *intercepted_function_name);
+
+#ifdef __cplusplus
+} // extern "C"
+
+namespace __rtsan {
+#if (defined(__has_feature) && __has_feature(realtime_sanitizer)) ||   
\
+defined(RTSAN_ENABLED)

cjappl wrote:

What do we think about this RTSAN_ENABLED? 

It was my thought that someone who didn't have the latest clang could still use 
these classes if they linked the runtime and did:

```
#define RTSAN_ENABLED true
#include 
```

I know people will want to use the realtime sanitizer with other compilers, 
especially AppleClang and gcc.

Does the name of this define make sense? should it be __RTSAN_ENABLED? Is there 
a better name for it?

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/106736

>From c9d3d6c256b763bc99e7bf2d2dca43cb1e88adb8 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:16:37 -0700
Subject: [PATCH 1/3] [clang][rtsan] Add realtime sanitizer to Features.def

---
 clang/include/clang/Basic/Features.def  |  2 ++
 clang/test/Lexer/has_feature_realtime_sanitizer.cpp | 12 
 2 files changed, 14 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_realtime_sanitizer.cpp

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 10538f555b418e..7f5d26118bdc71 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,
+LangOpts.Sanitize.has(SanitizerKind::Realtime))
 FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
diff --git a/clang/test/Lexer/has_feature_realtime_sanitizer.cpp 
b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
new file mode 100644
index 00..76febeb6473a4b
--- /dev/null
+++ b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -fsanitize=realtime %s -o - | FileCheck 
--check-prefix=CHECK-RTSAN %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-RTSAN %s
+
+#if __has_feature(realtime_sanitizer)
+int RealtimeSanitizerEnabled();
+#else
+int RealtimeSanitizerDisabled();
+#endif
+
+// CHECK-RTSAN: RealtimeSanitizerEnabled
+
+// CHECK-NO-RTSAN: RealtimeSanitizerDisabled

>From 3d1598edfde8b349bb65d9f132fdfdae988a4aa5 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:17:12 -0700
Subject: [PATCH 2/3] [compiler-rt][rtsan] Introduce rtsan_interface.h and
 ScopedDisabler

---
 compiler-rt/include/CMakeLists.txt|   1 +
 .../include/sanitizer/rtsan_interface.h   | 115 ++
 compiler-rt/lib/rtsan/rtsan.h |  20 +--
 compiler-rt/test/rtsan/disabler.cpp   |  35 ++
 compiler-rt/test/rtsan/enabler.cpp|  35 ++
 5 files changed, 192 insertions(+), 14 deletions(-)
 create mode 100644 compiler-rt/include/sanitizer/rtsan_interface.h
 create mode 100644 compiler-rt/test/rtsan/disabler.cpp
 create mode 100644 compiler-rt/test/rtsan/enabler.cpp

diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index d598a94ee2e237..242d62b9b447b1 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -10,6 +10,7 @@ if (COMPILER_RT_BUILD_SANITIZERS)
 sanitizer/lsan_interface.h
 sanitizer/msan_interface.h
 sanitizer/netbsd_syscall_hooks.h
+sanitizer/rtsan_interface.h
 sanitizer/scudo_interface.h
 sanitizer/tsan_interface.h
 sanitizer/tsan_interface_atomic.h
diff --git a/compiler-rt/include/sanitizer/rtsan_interface.h 
b/compiler-rt/include/sanitizer/rtsan_interface.h
new file mode 100644
index 00..399cbfd294dacd
--- /dev/null
+++ b/compiler-rt/include/sanitizer/rtsan_interface.h
@@ -0,0 +1,115 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls to this method are injected at the code
+// generation stage when RTSan is enabled.
+void SANITIZER_CDECL __rtsan_realtime_enter();
+
+// Exit the real-time context.
+// When not in a real-time context, RTSan interceptors will simply forward
+// intercepted method calls to the real methods.
+void SANITIZER_CDECL __rtsan_realtime_exit();
+
+// Disable all RTSan error reporting.
+void SANITIZER_CDECL __rtsan_disable(void);
+
+// Re-enable all RTSan error reporting.
+// The counterpart to `__rtsan_disable`.
+

[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits

cjappl wrote:

CC @davidtrevelyan for review

https://github.com/llvm/llvm-project/pull/106736
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt][rtsan] Introduce rtsan_interface.h and ScopedDisabler (PR #106736)

2024-08-30 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/106736

Follows #106650 - that's why that change is in this PR, that will disappear 
when that is approved and merged.


To disable rtsan, we are following the same approach as lsan: 
https://github.com/llvm/llvm-project/blob/c792de28dfaf3a13703e83e4eb09dd44574b3a3e/compiler-rt/include/sanitizer/lsan_interface.h#L80-L87

We needed to do a little groundwork to:
- Expose the rtsan_interface.h file, which didn't exist before
- Hide this behind a `#if defined(__has_feature) && 
__has_feature(realtime_sanitizer)` 



>From c9d3d6c256b763bc99e7bf2d2dca43cb1e88adb8 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:16:37 -0700
Subject: [PATCH 1/2] [clang][rtsan] Add realtime sanitizer to Features.def

---
 clang/include/clang/Basic/Features.def  |  2 ++
 clang/test/Lexer/has_feature_realtime_sanitizer.cpp | 12 
 2 files changed, 14 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_realtime_sanitizer.cpp

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 10538f555b418e..7f5d26118bdc71 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,
+LangOpts.Sanitize.has(SanitizerKind::Realtime))
 FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
diff --git a/clang/test/Lexer/has_feature_realtime_sanitizer.cpp 
b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
new file mode 100644
index 00..76febeb6473a4b
--- /dev/null
+++ b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -fsanitize=realtime %s -o - | FileCheck 
--check-prefix=CHECK-RTSAN %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-RTSAN %s
+
+#if __has_feature(realtime_sanitizer)
+int RealtimeSanitizerEnabled();
+#else
+int RealtimeSanitizerDisabled();
+#endif
+
+// CHECK-RTSAN: RealtimeSanitizerEnabled
+
+// CHECK-NO-RTSAN: RealtimeSanitizerDisabled

>From 3d1598edfde8b349bb65d9f132fdfdae988a4aa5 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:17:12 -0700
Subject: [PATCH 2/2] [compiler-rt][rtsan] Introduce rtsan_interface.h and
 ScopedDisabler

---
 compiler-rt/include/CMakeLists.txt|   1 +
 .../include/sanitizer/rtsan_interface.h   | 115 ++
 compiler-rt/lib/rtsan/rtsan.h |  20 +--
 compiler-rt/test/rtsan/disabler.cpp   |  35 ++
 compiler-rt/test/rtsan/enabler.cpp|  35 ++
 5 files changed, 192 insertions(+), 14 deletions(-)
 create mode 100644 compiler-rt/include/sanitizer/rtsan_interface.h
 create mode 100644 compiler-rt/test/rtsan/disabler.cpp
 create mode 100644 compiler-rt/test/rtsan/enabler.cpp

diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index d598a94ee2e237..242d62b9b447b1 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -10,6 +10,7 @@ if (COMPILER_RT_BUILD_SANITIZERS)
 sanitizer/lsan_interface.h
 sanitizer/msan_interface.h
 sanitizer/netbsd_syscall_hooks.h
+sanitizer/rtsan_interface.h
 sanitizer/scudo_interface.h
 sanitizer/tsan_interface.h
 sanitizer/tsan_interface_atomic.h
diff --git a/compiler-rt/include/sanitizer/rtsan_interface.h 
b/compiler-rt/include/sanitizer/rtsan_interface.h
new file mode 100644
index 00..399cbfd294dacd
--- /dev/null
+++ b/compiler-rt/include/sanitizer/rtsan_interface.h
@@ -0,0 +1,115 @@
+//===-- sanitizer/rtsan_interface.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file is a part of RealtimeSanitizer.
+//
+// Public interface header.
+//===--===//
+
+#ifndef SANITIZER_RTSAN_INTERFACE_H
+#define SANITIZER_RTSAN_INTERFACE_H
+
+#if __has_include()
+#include 
+#else
+#define SANITIZER_CDECL
+#endif // __has_include()
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// Initializes rtsan if it has not been initialized yet.
+// Used by the RTSan runtime to ensure that rtsan is initialized before any
+// other rtsan functions are called.
+void SANITIZER_CDECL __rtsan_ensure_initialized();
+
+// Enter real-time context.
+// When in a real-time context, RTSan interceptors will error if realtime
+// violations are detected. Calls t

[clang] [compiler-rt] [llvm] [CMake][compiler-rt] Support for using compiler-rt atomic library (PR #106603)

2024-08-30 Thread Chris Apple via cfe-commits

cjappl wrote:

> I'm seeing a test failure but I'm not sure if it's an issue with RTSan or 
> compiler-rt atomic implementation:

Interesting, so that test basically tests that large atomics that insert locks 
under the hood die as expected. Zooming in on the second part of the test:


```
std::atomic> large_atomic;
  ASSERT_FALSE(large_atomic.is_lock_free()); / HERE IS INTERESTING!
  auto Func = [&]() {
std::array x = large_atomic.load();
return x;
  };
  ExpectRealtimeDeath(Func);
  ExpectNonRealtimeSurvival(Func);

```

It seems like the compiler-rt version says it is lock free, but then we aren't 
dying. Does it take another lock, different from a pthread_mutex_lock? Those 
are the locks we look for in our implementation.

https://github.com/llvm/llvm-project/pull/106603
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Add realtime_sanitizer to Features.def (PR #106650)

2024-08-29 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/106650

None

>From 4af0857bd8f2cb332a1ee7b359002ed6522d1aa8 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 29 Aug 2024 17:16:37 -0700
Subject: [PATCH] [clang][rtsan] Add realtime sanitizer to Features.def

---
 clang/include/clang/Basic/Features.def  |  2 ++
 clang/test/Lexer/has_feature_realtime_sanitizer.cpp | 12 
 2 files changed, 14 insertions(+)
 create mode 100644 clang/test/Lexer/has_feature_realtime_sanitizer.cpp

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 10538f555b418e..7f5d26118bdc71 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -54,6 +54,8 @@ FEATURE(memtag_globals,
 FEATURE(xray_instrument, LangOpts.XRayInstrument)
 FEATURE(undefined_behavior_sanitizer,
 LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(realtime_sanitizer,
+LangOpts.Sanitize.has(SanitizerKind::Realtime))
 FEATURE(coverage_sanitizer, LangOpts.SanitizeCoverage)
 FEATURE(assume_nonnull, true)
 FEATURE(attribute_analyzer_noreturn, true)
diff --git a/clang/test/Lexer/has_feature_realtime_sanitizer.cpp 
b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
new file mode 100644
index 00..76febeb6473a4b
--- /dev/null
+++ b/clang/test/Lexer/has_feature_realtime_sanitizer.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -fsanitize=realtime %s -o - | FileCheck 
--check-prefix=CHECK-RTSAN %s
+// RUN: %clang_cc1 -E  %s -o - | FileCheck --check-prefix=CHECK-NO-RTSAN %s
+
+#if __has_feature(realtime_sanitizer)
+int RealtimeSanitizerEnabled();
+#else
+int RealtimeSanitizerDisabled();
+#endif
+
+// CHECK-RTSAN: RealtimeSanitizerEnabled
+
+// CHECK-NO-RTSAN: RealtimeSanitizerDisabled

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [CMake][compiler-rt] Support for using compiler-rt atomic library (PR #106603)

2024-08-29 Thread Chris Apple via cfe-commits

https://github.com/cjappl approved this pull request.

Seems reasonable to me, I would wait for other approvals, as I'm relatively new 
here.

Just ensure this is good to go with rtsan, I recommend running the tests 
locally, as I don't think they're a part of the default pre-commit set
```
ninja check-rtsan
```

https://github.com/llvm/llvm-project/pull/106603
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-23 Thread Chris Apple via cfe-commits

cjappl wrote:

Relanded as f77e8f765e42

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Reland realtime sanitizer codegen and driver (#102622) (PR #105841)

2024-08-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/105841
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Reland realtime sanitizer codegen and driver (#102622) (PR #105841)

2024-08-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/105841

This reverts commit a1e9b7e646b76bf844e8a9a101ebd27de11992ff
This relands commit d010ec6af8162a8ae4e42d2cac5282f83db0ce07

No modifications from the original patch. It was determined that the ubsan 
build failure was happening even after the revert, some examples:

https://lab.llvm.org/buildbot/#/builders/159/builds/4477 
https://lab.llvm.org/buildbot/#/builders/159/builds/4478 
https://lab.llvm.org/buildbot/#/builders/159/builds/4479

>From 3b78b5725a0d54274c0e6ea0a623c8bc586df745 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 22 Aug 2024 20:38:14 -0700
Subject: [PATCH] Reland "[clang][rtsan] Introduce realtime sanitizer codegen
 and driver (#105744)

Review in #102622

This reverts commit a1e9b7e646b76bf844e8a9a101ebd27de11992ff.

It was determined that the ubsan build failure was happening even after the
revert, some examples:

https://lab.llvm.org/buildbot/#/builders/159/builds/4477
https://lab.llvm.org/buildbot/#/builders/159/builds/4478
https://lab.llvm.org/buildbot/#/builders/159/builds/4479
---
 clang/docs/RealtimeSanitizer.rst  | 85 +++
 clang/docs/ReleaseNotes.rst   |  5 ++
 clang/docs/UsersManual.rst|  2 +
 clang/docs/index.rst  |  1 +
 clang/include/clang/Basic/Sanitizers.def  |  3 +
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  7 ++
 clang/lib/Driver/SanitizerArgs.cpp| 14 +--
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 ++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 ++
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 ++
 .../test/CodeGen/rtsan_entry_exit_insertion.c | 13 +++
 .../rtsan_no_attribute_sanitizer_disabled.c   |  6 ++
 clang/test/Driver/fsanitize.c | 46 ++
 16 files changed, 208 insertions(+), 5 deletions(-)
 create mode 100644 clang/docs/RealtimeSanitizer.rst
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_entry_exit_insertion.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c

diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst
new file mode 100644
index 00..799cd43509c6e6
--- /dev/null
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -0,0 +1,85 @@
+=
+RealtimeSanitizer
+=
+
+.. contents::
+   :local:
+
+Introduction
+
+RealtimeSanitizer (a.k.a. RTSan) is a real-time safety testing tool for C and 
C++
+projects. RTSan can be used to detect real-time violations, i.e. calls to 
methods
+that are not safe for use in functions with deterministic runtime requirements.
+RTSan considers any function marked with the ``[[clang::nonblocking]]`` 
attribute
+to be a real-time function. If RTSan detects a call to ``malloc``, ``free``,
+``pthread_mutex_lock``, or anything else that could have a non-deterministic
+execution time in a function marked ``[[clang::nonblocking]]``
+RTSan raises an error.
+
+The runtime slowdown introduced by RealtimeSanitizer is negligible.
+
+How to build
+
+
+Build LLVM/Clang with `CMake ` and enable the
+``compiler-rt`` runtime. An example CMake configuration that will allow for the
+use/testing of RealtimeSanitizer:
+
+.. code-block:: console
+
+   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
+
+Usage
+=
+
+There are two requirements:
+
+1. The code must be compiled with the ``-fsanitize=realtime`` flag.
+2. Functions that are subject to real-time constraints must be marked
+   with the ``[[clang::nonblocking]]`` attribute.
+
+Typically, these attributes should be added onto the functions that are entry
+points for threads with real-time priority. These threads are subject to a 
fixed
+callback time, such as audio callback threads or rendering loops in video game
+code.
+
+.. code-block:: console
+
+   % cat example_realtime_violation.cpp
+   #include 
+
+   void violation() [[clang::nonblocking]]{
+ std::vector v;
+ v.resize(100);
+   }
+
+   int main() {
+ violation();
+ return 0;
+   }
+   # Compile and link
+   % clang++ -fsanitize=realtime -g example_realtime_violation.cpp
+
+If a real-time safety violation is detected in a ``[[clang::nonblocking]]``
+context, or any function invoked by that function, the program will exit with a
+non-zero exit code.
+
+.. code-block:: console
+
+   % clang++ -fsanitize=realtime -g example_realtime_violation.cpp
+   % ./a.out
+   Real-time violation: intercepted call to real-time unsafe function `malloc` 
in real-time context! Stack trace:
+#0 0x000102893034 in __rtsan::PrintStackTrace() rtsan_stack.cpp:45
+#1 0x000102892

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

At least 3 more failures in this way since this reversion:
https://lab.llvm.org/buildbot/#/builders/159/builds/4477
https://lab.llvm.org/buildbot/#/builders/159/builds/4478
https://lab.llvm.org/buildbot/#/builders/159/builds/4479


I am going to re-land this tomorrow when I wake up

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

Thanks for taking a look @Sirraide , greatly appreciated.

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

Tests continue to fail after reverting this: 
https://lab.llvm.org/buildbot/#/builders/159/builds/4474

I am trying to bisect locally, I will likely reland this with no modifications 
tomorrow if it continues to look like this did not contribute to the build 
failures. 

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

Out of an abundance of caution I have reverted this. I am still unsure of what 
in my code could have caused this failure.

 If anyone out there has a bright idea please let me know. I will monitor the 
builds for a bit and ensure they are back to green

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang][rtsan] Introduce realtime sanitizer codegen and drive… (PR #105744)

2024-08-22 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/105744
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[clang][rtsan] Introduce realtime sanitizer codegen and drive… (PR #105744)

2024-08-22 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/105744

…r (#102622)"

This reverts commit d010ec6af8162a8ae4e42d2cac5282f83db0ce07.

Build failure: https://lab.llvm.org/buildbot/#/builders/159/builds/4466

>From b663988416adf8be4188c10521db585c234763a0 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 22 Aug 2024 14:42:22 -0700
Subject: [PATCH] Revert "[clang][rtsan] Introduce realtime sanitizer codegen
 and driver (#102622)"

This reverts commit d010ec6af8162a8ae4e42d2cac5282f83db0ce07.

Build failure: https://lab.llvm.org/buildbot/#/builders/159/builds/4466
---
 clang/docs/RealtimeSanitizer.rst  | 85 ---
 clang/docs/ReleaseNotes.rst   |  5 --
 clang/docs/UsersManual.rst|  2 -
 clang/docs/index.rst  |  1 -
 clang/include/clang/Basic/Sanitizers.def  |  3 -
 clang/include/clang/Driver/SanitizerArgs.h|  1 -
 clang/lib/CodeGen/BackendUtil.cpp |  8 --
 clang/lib/CodeGen/CodeGenFunction.cpp |  7 --
 clang/lib/Driver/SanitizerArgs.cpp| 14 ++-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 --
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 --
 clang/lib/Driver/ToolChains/Linux.cpp |  1 -
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 --
 .../test/CodeGen/rtsan_entry_exit_insertion.c | 13 ---
 .../rtsan_no_attribute_sanitizer_disabled.c   |  6 --
 clang/test/Driver/fsanitize.c | 46 --
 16 files changed, 5 insertions(+), 208 deletions(-)
 delete mode 100644 clang/docs/RealtimeSanitizer.rst
 delete mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 delete mode 100644 clang/test/CodeGen/rtsan_entry_exit_insertion.c
 delete mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c

diff --git a/clang/docs/RealtimeSanitizer.rst b/clang/docs/RealtimeSanitizer.rst
deleted file mode 100644
index 799cd43509c6e6..00
--- a/clang/docs/RealtimeSanitizer.rst
+++ /dev/null
@@ -1,85 +0,0 @@
-=
-RealtimeSanitizer
-=
-
-.. contents::
-   :local:
-
-Introduction
-
-RealtimeSanitizer (a.k.a. RTSan) is a real-time safety testing tool for C and 
C++
-projects. RTSan can be used to detect real-time violations, i.e. calls to 
methods
-that are not safe for use in functions with deterministic runtime requirements.
-RTSan considers any function marked with the ``[[clang::nonblocking]]`` 
attribute
-to be a real-time function. If RTSan detects a call to ``malloc``, ``free``,
-``pthread_mutex_lock``, or anything else that could have a non-deterministic
-execution time in a function marked ``[[clang::nonblocking]]``
-RTSan raises an error.
-
-The runtime slowdown introduced by RealtimeSanitizer is negligible.
-
-How to build
-
-
-Build LLVM/Clang with `CMake ` and enable the
-``compiler-rt`` runtime. An example CMake configuration that will allow for the
-use/testing of RealtimeSanitizer:
-
-.. code-block:: console
-
-   $ cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" 
-DLLVM_ENABLE_RUNTIMES="compiler-rt" /llvm
-
-Usage
-=
-
-There are two requirements:
-
-1. The code must be compiled with the ``-fsanitize=realtime`` flag.
-2. Functions that are subject to real-time constraints must be marked
-   with the ``[[clang::nonblocking]]`` attribute.
-
-Typically, these attributes should be added onto the functions that are entry
-points for threads with real-time priority. These threads are subject to a 
fixed
-callback time, such as audio callback threads or rendering loops in video game
-code.
-
-.. code-block:: console
-
-   % cat example_realtime_violation.cpp
-   #include 
-
-   void violation() [[clang::nonblocking]]{
- std::vector v;
- v.resize(100);
-   }
-
-   int main() {
- violation();
- return 0;
-   }
-   # Compile and link
-   % clang++ -fsanitize=realtime -g example_realtime_violation.cpp
-
-If a real-time safety violation is detected in a ``[[clang::nonblocking]]``
-context, or any function invoked by that function, the program will exit with a
-non-zero exit code.
-
-.. code-block:: console
-
-   % clang++ -fsanitize=realtime -g example_realtime_violation.cpp
-   % ./a.out
-   Real-time violation: intercepted call to real-time unsafe function `malloc` 
in real-time context! Stack trace:
-#0 0x000102893034 in __rtsan::PrintStackTrace() rtsan_stack.cpp:45
-#1 0x000102892e64 in __rtsan::Context::ExpectNotRealtime(char const*) 
rtsan_context.cpp:78
-#2 0x00010289397c in malloc rtsan_interceptors.cpp:286
-#3 0x000195bd7bd0 in operator new(unsigned long)+0x1c 
(libc++abi.dylib:arm64+0x16bd0)
-#4 0x5c7f00010230f07c  ()
-#5 0x00010230f058 in std::__1::__libcpp_allocate[abi:ue170006](unsigned 
long, unsigned long) new:324
-#6 0x00010230effc in 
std::__1::allocator::allocate[abi:ue170006](unsigned long) 
allocator.h:114
-... snip ...
-#10 0x00

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

So it's happening in a pass away from the Realtime sanitizer pass, the top of 
the stack says:

```
3.  Running pass 'Function Pass Manager' on module 
'/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp'.
4.  Running pass 'AArch64 Instruction Selection' on function 
'@_ZL12decorate_msgPcm'
 #0 0xb8be034b8d04 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/b/sanitizer-aarch64-linux-fuzzer/build/llvm_build0/./bin/clang+++0x6118d04)
```

I'm not sure how this change would have affected the AArch64 Instruction 
Selection pass, still investigating.

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

cjappl wrote:

(investigating this issue right now, I'm unfamiliar with the fuzzer, so I'm 
trying to figure out if this is my failure or not. Will keep people posted)

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-22 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-19 Thread Chris Apple via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S 
-emit-llvm -o - | FileCheck %s

cjappl wrote:

Got rid of this test completely, thanks for the help understanding all this. 
I'll mark this as resolved

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-19 Thread Chris Apple via cfe-commits


@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsanitize=realtime 
-emit-llvm -o - %s | FileCheck %s

cjappl wrote:

Fixed all of your latest round in the latest commit

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-19 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/6] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-19 Thread Chris Apple via cfe-commits

cjappl wrote:

Weekly ping of outstanding reviewers @Sirraide @cor3ntin @AaronBallman and 
@dougsonos.

Thanks in advance for any feedback/approvals before this goes in!

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-18 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited 
https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-18 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/5] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-18 Thread Chris Apple via cfe-commits


@@ -995,6 +996,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(

cjappl wrote:

Thanks Vitaly! Helpful explanation 

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-18 Thread Chris Apple via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S 
-emit-llvm -o - | FileCheck %s

cjappl wrote:

The basis of this test file were very similar ones for asan and tsan:
https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/tsan.c
https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/asan.c

So I thought it was required for rtsan as well! Do you recommend I delete this 
test, or move it elsewhere? I defer to your expertise.

 I will fix the tests in Codegen to use clang_cc1

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-08-13 Thread Chris Apple via cfe-commits

cjappl wrote:

> exceptions to "built-in functions are always safe"

aha! I missed this was part of the plan to begin with, that makes sense.

This latest commit fixed my example. Code throws a warning as expected!

https://github.com/llvm/llvm-project/pull/99656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] nonblocking/nonallocating attributes: 2nd pass caller/callee analysis (PR #99656)

2024-08-13 Thread Chris Apple via cfe-commits

cjappl wrote:

Hi @dougsonos 

Seeing a possible bug when using `malloc` in a [[nonallocating]] context.

Specifically this test program (partially stolen from one of your test cases)

```cpp
#include 
void nb4_inline() {}
void nb4_not_inline();

void nb4() noexcept [[clang::nonallocating]]
{
  float* ptr = (float*)malloc(100 * sizeof(float)); // SHOULD WARN BUT DOES NOT
  nb4_inline(); // OK
  nb4_not_inline(); // expected-warning {{'nonblocking' function must not call 
non-'nonblocking' function}}
}
```

Produces warnings:
```
/Users/topher/code/rtsan_example/main.cpp:15:3: warning: 'nonallocating' 
function must not call non-'nonallocating' function 'nb4_not_inline' 
[-Wfunction-effects]
   15 |   nb4_not_inline(); // expected-warning {{'nonblocking' function must 
not call non-'nonblocking' function}}
  |   ^
/Users/topher/code/rtsan_example/main.cpp:9:6: note: declaration cannot be 
inferred 'nonallocating' because it has no definition in this translation unit
9 | void nb4_not_inline();
  |  ^
```
But we are missing the warning for the malloc call (which should be 
non-nonallocating)

More simply:
```
#include 
float* nb4() noexcept [[clang::nonallocating]]
{
  float* ptr = (float*)malloc(100 * sizeof(float));
  return ptr;
}
```

Produces no warnings:
```
[2/2] Linking CXX executable helloWorld
Build finished
```


https://github.com/llvm/llvm-project/pull/99656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-13 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/4] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

cjappl wrote:

(Sorry for the "double ping", I just got commit powers, so adding people to the 
review explicitly)

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/3] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/6] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/5] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/4] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-12 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 9d3d49fa755c28b21c3b4771faae65cf418dec5a Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/3] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 81e6702d5de666..95aa328c0245de 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -989,6 +990,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 2b2e23f1e5d7fb..fc388f6f879a1e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-11 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited 
https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits


@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }

cjappl wrote:

Excellent, added that check in there.

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/102622

>From 00d75e70c55e1e0c0b57a6402a9d02604a35dba6 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH 1/2] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a661..05419d073f38f4 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -995,6 +996,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index af201554898f31..915ec302270f2a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |

[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits

cjappl wrote:

Pinging for a possible review:

@Sirraide @AaronBallman @MaskRay @vitalybuka @dougsonos 

Co-Author @davidtrevelyan 

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits


@@ -552,11 +552,15 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  SanitizerKind::Leak | SanitizerKind::Thread |
  SanitizerKind::Memory | SanitizerKind::KernelAddress |
  SanitizerKind::Scudo | SanitizerKind::SafeStack),
-  std::make_pair(SanitizerKind::MemTag,
- SanitizerKind::Address | SanitizerKind::KernelAddress |
- SanitizerKind::HWAddress |
- SanitizerKind::KernelHWAddress),
-  std::make_pair(SanitizerKind::KCFI, SanitizerKind::Function)};
+  std::make_pair(SanitizerKind::MemTag, SanitizerKind::Address |

cjappl wrote:

Sorry, a little clang-tidy cruft here, the only thing changed functionally was 
the addition of the realtime sanitizer pairs on line 560

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits


@@ -995,6 +996,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(

cjappl wrote:

I am completely not sure where in the pipeline this pass should live. Any 
advice from someone with more experience would be great. This was chosen to 
match other passes of sanitizers around it.

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits


@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }

cjappl wrote:

@dougsonos , would love some eyes on this to make sure this makes sense to you!

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits

cjappl wrote:

I was not able to figure out a way to separate the CodeGen from the driver, 
seeing as the codegen only happens when the sanitizer is enabled. This means to 
write unit tests for the CodeGen, I needed the -fsanitize=realtime flag. If 
someone has advice on how to get around this problem I'm more than happy to 
break this up if it is too big!

https://github.com/llvm/llvm-project/pull/102622
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer codegen and driver (PR #102622)

2024-08-09 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/102622

Introduce the `-fsanitize=realtime` flag in clang driver

Plug in the RealtimeSanitizer PassManager pass in Codegen, and attribute a 
function based on if it has the `[[clang::nonblocking]]` function effect.


>From 00d75e70c55e1e0c0b57a6402a9d02604a35dba6 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Wed, 24 Jul 2024 14:25:44 -0700
Subject: [PATCH] [clang][rtsan] Introduce realtime sanitizer codegen and
 driver

---
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/BackendUtil.cpp |  8 
 clang/lib/CodeGen/CodeGenFunction.cpp |  6 +++
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  6 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/CodeGen/rtsan_attribute_inserted.c |  7 +++
 clang/test/CodeGen/rtsan_insert_at_entry.c|  9 
 clang/test/CodeGen/rtsan_insert_at_exit.c |  9 
 .../rtsan_no_attribute_sanitizer_disabled.c   |  8 
 clang/test/Driver/fsanitize.c | 46 +++
 clang/test/Driver/rtsan.c | 14 ++
 14 files changed, 135 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/rtsan_attribute_inserted.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_entry.c
 create mode 100644 clang/test/CodeGen/rtsan_insert_at_exit.c
 create mode 100644 clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c39..9223f62b3639a7 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -79,6 +79,9 @@ SANITIZER("thread", Thread)
 // Numerical stability sanitizer.
 SANITIZER("numerical", NumericalStability)
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // LeakSanitizer
 SANITIZER("leak", Leak)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679f..c13a640268f0c7 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -106,6 +106,7 @@ class SanitizerArgs {
   bool needsNsanRt() const {
 return Sanitizers.has(SanitizerKind::NumericalStability);
   }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
 
   bool hasMemTag() const {
 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a661..05419d073f38f4 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
 #include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
+#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -995,6 +996,13 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 FPM.addPass(BoundsCheckingPass());
   });
 
+if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+  PB.registerScalarOptimizerLateEPCallback(
+  [](FunctionPassManager &FPM, OptimizationLevel Level) {
+RealtimeSanitizerOptions Opts;
+FPM.addPass(RealtimeSanitizerPass(Opts));
+  });
+
 // Don't add sanitizers if we are here from ThinLTO PostLink. That already
 // done on PreLink stage.
 if (!IsThinLTOPostLink) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index af201554898f31..915ec302270f2a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -845,6 +845,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
   if (SanOpts.has(SanitizerKind::ShadowCallStack))
 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects())
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
+Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
+  }
+
   // Apply fuzzing attribute to the function.
   if (SanOpts.hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1fd870b72286e5..7b38f20fc8d059 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++

[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-25 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/100192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-25 Thread Chris Apple via cfe-commits

cjappl wrote:

Thanks to the feedback from @MaskRay and @vitalybuka , closing in favor of 
doing this processing in LLVM.  (PR: 
https://github.com/llvm/llvm-project/pull/100596)

The clang driver changes will come after that is merged! Appreciate all the 
reviews setting us on the right path.

https://github.com/llvm/llvm-project/pull/100192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/100192

>From 0307f457862e4a7ef623a74690422eb1425f1067 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 18 Jul 2024 17:29:01 +0200
Subject: [PATCH 1/2] [rtsan] Introduce rtsan clang codegen

---
 clang/include/clang/Basic/Attr.td  |  5 +++
 clang/include/clang/Basic/Sanitizers.def   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CodeGenFunction.cpp  | 51 ++
 clang/lib/Driver/SanitizerArgs.cpp | 14 +++---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  7 +++
 clang/lib/Driver/ToolChains/Darwin.cpp |  8 
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 clang/test/Driver/fsanitize.c  | 48 
 clang/test/Driver/rtsan.c  | 12 +
 10 files changed, 145 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4825979a974d2..8a4a29d589b9b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3527,6 +3527,11 @@ def NoSanitize : InheritableAttr {
 bool hasCoverage() const {
   return llvm::is_contained(sanitizers(), "coverage");
 }
+
+bool hasRealtime() const {
+  return llvm::is_contained(sanitizers(), "realtime");
+}
+
   }];
 }
 
diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c3..8a5df643ffa0c 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -37,6 +37,9 @@
 #endif
 
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // AddressSanitizer
 SANITIZER("address", Address)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679..6c0df926aec5b 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -79,6 +79,7 @@ class SanitizerArgs {
   bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
   bool needsHwasanRt() const {
 return Sanitizers.has(SanitizerKind::HWAddress);
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1e98bea8c8ce3..9346218bd1ce4 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -31,6 +31,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
@@ -40,6 +41,9 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/FPEnv.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
@@ -1410,6 +1414,35 @@ QualType 
CodeGenFunction::BuildFunctionArgList(GlobalDecl GD,
   return ResTy;
 }
 
+void InsertCallBeforeInstruction(llvm::Function *Fn,
+ llvm::Instruction &Instruction,
+ const char *FunctionName) {
+  llvm::LLVMContext &context = Fn->getContext();
+  llvm::FunctionType *FuncType =
+  llvm::FunctionType::get(llvm::Type::getVoidTy(context), false);
+  llvm::FunctionCallee Func =
+  Fn->getParent()->getOrInsertFunction(FunctionName, FuncType);
+  llvm::IRBuilder<> builder{&Instruction};
+  builder.CreateCall(Func, {});
+}
+
+void InsertCallAtFunctionEntryPoint(llvm::Function *Fn,
+const char *InsertFnName) {
+
+  InsertCallBeforeInstruction(Fn, Fn->front().front(), InsertFnName);
+}
+
+void InsertCallAtAllFunctionExitPoints(llvm::Function *Fn,
+   const char *InsertFnName) {
+  for (auto &BB : *Fn) {
+for (auto &I : BB) {
+  if (auto *RI = dyn_cast(&I)) {
+InsertCallBeforeInstruction(Fn, I, InsertFnName);
+  }
+}
+  }
+}
+
 void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
const CGFunctionInfo &FnInfo) {
   assert(Fn && "generating code for null Function");
@@ -1578,9 +1611,27 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, 
llvm::Function *Fn,
 }
   }
 
+  if (SanOpts.has(SanitizerKind::Realtime)) {
+for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects()) {
+  if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking) {
+InsertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter");
+break;
+  }
+}
+  }
+
   //

[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-23 Thread Chris Apple via cfe-commits


@@ -1410,6 +1414,35 @@ QualType 
CodeGenFunction::BuildFunctionArgList(GlobalDecl GD,
   return ResTy;
 }
 
+void InsertCallBeforeInstruction(llvm::Function *Fn,

cjappl wrote:

> Also maybe I missed some discussion. these changes looks like better be done 
> by llvm pass.

Nope, this is just us not knowing what we don't know!

Any thoughts as to where this may live in that step? I'm unfamiliar with where 
it might be appropriate. Pointing to a general file or something to grep for 
would be greatly appreciated! Thanks Vitaly.


https://github.com/llvm/llvm-project/pull/100192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [clang][llvm][rtsan] Introduce RealtimeSanitizer clang codegen, llvm attributes (PR #100120)

2024-07-23 Thread Chris Apple via cfe-commits

cjappl wrote:

Closing in favor of these two reviews to begin with, a 3rd will be added with 
the lit test components after these are merged:

1. Fixing unit test intermittent failure on mac: 
https://github.com/llvm/llvm-project/pull/100188
2. clang codegen component https://github.com/llvm/llvm-project/pull/100192
3. (NOT POSTED YET) Initial lit tests and re-enabling our instrumented unit 
tests from this review

https://github.com/llvm/llvm-project/pull/100120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [clang][llvm][rtsan] Introduce RealtimeSanitizer clang codegen, llvm attributes (PR #100120)

2024-07-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl closed 
https://github.com/llvm/llvm-project/pull/100120
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-23 Thread Chris Apple via cfe-commits

cjappl wrote:

CC for review @MaskRay @vitalybuka @AaronBallman @Sirraide @rjmccall 
@erichkeane @davidtrevelyan @dougsonos 

https://github.com/llvm/llvm-project/pull/100192
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

2024-07-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl created 
https://github.com/llvm/llvm-project/pull/100192

Inserts the `__rtsan_realtime_enter` at the first line of all functions with 
[[clang::nonblocking]] function effects, and `__rtsan_realtime_exit` at all 
exit points.

Introduces the -fsanitize=realtime flag, and unit tests to confirm things are 
working.

Please see the [reviewer support 
document](https://github.com/realtime-sanitizer/radsan/blob/doc/review-support/doc/review.md)
 for what our next steps are. 

>From 0307f457862e4a7ef623a74690422eb1425f1067 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 18 Jul 2024 17:29:01 +0200
Subject: [PATCH] [rtsan] Introduce rtsan clang codegen

---
 clang/include/clang/Basic/Attr.td  |  5 +++
 clang/include/clang/Basic/Sanitizers.def   |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h |  1 +
 clang/lib/CodeGen/CodeGenFunction.cpp  | 51 ++
 clang/lib/Driver/SanitizerArgs.cpp | 14 +++---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  7 +++
 clang/lib/Driver/ToolChains/Darwin.cpp |  8 
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 clang/test/Driver/fsanitize.c  | 48 
 clang/test/Driver/rtsan.c  | 12 +
 10 files changed, 145 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/rtsan.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4825979a974d2..8a4a29d589b9b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3527,6 +3527,11 @@ def NoSanitize : InheritableAttr {
 bool hasCoverage() const {
   return llvm::is_contained(sanitizers(), "coverage");
 }
+
+bool hasRealtime() const {
+  return llvm::is_contained(sanitizers(), "realtime");
+}
+
   }];
 }
 
diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c3..8a5df643ffa0c 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -37,6 +37,9 @@
 #endif
 
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // AddressSanitizer
 SANITIZER("address", Address)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679..6c0df926aec5b 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -79,6 +79,7 @@ class SanitizerArgs {
   bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
   bool needsHwasanRt() const {
 return Sanitizers.has(SanitizerKind::HWAddress);
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1e98bea8c8ce3..9346218bd1ce4 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -31,6 +31,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
@@ -40,6 +41,9 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/FPEnv.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
@@ -1410,6 +1414,35 @@ QualType 
CodeGenFunction::BuildFunctionArgList(GlobalDecl GD,
   return ResTy;
 }
 
+void InsertCallBeforeInstruction(llvm::Function *Fn,
+ llvm::Instruction &Instruction,
+ const char *FunctionName) {
+  llvm::LLVMContext &context = Fn->getContext();
+  llvm::FunctionType *FuncType =
+  llvm::FunctionType::get(llvm::Type::getVoidTy(context), false);
+  llvm::FunctionCallee Func =
+  Fn->getParent()->getOrInsertFunction(FunctionName, FuncType);
+  llvm::IRBuilder<> builder{&Instruction};
+  builder.CreateCall(Func, {});
+}
+
+void InsertCallAtFunctionEntryPoint(llvm::Function *Fn,
+const char *InsertFnName) {
+
+  InsertCallBeforeInstruction(Fn, Fn->front().front(), InsertFnName);
+}
+
+void InsertCallAtAllFunctionExitPoints(llvm::Function *Fn,
+   const char *InsertFnName) {
+  for (auto &BB : *Fn) {
+for (auto &I : BB) {
+  if (auto *RI = dyn_cast(&I)) {
+InsertCallBeforeInstruction(Fn, I, InsertFnName);
+  }
+}
+  }
+}
+
 void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
const CGFunctionInfo &FnInfo) {
   assert(Fn && "generating code for null Function");
@@

[clang] [compiler-rt] [llvm] [clang][llvm][rtsan] Introduce RealtimeSanitizer clang codegen, llvm attributes (PR #100120)

2024-07-23 Thread Chris Apple via cfe-commits

https://github.com/cjappl updated 
https://github.com/llvm/llvm-project/pull/100120

>From e0a1336da28f0f1d9f870be1676991d415160321 Mon Sep 17 00:00:00 2001
From: Chris Apple 
Date: Thu, 18 Jul 2024 17:29:01 +0200
Subject: [PATCH 1/2] [rtsan] Introduce rtsan frontend

---
 clang/include/clang/Basic/Attr.td |  5 ++
 clang/include/clang/Basic/Sanitizers.def  |  3 ++
 clang/include/clang/Driver/SanitizerArgs.h|  1 +
 clang/lib/CodeGen/CGCall.cpp  |  6 +++
 clang/lib/CodeGen/CodeGenFunction.cpp | 43 +
 clang/lib/Driver/SanitizerArgs.cpp| 14 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  7 +++
 clang/lib/Driver/ToolChains/Darwin.cpp|  8 
 clang/lib/Driver/ToolChains/Linux.cpp |  1 +
 clang/test/Driver/fsanitize.c | 48 +++
 clang/test/Driver/rtsan.c | 12 +
 compiler-rt/lib/rtsan/rtsan_interceptors.cpp  |  4 +-
 compiler-rt/lib/rtsan/tests/CMakeLists.txt| 15 +++---
 compiler-rt/test/rtsan/CMakeLists.txt | 11 -
 compiler-rt/test/rtsan/test_rtsan.cpp | 17 +++
 .../test/rtsan/test_rtsan_inactive.cpp| 23 +
 .../test/sanitizer_common/CMakeLists.txt  |  2 +-
 .../test/sanitizer_common/lit.common.cfg.py   |  3 ++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  1 +
 llvm/include/llvm/IR/Attributes.td|  3 ++
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |  2 +
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  2 +
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  1 +
 23 files changed, 206 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/Driver/rtsan.c
 create mode 100644 compiler-rt/test/rtsan/test_rtsan.cpp
 create mode 100644 compiler-rt/test/rtsan/test_rtsan_inactive.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4825979a974d2..8a4a29d589b9b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3527,6 +3527,11 @@ def NoSanitize : InheritableAttr {
 bool hasCoverage() const {
   return llvm::is_contained(sanitizers(), "coverage");
 }
+
+bool hasRealtime() const {
+  return llvm::is_contained(sanitizers(), "realtime");
+}
+
   }];
 }
 
diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index bee35e9dca7c3..8a5df643ffa0c 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -37,6 +37,9 @@
 #endif
 
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // AddressSanitizer
 SANITIZER("address", Address)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 47ef175302679..6c0df926aec5b 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -79,6 +79,7 @@ class SanitizerArgs {
   bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
+  bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
   bool needsHwasanRt() const {
 return Sanitizers.has(SanitizerKind::HWAddress);
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index d582aba679ddc..7af7785515688 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2408,6 +2408,12 @@ void CodeGenModule::ConstructAttributeList(StringRef 
Name,
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 NBA = Fn->getAttr();
   }
+
+  for (const FunctionEffectWithCondition &Fe : Fn->getFunctionEffects()) {
+if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking) {
+  FuncAttrs.addAttribute(llvm::Attribute::NonBlocking);
+}
+  }
 }
 
 if (isa(TargetDecl) || isa(TargetDecl)) {
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1e98bea8c8ce3..84ce2b20dd45d 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -31,6 +31,7 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/Sanitizers.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
@@ -40,6 +41,9 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/FPEnv.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
@@ -1410,6 +1414,35 @@ QualType 
CodeGenFunction::BuildFunctionArgList(GlobalDecl GD,
   return ResTy;
 }
 
+void InsertCallBeforeInstruction(llvm::Function *Fn,
+ llvm::

[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

> This also breaks building the compiler-rt for older android versions, because 
> pthread_spinlock_t is only defined when `__ANDROID_API__` >= 24.

Thanks for reporting this @glandium ! I am in the process of disabling this for 
android as we speak. Let me know if you see anything else fishy

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

This patch I have a strong hunch fixes issue 1 in my comment above. This patch 
compiles and runs on my linux container and my mac, proving it doesn't affect 
compilation on those two systems.

```
diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt 
b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index d96e538b255f..e539ebc387e0 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -60,7 +60,7 @@ foreach(arch ${RTSAN_TEST_ARCH})
   #  RtsanUnitTests "Rtsan-${arch}-Test" ${arch}
   #  COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
   #  SOURCES ${RTSAN_INST_TEST_SOURCES} ${COMPILER_RT_GOOGLETEST_SOURCES}
-  #  DEPS llvm_gtest rtsan
+  #  DEPS rtsan
   #  CFLAGS ${RTSAN_UNITTEST_CFLAGS} -fsanitize=realtime
   #  LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS} -fsanitize=realtime)

@@ -94,7 +94,6 @@ foreach(arch ${RTSAN_TEST_ARCH})
 COMPILE_DEPS ${RTSAN_UNITTEST_HEADERS}
 SOURCES ${RTSAN_NOINST_TEST_SOURCES}
 ${COMPILER_RT_GOOGLETEST_SOURCES}
-DEPS llvm_gtest
 CFLAGS ${RTSAN_UNITTEST_CFLAGS}
 LINK_FLAGS ${RTSAN_UNITTEST_LINK_FLAGS}
 RUNTIME ${RTSAN_TEST_RUNTIME})
```

This also better matches the other sanitizers, llvm_gtest is a dependency in 
llvm, anything in compiler-rt using gtest just uses the sources directly as 
seen in:

```
SOURCES ${RTSAN_NOINST_TEST_SOURCES}
 ${COMPILER_RT_GOOGLETEST_SOURCES}
```

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

There are 3 errors I see:

Mostly it's this `llvm_gtest` issue:
```
ninja: error: 'compiler-rt/lib/rtsan/tests/llvm_gtest', needed by 
'compiler-rt/lib/rtsan/tests/RtsanNoInstTestObjects.rtsan_preinit.cpp.x86_64.o',
 missing and no known rule to make it
```

On fuchsia it is a parameter type issue:
```
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:55:22:
 error: use of undeclared identifier '__unsanitized_open'; did you mean 
'__unsanitized_memset'?
   55 |   const int result = REAL(open)(path, oflag, mode);
  |  ^~
  |  __unsanitized_memset
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18:
 note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
  |  ^
:138:1: note: expanded from here
  138 | __unsanitized_open
  | ^
/usr/local/fuchsia/sdk/arch/x64/sysroot/include/zircon/sanitizer.h:34:18: note: 
'__unsanitized_memset' declared here
   34 | __typeof(memset) __unsanitized_memset;
  |  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:55:33:
 error: cannot initialize a parameter of type 'void *' with an lvalue of type 
'const char *'
   55 |   const int result = REAL(open)(path, oflag, mode);
  | ^~~~
/usr/local/fuchsia/sdk/arch/x64/sysroot/include/zircon/sanitizer.h:34:18: note: 
passing argument to parameter here
   34 | __typeof(memset) __unsanitized_memset;
  |  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:69:22:
 error: use of undeclared identifier '__unsanitized_openat'
   69 |   const int result = REAL(openat)(fd, path, oflag, mode);
  |  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18:
 note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
  |  ^
:141:1: note: expanded from here
  141 | __unsanitized_openat
  | ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/rtsan_interceptors.cpp:77:22:
 error: use of undeclared identifier '__unsanitized_creat'
   77 |   const int result = REAL(creat)(path, mode);
  |  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/compiler-rt/lib/rtsan/../interception/interception.h:241:18:
 note: expanded from macro 'REAL'
  241 | # define REAL(x) __unsanitized_##x
  |  ^
:144:1: note: expanded from here
  144 | __unsanitized_creat
  | ^
Step 6 (build) failure: build (failure)
...
```

On windows (which I think we should just disable support for, for now:

```
C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\lib\rtsan\rtsan_context.cpp(19):
 fatal error C1083: Cannot open include file: 'pthread.h': No such file or 
directory
```


Working to see if I can fix the llvm_gtest issue right now. I would love advice 
on Fuchsia and disabling rtsan for windows.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

> I can reproduce and will debug in an hour.

Thanks for the help @vitalybuka , I am looking into this as well, but very 
grateful for more experienced eyes on the matter too. I'll keep you posted here 
if I find anything

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-09 Thread Chris Apple via cfe-commits

cjappl wrote:

Also, just as a heads up, neither of the authors have commit access as we are 
new to LLVM. If this is OK to go in we will need help with that step. 

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-08 Thread Chris Apple via cfe-commits


@@ -0,0 +1,516 @@
+//===--- rtsan_test_interceptors.cpp - Realtime Sanitizer ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//

cjappl wrote:

Seems reasonable to convert these to lit! I propose leaving this for this 
commit, and we convert them in the near future. Specifically this next commit 
will introduce the -fsanitize=realtime flag, and come with a bunch of the lit 
tests that we have written, so it will be easier to convert them once that 
infrastructure has landed.

One clarifying question, for when that work is done:

Should we have a lit test for every intereceptor? The reason we did it in gtest 
unit tests is that adding a new interceptor's test is a few lines, as opposed 
to a  brand new file with the lit boilerplate. This makes it easy to make sure 
that every interceptor does what we think it does. We worried about the "cost" 
of the new file for every interceptor.  In our demo branch, as we have it laid 
out, the lit tests test on the full end-to-end system level, while these tests 
actually hit every interceptor.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-08 Thread Chris Apple via cfe-commits

cjappl wrote:

Pinging reviewers @vitalybuka @zygoloid

State of the review: 1 approval from MaskRay, all open comments have been 
addressed. Looking for more feedback, or more approval or a merge if this is 
looking good.

Thanks much! :)

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-03 Thread Chris Apple via cfe-commits


@@ -0,0 +1,67 @@
+import os
+
+# Setup config name.
+config.name = "RTSAN" + config.name_suffix
+
+# Setup source root.
+config.test_source_root = os.path.dirname(__file__)
+
+# Setup default compiler flags use with -frtsan-instrument option.
+clang_rtsan_cflags = ["-frtsan-instrument", config.target_cflags]
+
+# If libc++ was used to build rtsan libraries, libc++ is needed. Fix applied
+# to Linux only since -rpath may not be portable. This can be extended to
+# other platforms.
+if config.libcxx_used == "1" and config.host_os == "Linux":
+clang_rtsan_cflags = clang_rtsan_cflags + (
+["-L%s -lc++ -Wl,-rpath=%s" % (config.llvm_shlib_dir, 
config.llvm_shlib_dir)]

cjappl wrote:

Removed! 

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-03 Thread Chris Apple via cfe-commits

cjappl wrote:

> clangDriver changes are usually the last. The expectation is that if 
> -fsanitize=realtime does not return an error, there should be some basic 
> functionality.

Thanks for the feedback @MaskRay . I removed all of the clang components of 
this review, leaving only the compiler-rt components. We will re-introduce the 
clang changes in a future review.

In the meantime, I commented out compilation of our unit tests that required 
the -fsanitize flag, let me know if you'd prefer to see them removed until 
later. These unit tests are paired with the code introduced here, so I think at 
least by subject it makes sense to introduce them here, even if they are 
briefly not being compiled.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-07-01 Thread Chris Apple via cfe-commits

cjappl wrote:

Pinging reviewers @vitalybuka @MaskRay @zygoloid 

All the comments on this PR have been addressed, looking for more feedback, or 
approval/merge if we are getting close! Thanks in advance :)

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-06-26 Thread Chris Apple via cfe-commits

cjappl wrote:

Bumped the branch to resolve the conflict in config-ix.cmake

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-06-21 Thread Chris Apple via cfe-commits

cjappl wrote:

Pinging reviewers, after we had more conversations on the overall structure and 
usefulness of RTSan, and it was approved. 

@zygoloid @vitalybuka @MaskRay 

Details of the aforementioned discussion are around here in the discourse 
thread:
https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/82

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-06-05 Thread Chris Apple via cfe-commits


@@ -1509,6 +1511,11 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
   }

cjappl wrote:

Thanks for catching this! Added a few basic ones that test that the flag is 
supported, and that some known sanitizer incompatibilities are blocked

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [llvm] Remove some `try_compile` CMake checks for compiler flags (PR #92953)

2024-06-03 Thread Chris Apple via cfe-commits

cjappl wrote:

Thanks for your help! You were correct that cc was pointing to gcc. This is 
fixed when I updated my machine to use my known clang as the default compiler.

For future archeologists, this meant (from [this 
answer](https://askubuntu.com/questions/1198087/how-to-set-clang-9-as-the-default-c-compiler-on-ubuntu-19-10))

```
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 60
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 60
```

https://github.com/llvm/llvm-project/pull/92953
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [llvm] Remove some `try_compile` CMake checks for compiler flags (PR #92953)

2024-06-03 Thread Chris Apple via cfe-commits

cjappl wrote:

Hi @Endilll 

I did a git bisect that pointed to this change as the one blocking my 
compilation on an Ubuntu docker image with clang 14.0

The error I see:

```
CMake Error at 
/test_radsan/llvm-project/compiler-rt/cmake/Modules/CheckSectionExists.cmake:72 
(message):
  cc: error: unrecognized command-line option
  '-Wcovered-switch-default'; did you mean
  '-Wno-switch-default'?

  cc: error: unrecognized command-line option
  '-Wstring-conversion'; did you mean
  '-Wsign-conversion'?

Call Stack (most recent call first):
  /test_radsan/llvm-project/compiler-rt/lib/builtins/CMakeLists.txt:923 
(check_section_exists)
```

My compiler info, printed from CMake:
```
  CMAKE_CXX_COMPILER_VERSION: 14.0.0
  CMAKE_CXX_COMPILER_ID: Clang
```

More info from the command line:
```
$ clang --version
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ uname -a
Linux 18728bf50582 6.5.11-linuxkit #1 SMP PREEMPT Mon Dec  4 11:30:00 UTC 2023 
aarch64 aarch64 aarch64 GNU/Linux
$ cmake --version
cmake version 3.22.1
```

Let me know what other information may be helpful, or if this is user error. It 
seems from your godbolt links above, clang 5.0 and higher should work, so I'm 
surprised that 14.0 is dying in this environment

https://github.com/llvm/llvm-project/pull/92953
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-06-03 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce Realtime Sanitizer (RTSan) backend (PR #92460)

2024-06-03 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-06-03 Thread Chris Apple via cfe-commits

https://github.com/cjappl edited https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-30 Thread Chris Apple via cfe-commits

cjappl wrote:

Ping

@yln @vitalybuka @Sirraide @AaronBallman @zygoloid @compnerd @petrhosek 
@isanbard @MaskRay 

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-23 Thread Chris Apple via cfe-commits

cjappl wrote:

Weekly ping of reviewers

@yln @vitalybuka @Sirraide @AaronBallman @zygoloid @compnerd @petrhosek 
@isanbard

Looking for weighing in on any of the code as it stands now, or the naming 
question posed by MaskRay 
[here](https://discourse.llvm.org/t/rfc-nolock-and-noalloc-attributes/76837/75),
 so far there seems to be support for rtsan over radsan :)

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-20 Thread Chris Apple via cfe-commits


@@ -1382,6 +1382,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   StaticRuntimes.push_back("asan_cxx");
   }
 
+  if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt()) {
+StaticRuntimes.push_back("radsan");
+  }

cjappl wrote:

Ok, if I can summarize the important bits in my own words:

Different platforms have different defaults they use for the sanitizers, some 
(Darwin, for example) use shared, others (clang on Linux) use static.

A user can specify and override the default with the flags 
`-[shared|static]-libsan`.



To support the most possible configurations, do you think we should add back in 
the ability to link the shared library in this file? In Darwin.cpp we already 
show the ability to link the shared runtime, so it seemingly would be as simple 
as adding in a:

```
if (SanArgs.needsRadsanRt())
  SharedRuntimes.push_back("radsan");

```

To the block above. Any advice?

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-20 Thread Chris Apple via cfe-commits


@@ -0,0 +1,106 @@
+//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//===--===//
+
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace detail {
+
+static pthread_key_t Key;

cjappl wrote:

I pushed the change for all non-lambda variable names, happy to change the 
lambdas too based on your feedback.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-20 Thread Chris Apple via cfe-commits


@@ -0,0 +1,106 @@
+//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//===--===//
+
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace detail {
+
+static pthread_key_t Key;

cjappl wrote:

No apology necessary! Happy to do this right the first time.

Does this also apply to lambdas?

```
  auto Func = [&vec]() { vec.push_back(0.4f); };
```

Should this become:
```
  auto func = [&vec]() { vec.push_back(0.4f); };
```

Or remain "function case"?

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-19 Thread Chris Apple via cfe-commits


@@ -0,0 +1,106 @@
+//===--- radsan_context.cpp - Realtime Sanitizer --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//===--===//
+
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace __sanitizer;
+
+namespace detail {
+
+static pthread_key_t Key;

cjappl wrote:

Great thanks!! Before I go through and edit these, `snake_case` is preferred 
for variables in all contexts?

Really appreciate the review. Pushing up most of your requested changes now.

https://github.com/llvm/llvm-project/pull/92460
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >