-
Couldn't load subscription status.
- Fork 1
[DRAFT] Move to LLVM passmanager pass [DO NOT MERGE DIRECTLY] #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsanitize=realtime -emit-llvm -o - %s | FileCheck %s | ||
|
|
||
| // The first instruction after the function is entred should be a call to | ||
| // enable the realtime sanitizer stack | ||
|
|
||
| int foo(int *a) [[clang::nonblocking]] { return *a; } | ||
| // CHECK: define{{.*}}foo | ||
| // CHECK-NEXT: entry: | ||
| // CHECK-NEXT: call{{.*}}__rtsan_realtime_enter |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -fsanitize=realtime -emit-llvm -o - %s | FileCheck %s | ||
|
|
||
| // __rtsan_realtime_exit should be inserted at all function returns | ||
|
|
||
| int bar(int* x) [[clang::nonblocking]] { | ||
| return *x; | ||
| } | ||
| // CHECK: call{{.*}}__rtsan_realtime_exit | ||
| // CHECK-NEXT: ret | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -o - | FileCheck %s | ||
|
|
||
| float process(float *a) [[clang::nonblocking]] { return *a; } | ||
|
|
||
| // CHECK: define{{.*}}process{{.*}}#0 { | ||
| // CHECK: attributes #0 = { | ||
| // CHECK-SAME: {{.*nonblocking.*}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang -O1 -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang -O3 -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -o - | FileCheck %s | ||
| // RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -flto=thin -o - | FileCheck %s | ||
| // RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -flto=thin -o - | FileCheck %s | ||
| // RUN: %clang -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -flto -o - | FileCheck %s | ||
| // RUN: %clang -O2 -target x86_64-unknown-linux -fsanitize=realtime %s -S -emit-llvm -flto -o - | FileCheck %s | ||
|
|
||
| // Ensure the rtsan_realtime calls are never optimized away | ||
|
|
||
| int foo(int *a) [[clang::nonblocking]] { return *a; } | ||
| // CHECK: __rtsan_realtime_enter | ||
| // CHECK: __rtsan_realtime_exit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // RUN: %clangxx -fsanitize=realtime %s -o %t | ||
| // RUN: not %run %t 2>&1 | FileCheck %s | ||
| // UNSUPPORTED: ios | ||
|
|
||
| // Intent: Ensure that an intercepted call in a [[clang::nonblocking]] function | ||
| // is flagged as an error. Basic smoke test. | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); } | ||
|
|
||
| int main() { | ||
| violation(); | ||
| return 0; | ||
| // CHECK: {{.*Real-time violation.*}} | ||
| // CHECK: {{.*malloc*}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // RUN: %clangxx %s -o %t | ||
| // RUN: %run %t 2>&1 | FileCheck %s | ||
| // UNSUPPORTED: ios | ||
|
|
||
| // Intent: Ensure [[clang::nonblocking]] has no impact if -fsanitize=realtime is not used | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| // In this test, we don't use the -fsanitize=realtime flag, so nothing | ||
| // should happen here | ||
| void violation() [[clang::nonblocking]] { void *Ptr = malloc(2); } | ||
|
|
||
| int main() { | ||
| printf("Starting run\n"); | ||
| violation(); | ||
| printf("No violations ended the program\n"); | ||
| return 0; | ||
| // CHECK: {{.*Starting run.*}} | ||
| // CHECK NOT: {{.*Real-time violation.*}} | ||
| // CHECK NOT: {{.*malloc*}} | ||
| // CHECK: {{.*No violations ended the program.*}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===--------- Definition of the RealtimeSanitizer class ---------*- 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZER_H | ||
| #define LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZER_H | ||
|
|
||
| #include "llvm/IR/PassManager.h" | ||
| #include "llvm/Transforms/Instrumentation/RealtimeSanitizerOptions.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| struct RealtimeSanitizerOptions {}; | ||
|
|
||
| class RealtimeSanitizerPass : public PassInfoMixin<RealtimeSanitizerPass> { | ||
| public: | ||
| RealtimeSanitizerPass(const RealtimeSanitizerOptions &Options); | ||
| PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM); | ||
|
|
||
| static bool isRequired() { return true; } | ||
|
|
||
| private: | ||
| RealtimeSanitizerOptions Options{}; | ||
| }; | ||
|
|
||
| } // namespace llvm | ||
|
|
||
| #endif // LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZER_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //===--------- Definition of the RealtimeSanitizer options -------*- 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 defines data types used to set Realtime Sanitizer options. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZEROPTIONS_H | ||
| #define LLVM_TRANSFORMS_INSTRUMENTATION_REALTIMESANITIZEROPTIONS_H | ||
|
||
|
|
||
| namespace llvm {} // namespace llvm | ||
|
||
|
|
||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have the llvm work done (in the earlier commit), we now check if the sanitizer is enabled, and insert this "Pass" that we defined in LLVM.
As for where it should live
registerScalarOptimizerLateEPCallbackwas my guess, as it says it is "very late in the pipeline" but we likely have to ask reviewers what is appropriate