Skip to content

[clang][rtsan] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR #111055

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

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
for (const FunctionEffectWithCondition &Fe : FD->getFunctionEffects()) {
if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
else if (Fe.Effect.kind() == FunctionEffect::Kind::Blocking)
Fn->addFnAttr(llvm::Attribute::SanitizeRealtimeUnsafe);
}

// Apply fuzzing attribute to the function.
Expand Down
10 changes: 7 additions & 3 deletions clang/test/CodeGen/rtsan_attribute_inserted.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=realtime %s -emit-llvm -o - %s | FileCheck %s

float process(float *a) [[clang::nonblocking]] { return *a; }

// CHECK-LABEL: @process{{.*}}#0 {
// CHECK: @process{{.*}} #0 {
// CHECK: attributes #0 = {
// CHECK-SAME: {{.*sanitize_realtime.*}}
// CHECK-SAME: {{.*sanitize_realtime .*}}

int spinlock(int *a) [[clang::blocking]] { return *a; }
// CHECK: @spinlock{{.*}} #1 {
// CHECK: attributes #1 = {
// CHECK-SAME: {{.*sanitize_realtime_unsafe .*}}
6 changes: 4 additions & 2 deletions clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s

float process(float *a) [[clang::nonblocking]] { return *a; }
int spinlock(int *a) [[clang::blocking]] { return *a; }

// Without the -fsanitize=realtime flag, we shouldn't attach the attribute.
// CHECK-NOT: {{.*sanitize_realtime.*}}
// Without the -fsanitize=realtime flag, we shouldn't attach the attributes.
// CHECK-NOT: {{.*sanitize_realtime .*}}
// CHECK-NOT: {{.*sanitize_realtime_unsafe .*}}
Loading