[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

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

I found this handy for situations where you want to pass in a config file and 
not rely on a default `.clang-tidy` file.


The new option is `-config` and will expect something that can be passed into 
the `--config-file=` parameter of `clang-tidy`

>From 433f4ac919a6967c278e56a19b5824e474ebd907 Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:53:56 -0800
Subject: [PATCH] Add ability to pass in a clang-tidy config file to
 clang-tidy-diff

---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 8817e2914f6e25..fdaf1a4330e060 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -223,6 +223,12 @@ def main():
 default=[],
 help="Load the specified plugin in clang-tidy.",
 )
+parser.add_argument(
+"-config",
+dest="config",
+default=None,
+help="Specifies a clang-tidy config file"
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -309,6 +315,8 @@ def main():
 
 # Form the common args list.
 common_clang_tidy_args = []
+if args.config is not None:
+common_clang_tidy_args.append("--config-file=" + args.config)
 if args.fix:
 common_clang_tidy_args.append("-fix")
 if args.checks != "":

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


[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

cjappl wrote:

@njames93 friendly ping for a review on this PR. Thank you in advance!

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


[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

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

>From 433f4ac919a6967c278e56a19b5824e474ebd907 Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:53:56 -0800
Subject: [PATCH 1/2] Add ability to pass in a clang-tidy config file to
 clang-tidy-diff

---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 8817e2914f6e25..fdaf1a4330e060 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -223,6 +223,12 @@ def main():
 default=[],
 help="Load the specified plugin in clang-tidy.",
 )
+parser.add_argument(
+"-config",
+dest="config",
+default=None,
+help="Specifies a clang-tidy config file"
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -309,6 +315,8 @@ def main():
 
 # Form the common args list.
 common_clang_tidy_args = []
+if args.config is not None:
+common_clang_tidy_args.append("--config-file=" + args.config)
 if args.fix:
 common_clang_tidy_args.append("-fix")
 if args.checks != "":

>From ff3e289814d8af2c3c8eea12e3ee3c48959aa79a Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 16:42:28 -0800
Subject: [PATCH 2/2] Fix style

---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index fdaf1a4330e060..e20b7a2cda2dde 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -227,7 +227,7 @@ def main():
 "-config",
 dest="config",
 default=None,
-help="Specifies a clang-tidy config file"
+help="Specifies a clang-tidy config file",
 )
 
 clang_tidy_args = []

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


[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

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

>From 433f4ac919a6967c278e56a19b5824e474ebd907 Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:53:56 -0800
Subject: [PATCH 1/3] Add ability to pass in a clang-tidy config file to
 clang-tidy-diff

---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 8817e2914f6e25..fdaf1a4330e060 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -223,6 +223,12 @@ def main():
 default=[],
 help="Load the specified plugin in clang-tidy.",
 )
+parser.add_argument(
+"-config",
+dest="config",
+default=None,
+help="Specifies a clang-tidy config file"
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -309,6 +315,8 @@ def main():
 
 # Form the common args list.
 common_clang_tidy_args = []
+if args.config is not None:
+common_clang_tidy_args.append("--config-file=" + args.config)
 if args.fix:
 common_clang_tidy_args.append("-fix")
 if args.checks != "":

>From ff3e289814d8af2c3c8eea12e3ee3c48959aa79a Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 16:42:28 -0800
Subject: [PATCH 2/3] Fix style

---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index fdaf1a4330e060..e20b7a2cda2dde 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -227,7 +227,7 @@ def main():
 "-config",
 dest="config",
 default=None,
-help="Specifies a clang-tidy config file"
+help="Specifies a clang-tidy config file",
 )
 
 clang_tidy_args = []

>From 05ae28f6705a7bccf36bbb3a84a17c3597b44c09 Mon Sep 17 00:00:00 2001
From: Chris Apple <14171107+cja...@users.noreply.github.com>
Date: Sat, 16 Dec 2023 16:51:41 -0800
Subject: [PATCH 3/3] Update ReleaseNotes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..0e2679e4fafb0e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -124,6 +124,10 @@ Improvements to clang-tidy
   exporting fixes fails. It now accepts a directory as a value for
   `-export-fixes` to export individual yaml files for each compilation unit.
 
+- Improved :program:`clang-tidy-diff.py` script. It now accepts a `-config` 
option
+  to pass in a configuration file to :program:`clang-tidy`. This option 
corresponds
+  to the `--config-file` option in :program:`clang-tidy`.
+
 - Improved :program:`run-clang-tidy.py` script. It now accepts a directory
   as a value for `-export-fixes` to export individual yaml files for each
   compilation unit.

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


[clang-tools-extra] Allow to pass config file to clang-tidy-diff (PR #75457)

2023-12-16 Thread Chris Apple via cfe-commits

cjappl wrote:

@MichaelLettrich I just realized I submitted basically the same PR as you! 
Great minds think alike. I found yours when I searched.

https://github.com/llvm/llvm-project/pull/75721

In this PR I added to the release notes, feel free to steal them if you want. I 
would love this feature in `main`

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


[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

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


[clang-tools-extra] Add ability to pass in a clang-tidy config file to clang-tidy-diff (PR #75721)

2023-12-16 Thread Chris Apple via cfe-commits

cjappl wrote:

This is almost exactly the same as #75457 , just with the release notes. I'm 
going to close this for now and re-open it if that one gets stale.

https://github.com/llvm/llvm-project/pull/75721
___
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-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-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-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-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][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] [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] [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

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] [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] 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


@@ -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] [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] 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] [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] [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-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-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] [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 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


@@ -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


@@ -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


@@ -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

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

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


@@ -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-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-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/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/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/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/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

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-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] 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] 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] [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] [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 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-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 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] [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] [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] [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] [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] [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] [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] [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] [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] [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-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-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] [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] 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-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] [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] [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 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


@@ -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/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

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


@@ -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


@@ -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] [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] [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] [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] [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] 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-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:

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:

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:

