From 6b85c3b09724a9bdfc93c735f47b949867ff5afb Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Sat, 31 Aug 2024 17:20:47 +0100 Subject: [PATCH] Add sanitize_realtime_unsafe attr to [[clang::blocking]] function IR --- clang/lib/CodeGen/CodeGenFunction.cpp | 2 ++ clang/test/CodeGen/rtsan_attribute_inserted.c | 10 +++++++--- .../CodeGen/rtsan_no_attribute_sanitizer_disabled.c | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index fae26d11feca2..e2f87842700de 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -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. diff --git a/clang/test/CodeGen/rtsan_attribute_inserted.c b/clang/test/CodeGen/rtsan_attribute_inserted.c index 05a1d9a8c2047..b21ecb6b6b06a 100644 --- a/clang/test/CodeGen/rtsan_attribute_inserted.c +++ b/clang/test/CodeGen/rtsan_attribute_inserted.c @@ -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 .*}} diff --git a/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c b/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c index 43ad6ed1a429e..0f43007c5e4c1 100644 --- a/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c +++ b/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c @@ -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 .*}}