[clang] [compiler-rt] Realtime Sanitizer: Introduce RADSan backend (PR #92460)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 14:38:04 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 7115ed0fff027b65fa76fdfae215ed1382ed1473 3f28f74af90ee4c0d9fe2d9fdb1d91ba62c1441f -- compiler-rt/lib/radsan/radsan.cpp compiler-rt/lib/radsan/radsan.h compiler-rt/lib/radsan/radsan_context.cpp compiler-rt/lib/radsan/radsan_context.h compiler-rt/lib/radsan/radsan_interceptors.cpp compiler-rt/lib/radsan/radsan_interceptors.h compiler-rt/lib/radsan/radsan_preinit.cpp compiler-rt/lib/radsan/radsan_stack.cpp compiler-rt/lib/radsan/radsan_stack.h compiler-rt/lib/radsan/tests/radsan_test_context.cpp compiler-rt/lib/radsan/tests/radsan_test_functional.cpp compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp compiler-rt/lib/radsan/tests/radsan_test_main.cpp compiler-rt/lib/radsan/tests/radsan_test_utilities.h clang/include/clang/Driver/SanitizerArgs.h clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/Linux.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index cb96f9992a..662d14e679 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1511,9 +1511,9 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
}
}
- if(Sanitize.needsRadsanRt())
- {
- assert(Sanitize.needsSharedRt() && "Static sanitizer runtimes not supported");
+ if (Sanitize.needsRadsanRt()) {
+ assert(Sanitize.needsSharedRt() &&
+ "Static sanitizer runtimes not supported");
AddLinkSanitizerLibArgs(Args, CmdArgs, "radsan");
}
if (Sanitize.needsLsanRt())
diff --git a/compiler-rt/lib/radsan/radsan.cpp b/compiler-rt/lib/radsan/radsan.cpp
index e5117ac0d5..97069a0ac1 100644
--- a/compiler-rt/lib/radsan/radsan.cpp
+++ b/compiler-rt/lib/radsan/radsan.cpp
@@ -14,8 +14,8 @@
extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE void radsan_init() {
- radsan::InitializeInterceptors();
+SANITIZER_INTERFACE_ATTRIBUTE void radsan_init() {
+ radsan::InitializeInterceptors();
}
SANITIZER_INTERFACE_ATTRIBUTE void radsan_realtime_enter() {
diff --git a/compiler-rt/lib/radsan/radsan.h b/compiler-rt/lib/radsan/radsan.h
index b79933fde5..28682cb9c1 100644
--- a/compiler-rt/lib/radsan/radsan.h
+++ b/compiler-rt/lib/radsan/radsan.h
@@ -14,7 +14,7 @@
extern "C" {
-/** Initialise radsan interceptors.
+/** Initialise radsan interceptors.
A call to this method is added to the preinit array on Linux systems.
*/
@@ -43,7 +43,7 @@ SANITIZER_INTERFACE_ATTRIBUTE void radsan_off();
/** Re-enable all RADSan error reporting.
- The counterpart to `radsan_off`.
+ The counterpart to `radsan_off`.
*/
SANITIZER_INTERFACE_ATTRIBUTE void radsan_on();
diff --git a/compiler-rt/lib/radsan/radsan_interceptors.cpp b/compiler-rt/lib/radsan/radsan_interceptors.cpp
index f7fd005aa0..0719d32758 100644
--- a/compiler-rt/lib/radsan/radsan_interceptors.cpp
+++ b/compiler-rt/lib/radsan/radsan_interceptors.cpp
@@ -1,4 +1,5 @@
-//===--- radsan_interceptors.cpp - Realtime Sanitizer --------------*- C++ -*-===//
+//===--- radsan_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.
diff --git a/compiler-rt/lib/radsan/radsan_interceptors.h b/compiler-rt/lib/radsan/radsan_interceptors.h
index 30b37fb24a..9f020fa9d4 100644
--- a/compiler-rt/lib/radsan/radsan_interceptors.h
+++ b/compiler-rt/lib/radsan/radsan_interceptors.h
@@ -1,4 +1,5 @@
-//===--- radsan_interceptors.h - Realtime Sanitizer --------------*- C++ -*-===//
+//===--- radsan_interceptors.h - 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.
diff --git a/compiler-rt/lib/radsan/radsan_preinit.cpp b/compiler-rt/lib/radsan/radsan_preinit.cpp
index e5e92becb1..d3ee60f939 100644
--- a/compiler-rt/lib/radsan/radsan_preinit.cpp
+++ b/compiler-rt/lib/radsan/radsan_preinit.cpp
@@ -17,7 +17,7 @@
// exported.
// This code is linked into the main executable when -fsanitize=realtime is in
// the link flags. It can only use exported interface functions.
-__attribute__((section(".preinit_array"), used))
-void (*__local_radsan_preinit)(void) = radsan_init;
+__attribute__((section(".preinit_array"),
+ used)) void (*__local_radsan_preinit)(void) = radsan_init;
#endif
diff --git a/compiler-rt/lib/radsan/tests/radsan_test_context.cpp b/compiler-rt/lib/radsan/tests/radsan_test_context.cpp
index 91822df5a8..d389b60e8c 100644
--- a/compiler-rt/lib/radsan/tests/radsan_test_context.cpp
+++ b/compiler-rt/lib/radsan/tests/radsan_test_context.cpp
@@ -1,4 +1,5 @@
-//===--- radsan_test_context.cpp - Realtime Sanitizer --------------*- C++ -*-===//
+//===--- radsan_test_context.cpp - Realtime Sanitizer --------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp
index 20ed7c7542..e3b2e34fbe 100644
--- a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp
+++ b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp
@@ -1,4 +1,5 @@
-//===--- radsan_test_interceptors.cpp - Realtime Sanitizer --------------*- C++ -*-===//
+//===--- radsan_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.
@@ -202,7 +203,7 @@ TEST(TestRadsanInterceptors, CloseDiesWhenRealtime) {
TEST(TestRadsanInterceptors, FopenDiesWhenRealtime) {
auto Func = []() {
- FILE* Fd = fopen(TemporaryFilePath(), "w");
+ FILE *Fd = fopen(TemporaryFilePath(), "w");
EXPECT_THAT(Fd, Ne(nullptr));
};
ExpectRealtimeDeath(Func, "fopen");
@@ -211,7 +212,7 @@ TEST(TestRadsanInterceptors, FopenDiesWhenRealtime) {
}
TEST(TestRadsanInterceptors, FreadDiesWhenRealtime) {
- FILE* Fd = fopen(TemporaryFilePath(), "w");
+ FILE *Fd = fopen(TemporaryFilePath(), "w");
auto Func = [Fd]() {
char c{};
fread(&c, 1, 1, Fd);
@@ -224,9 +225,9 @@ TEST(TestRadsanInterceptors, FreadDiesWhenRealtime) {
}
TEST(TestRadsanInterceptors, FwriteDiesWhenRealtime) {
- FILE* Fd = fopen(TemporaryFilePath(), "w");
+ FILE *Fd = fopen(TemporaryFilePath(), "w");
ASSERT_NE(nullptr, Fd);
- const char* Message = "Hello, world!";
+ const char *Message = "Hello, world!";
auto Func = [&]() { fwrite(&Message, 1, 4, Fd); };
ExpectRealtimeDeath(Func, "fwrite");
ExpectNonRealtimeSurvival(Func);
@@ -234,7 +235,7 @@ TEST(TestRadsanInterceptors, FwriteDiesWhenRealtime) {
}
TEST(TestRadsanInterceptors, FcloseDiesWhenRealtime) {
- FILE* Fd = fopen(TemporaryFilePath(), "w");
+ FILE *Fd = fopen(TemporaryFilePath(), "w");
EXPECT_THAT(Fd, Ne(nullptr));
auto Func = [Fd]() { fclose(Fd); };
ExpectRealtimeDeath(Func, "fclose");
@@ -249,7 +250,7 @@ TEST(TestRadsanInterceptors, PutsDiesWhenRealtime) {
}
TEST(TestRadsanInterceptors, FputsDiesWhenRealtime) {
- FILE* Fd = fopen(TemporaryFilePath(), "w");
+ FILE *Fd = fopen(TemporaryFilePath(), "w");
ASSERT_THAT(Fd, Ne(nullptr)) << errno;
auto Func = [Fd]() { fputs("Hello, world!\n", Fd); };
ExpectRealtimeDeath(Func);
diff --git a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h
index 4a2510d5f8..8c2821e982 100644
--- a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h
+++ b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h
@@ -1,4 +1,5 @@
-//===--- radsan_test_utilities.h - Realtime Sanitizer --------------*- C++ -*-===//
+//===--- radsan_test_utilities.h - 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.
@@ -10,15 +11,13 @@
#pragma once
-#include "gmock/gmock.h"
#include "radsan.h"
+#include "gmock/gmock.h"
#include <string>
namespace radsan_testing {
-template <typename Function>
-void RealtimeInvoke(Function &&Func)
-{
+template <typename Function> void RealtimeInvoke(Function &&Func) {
radsan_realtime_enter();
std::forward<Function>(Func)();
radsan_realtime_exit();
``````````
</details>
https://github.com/llvm/llvm-project/pull/92460
More information about the cfe-commits
mailing list