> 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] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -27,6 +27,8 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"

cjappl wrote:

FYI, these two headers require a cmake change:

```
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index a96439df6642..278c7c7394ab 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -80,6 +80,7 @@ add_clang_library(clangSema
   LINK_LIBS
   clangAPINotes
   clangAST
+  clangASTMatchers
   clangAnalysis
   clangBasic
   clangEdit
```

With this small change I was able to build the branch of your work merged with 
ours, no other adaptations necessary :) 

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -27,6 +27,8 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"

cjappl wrote:

To be less prescriptive with the solution:

I was getting linker errors saying that the symbols found in the ASTMatchers 
headers (used later in this file) were missing. I fixed it with this CMake 
change. Let me know if anyone needs more info and I'll re-generate the error.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -8057,3 +8057,70 @@ requirement:
   }
   }];
 }
+
+def DocCatNonBlockingNonAllocating : DocumentationCategory<"Performance 
Constraint Attributes"> {
+  let Content = [{

cjappl wrote:

It may be good to mention what the flag is that you use to enable these 
warnings.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

cjappl wrote:


Hi @dougsonos,

Just starting to integrate our two changes and noticing a possible bug here.

Issue: `blocking(false)` does not seem to resolve to `nonblocking`

## Streps to repro:
1. Have an example like
```
int main() [[clang::blocking(false)]]
{
return 0;
}
```
2. (optional, if you can't get diagnostics another way) Apply this patch to 
llvm, and recompile clang
```
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 69548902dc43..3047ed1e1887 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2404,6 +2404,15 @@ void CodeGenModule::ConstructAttributeList(StringRef 
Name,
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 NBA = Fn->getAttr();
   }
+
+  llvm::raw_fd_ostream stream(1, true);
+  const auto effects = Fn->getFunctionEffects();
+  if (not effects.empty())
+  {
+stream << "Function: " << Fn->getNameAsString().c_str() << "\n";
+Fn->getFunctionEffects().dump(stream);
+stream << "\n";
+  }
 }
 
 if (isa(TargetDecl) || isa(TargetDecl)) {
```

3. Compile aforementioned main file with the new perf-constraints clang

## Observed 

`blocking(false)` incorrectly resolves to `blocking`, when it should be 
`nonblocking`

```
> ninja
[1/2] Building CXX object CMakeFiles/MyExecutable.dir/main.cpp.o
Function: main
Effects{blocking}
...
```

All the other (non)blocking conditionals seem to work as intended.

1. `nonblocking(true)` -- should resolve to nonblocking ✅
```
Function: main
Effects{nonblocking}
```
2. `nonblocking(false)` -- should resolve to blocking ✅
```
Function: main
Effects{blocking}
```
3. `blocking(true)` -- should resolve to blocking ✅
```
Function: main
Effects{blocking}
```

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

cjappl wrote:

Ah! Nice, that is a totally valid solution as well. The only argument for the 
parameter that I can think of is symmetry.

I just noticed it _could_ accept a parameter, so I expected the behavior above. 
Absolutely good by me to strike it from being possible.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

cjappl wrote:

I can confirm that now if I try to use any argument with `blocking` I get: 
```
/Users/topher/Desktop/test_radsan/main.cpp:25:40: error: 'blocking' attribute 
takes no arguments
   25 | float process (float* data) noexcept [[clang::blocking(false)]]
```

Great!

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

cjappl wrote:

Possibly another bug here (or user error).

I am trying to see the warnings show up for a simple test program. The clang 
used in this example is the tip of your branch at time of writing 
b95964c2570c11d1d80ae6874be5e400f7b504ad

```cpp
#include 
#include 

int* process () [[clang::nonblocking]] 
{


  // THIS MALLOC SHOULD WARN, RIGHT? 
  int* malloced_data = (int*)std::malloc(sizeof(int));


  malloced_data[0] = 7;
  return malloced_data;
}

int main()
{
  int* y = process();
  printf("y[0] = %d\n", y[0]);
  return (int)y[0];
}
```

When I run compile and run this code, it runs, with the proper "7" exit code, 
but does not give me any warnings on compilation.

```
> /Users/topher/code/radsan_cjappl/build/bin/clang++ main.cpp -isysroot 
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk
>  -Wfunction-effects -Werror
> ./a.out
y[0] = 7
> echo $?
7
```

I highly suspect I'm doing something wrong, but can't figure out what it might 
be.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -1870,6 +1870,28 @@ bool Sema::IsFunctionConversion(QualType FromType, 
QualType ToType,
   FromFn = QT->getAs();
   Changed = true;
 }
+
+// For C, when called from checkPointerTypesForAssignment,
+// we need not to alter FromFn, or else even an innocuous cast
+// like dropping effects will fail. In C++ however we do want to
+// alter FromFn. TODO: Is this correct?

cjappl wrote:

Did you ever get clarity on if this was correct? Calling it out as I peruse 
this PR, I don't have the answer but it's hidden in here so wanted to bring 
attention to it.

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -18347,7 +18347,7 @@ void Sema::SetFunctionBodyKind(Decl *D, SourceLocation 
Loc, FnBodyKind BodyKind,
   }
 }
 
-bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
+bool Sema::CheckOverridingFunctionAttributes(CXXMethodDecl *New,

cjappl wrote:

It seems possibly strange to me that a function called "Check" would mutate a 
value passed into it. I would expect it to be passive.

Can the mutation come later, or in a different function, or perhaps this should 
be renamed?

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -7963,6 +7967,148 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
   llvm_unreachable("unexpected attribute kind!");
 }
 
+ExprResult Sema::ActOnEffectExpression(Expr *CondExpr, FunctionEffectMode 
&Mode,
+   bool RequireConstexpr) {
+  // see checkFunctionConditionAttr, Sema::CheckCXXBooleanCondition
+  if (RequireConstexpr || !CondExpr->isTypeDependent()) {
+ExprResult E = PerformContextuallyConvertToBool(CondExpr);
+if (E.isInvalid())
+  return E;
+CondExpr = E.get();
+if (RequireConstexpr || !CondExpr->isValueDependent()) {
+  llvm::APSInt CondInt;
+  E = VerifyIntegerConstantExpression(
+  E.get(), &CondInt,
+  // TODO: have our own diagnostic
+  diag::err_constexpr_if_condition_expression_is_not_constant);
+  if (E.isInvalid()) {
+return E;
+  }
+  Mode =
+  (CondInt != 0) ? FunctionEffectMode::True : 
FunctionEffectMode::False;
+} else {
+  Mode = FunctionEffectMode::Dependent;
+}
+  } else {
+Mode = FunctionEffectMode::Dependent;
+  }
+  return CondExpr;
+}
+
+static bool
+handleNonBlockingNonAllocatingTypeAttr(TypeProcessingState &TPState,
+   ParsedAttr &PAttr, QualType &QT,
+   FunctionTypeUnwrapper &Unwrapped) {
+  // Delay if this is not a function type.
+  if (!Unwrapped.isFunctionType())
+return false;
+
+  // Require FunctionProtoType
+  auto *FPT = Unwrapped.get()->getAs();
+  if (FPT == nullptr) {
+// TODO: special diagnostic?
+return false;
+  }
+
+  // Parse the new  attribute.
+  // non/blocking or non/allocating? Or conditional (computed)?
+  const bool isNonBlocking = PAttr.getKind() == ParsedAttr::AT_NonBlocking ||
+ PAttr.getKind() == ParsedAttr::AT_Blocking;
+  Sema &S = TPState.getSema();
+
+  FunctionEffectMode NewMode = FunctionEffectMode::None;
+  Expr *CondExpr = nullptr; // only valid if dependent
+
+  if (PAttr.getKind() == ParsedAttr::AT_NonBlocking ||
+  PAttr.getKind() == ParsedAttr::AT_NonAllocating) {
+if (!PAttr.checkAtMostNumArgs(S, 1)) {
+  PAttr.setInvalid();
+  return true;
+}
+
+// Parse the conditional expression, if any
+if (PAttr.getNumArgs() == 1) {
+  CondExpr = PAttr.getArgAsExpr(0);
+  ExprResult E = S.ActOnEffectExpression(CondExpr, NewMode);
+  if (E.isInvalid())
+return false;
+  CondExpr = NewMode == FunctionEffectMode::Dependent ? E.get() : nullptr;
+} else {
+  NewMode = FunctionEffectMode::True;
+}
+  } else {
+// This is the `blocking` or `allocating` attribute.
+if (S.CheckAttrNoArgs(PAttr))
+  return true;
+NewMode = FunctionEffectMode::False;
+  }
+
+  const FunctionEffect::Kind FEKind =
+  (NewMode == FunctionEffectMode::False)
+  ? (isNonBlocking ? FunctionEffect::Kind::Blocking
+   : FunctionEffect::Kind::Allocating)
+  : (isNonBlocking ? FunctionEffect::Kind::NonBlocking
+   : FunctionEffect::Kind::NonAllocating);
+  const FunctionEffectWithCondition NewEC{FunctionEffect(FEKind),
+  FunctionEffectCondition(CondExpr)};
+
+  // Diagnose the newly provided attribute as incompatible with a previous one.
+  auto incompatible = [&](const FunctionEffectWithCondition &PrevEC) {
+S.Diag(PAttr.getLoc(), diag::err_attributes_are_not_compatible)
+<< ("'" + NewEC.description() + "'")
+<< ("'" + PrevEC.description() + "'") << false;
+// we don't necessarily have the location of the previous attribute,
+// so no note.
+PAttr.setInvalid();
+return true;
+  };
+
+  // Find previous attributes
+  std::optional PrevNonBlocking;
+  std::optional PrevNonAllocating;
+
+  for (const FunctionEffectWithCondition &PrevEC : FPT->getFunctionEffects()) {
+if (PrevEC.Effect.kind() == FEKind ||
+PrevEC.Effect.oppositeKind() == FEKind)
+  return incompatible(PrevEC);
+switch (PrevEC.Effect.kind()) {
+case FunctionEffect::Kind::Blocking:
+case FunctionEffect::Kind::NonBlocking:
+  PrevNonBlocking = PrevEC;
+  break;
+case FunctionEffect::Kind::Allocating:
+case FunctionEffect::Kind::NonAllocating:
+  PrevNonAllocating = PrevEC;
+  break;
+default:
+  break;
+}
+  }
+
+  if (isNonBlocking) {

cjappl wrote:

minor: only var I've seen so far not UpperCamelCase

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -7963,6 +7967,148 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr 
&Attr) {
   llvm_unreachable("unexpected attribute kind!");
 }
 
+ExprResult Sema::ActOnEffectExpression(Expr *CondExpr, FunctionEffectMode 
&Mode,
+   bool RequireConstexpr) {
+  // see checkFunctionConditionAttr, Sema::CheckCXXBooleanCondition
+  if (RequireConstexpr || !CondExpr->isTypeDependent()) {
+ExprResult E = PerformContextuallyConvertToBool(CondExpr);
+if (E.isInvalid())
+  return E;
+CondExpr = E.get();
+if (RequireConstexpr || !CondExpr->isValueDependent()) {
+  llvm::APSInt CondInt;
+  E = VerifyIntegerConstantExpression(
+  E.get(), &CondInt,
+  // TODO: have our own diagnostic
+  diag::err_constexpr_if_condition_expression_is_not_constant);
+  if (E.isInvalid()) {

cjappl wrote:

Minor funky 4 spacing for the first few lines here

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

https://github.com/cjappl commented:

Just doing a first pass review. The guts of this are above my paygrade, but 
after playing with this functionally for a few days it seems to behave as 
intended from the realtime sanitizer team! :)

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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

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


[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 %s -ast-dump -fblocks | FileCheck %s
+
+// Make sure that the attribute gets parsed and attached to the correct AST 
elements.
+
+#pragma clang diagnostic ignored "-Wunused-variable"
+
+// 
=
+// Square brackets, true
+
+namespace square_brackets {
+
+// On the type of the FunctionDecl
+void nl_function() [[clang::nonblocking]];
+// CHECK: FunctionDecl {{.*}} nl_function 'void () 
__attribute__((clang_nonblocking))'
+
+// On the type of the VarDecl holding a function pointer
+void (*nl_func_a)() [[clang::nonblocking]];
+// CHECK: VarDecl {{.*}} nl_func_a 'void (*)() 
__attribute__((clang_nonblocking))'
+
+// On the type of the ParmVarDecl of a function parameter
+static void nlReceiver(void (*nl_func)() [[clang::nonblocking]]);
+// CHECK: ParmVarDecl {{.*}} nl_func 'void (*)() 
__attribute__((clang_nonblocking))'
+
+// As an AttributedType within the nested types of a typedef
+typedef void (*nl_fp_type)() [[clang::nonblocking]];
+// CHECK: TypedefDecl {{.*}} nl_fp_type 'void (*)() 
__attribute__((clang_nonblocking))'
+using nl_fp_talias = void (*)() [[clang::nonblocking]];
+// CHECK: TypeAliasDecl {{.*}} nl_fp_talias 'void (*)() 
__attribute__((clang_nonblocking))'
+
+// From a typedef or typealias, on a VarDecl
+nl_fp_type nl_fp_var1;
+// CHECK: VarDecl {{.*}} nl_fp_var1 'nl_fp_type':'void (*)() 
__attribute__((clang_nonblocking))'
+nl_fp_talias nl_fp_var2;
+// CHECK: VarDecl {{.*}} nl_fp_var2 'nl_fp_talias':'void (*)() 
__attribute__((clang_nonblocking))'
+
+// On type of a FieldDecl
+struct Struct {
+   void (*nl_func_field)() [[clang::nonblocking]];
+// CHECK: FieldDecl {{.*}} nl_func_field 'void (*)() 
__attribute__((clang_nonblocking))'
+};
+
+// nonallocating should NOT be subsumed into nonblocking
+void nl1() [[clang::nonblocking]] [[clang::nonallocating]];
+// CHECK: FunctionDecl {{.*}} nl1 'void () __attribute__((clang_nonblocking)) 
__attribute__((clang_nonallocating))'
+
+void nl2() [[clang::nonallocating]] [[clang::nonblocking]];
+// CHECK: FunctionDecl {{.*}} nl2 'void () __attribute__((clang_nonblocking)) 
__attribute__((clang_nonallocating))'
+
+decltype(nl1) nl3;
+// CHECK: FunctionDecl {{.*}} nl3 'decltype(nl1)':'void () 
__attribute__((clang_nonblocking)) __attribute__((clang_nonallocating))'
+
+// Attribute propagates from base class virtual method to overrides.
+struct Base {
+   virtual void nb_method() [[clang::nonblocking]];
+};
+struct Derived : public Base {
+   void nb_method() override;
+   // CHECK: CXXMethodDecl {{.*}} nb_method 'void () 
__attribute__((clang_nonblocking))'
+};
+
+// Dependent expression
+template 
+struct Dependent {
+   void nb_method2() [[clang::nonblocking(V)]];
+   // CHECK: CXXMethodDecl {{.*}} nb_method2 'void () 
__attribute__((clang_nonblocking(V)))'
+};
+
+// --- Blocks ---
+
+// On the type of the VarDecl holding a BlockDecl
+void (^nl_block1)() [[clang::nonblocking]] = ^() [[clang::nonblocking]] {};
+// CHECK: VarDecl {{.*}} nl_block1 'void (^)() 
__attribute__((clang_nonblocking))'
+
+int (^nl_block2)() [[clang::nonblocking]] = ^() [[clang::nonblocking]] { 
return 0; };
+// CHECK: VarDecl {{.*}} nl_block2 'int (^)() 
__attribute__((clang_nonblocking))'
+
+// The operand of the CallExpr is an ImplicitCastExpr of a DeclRefExpr -> 
nl_block which hold the attribute
+static void blockCaller() { nl_block1(); }
+// CHECK: DeclRefExpr {{.*}} 'nl_block1' 'void (^)() 
__attribute__((clang_nonblocking))'
+
+// --- Lambdas ---
+
+// On the operator() of a lambda's CXXMethodDecl
+auto nl_lambda = []() [[clang::nonblocking]] {};
+// CHECK: CXXMethodDecl {{.*}} operator() 'void () const 
__attribute__((clang_nonblocking))' inline
+
+// 
=
+// Square brackets, false
+
+void nl_func_false() [[clang::blocking]];
+// CHECK: FunctionDecl {{.*}} nl_func_false 'void () 
__attribute__((clang_blocking))'
+
+// TODO: This exposes a bug where a type attribute is lost when inferring a 
lambda's
+// return type.
+auto nl_lambda_false = []() [[clang::blocking]] {};
+
+} // namespace square_brackets
+
+// 
=
+// GNU-style attribute, true
+
+// TODO: Duplicate more of the above for GNU-style attribute
+
+namespace gnu_style {
+
+// On the type of the FunctionDecl
+void nl_function() __attribute__((clang_nonblocking));
+// CHECK: FunctionDecl {{.*}} nl_function 'void () 
__attribute__((clang_nonblocking))'
+
+// Alternate placement on the FunctionDecl
+__attribute__((clang_nonblocking)) void nl_function();
+// CHECK: FunctionDecl {{.*}} nl_function 'void () 
__attribute__((clang_nonblocking))'
+
+// On the type of the VarDecl holding a function pointer
+void (*nl_func_a)() __attribute__((clang_nonblocking));
+// CHECK: VarDecl {{.*}} nl_fun

[clang] nonblocking/nonallocating attributes (was: nolock/noalloc) (PR #84983)

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


@@ -18347,7 +18347,7 @@ void Sema::SetFunctionBodyKind(Decl *D, SourceLocation 
Loc, FnBodyKind BodyKind,
   }
 }
 
-bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New,
+bool Sema::CheckOverridingFunctionAttributes(CXXMethodDecl *New,

cjappl wrote:

Works for me!

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


[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

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

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


[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

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

cjappl wrote:

Sorry, premature!!

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


[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

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

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


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

2024-05-16 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] Realtime Sanitizer: Introduce RADSan backend (PR #92460)

2024-05-16 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:

One question we have here: What is the SharedRuntimes vs StaticRuntimes? Why 
would we need to support both? This is one change we "eyeballed" based on the 
other sanitizers.

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   3   >