Skip to content

Commit 4102625

Browse files
[rtsan][llvm][NFC] Rename sanitize_realtime_unsafe attr to sanitize_realtime_blocking (#113155)
# What This PR renames the newly-introduced llvm attribute `sanitize_realtime_unsafe` to `sanitize_realtime_blocking`. Likewise, sibling variables such as `SanitizeRealtimeUnsafe` are renamed to `SanitizeRealtimeBlocking` respectively. There are no other functional changes. # Why? - There are a number of problems that can cause a function to be real-time "unsafe", - we wish to communicate what problems rtsan detects and *why* they're unsafe, and - a generic "unsafe" attribute is, in our opinion, too broad a net - which may lead to future implementations that need extra contextual information passed through them in order to communicate meaningful reasons to users. - We want to avoid this situation and make the runtime library boundary API/ABI as simple as possible, and - we believe that restricting the scope of attributes to names like `sanitize_realtime_blocking` is an effective means of doing so. We also feel that the symmetry between `[[clang::blocking]]` and `sanitize_realtime_blocking` is easier to follow as a developer. # Concerns - I'm aware that the LLVM attribute `sanitize_realtime_unsafe` has been part of the tree for a few weeks now (introduced here: #106754). Given that it hasn't been released in version 20 yet, am I correct in considering this to not be a breaking change?
1 parent 69ead94 commit 4102625

File tree

16 files changed

+28
-28
lines changed

16 files changed

+28
-28
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
852852
if (Fe.Effect.kind() == FunctionEffect::Kind::NonBlocking)
853853
Fn->addFnAttr(llvm::Attribute::SanitizeRealtime);
854854
else if (Fe.Effect.kind() == FunctionEffect::Kind::Blocking)
855-
Fn->addFnAttr(llvm::Attribute::SanitizeRealtimeUnsafe);
855+
Fn->addFnAttr(llvm::Attribute::SanitizeRealtimeBlocking);
856856
}
857857

858858
// Apply fuzzing attribute to the function.

clang/test/CodeGen/rtsan_attribute_inserted.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ float process(float *a) [[clang::nonblocking]] { return *a; }
88
int spinlock(int *a) [[clang::blocking]] { return *a; }
99
// CHECK: @spinlock{{.*}} #1 {
1010
// CHECK: attributes #1 = {
11-
// CHECK-SAME: {{.*sanitize_realtime_unsafe .*}}
11+
// CHECK-SAME: {{.*sanitize_realtime_blocking .*}}

clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ int spinlock(int *a) [[clang::blocking]] { return *a; }
55

66
// Without the -fsanitize=realtime flag, we shouldn't attach the attributes.
77
// CHECK-NOT: {{.*sanitize_realtime .*}}
8-
// CHECK-NOT: {{.*sanitize_realtime_unsafe .*}}
8+
// CHECK-NOT: {{.*sanitize_realtime_blocking .*}}

compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ TEST(TestRtsan, ThrowingAnExceptionDiesWhenRealtime) {
204204

205205
TEST(TestRtsan, DoesNotDieIfTurnedOff) {
206206
std::mutex mutex;
207-
auto RealtimeUnsafeFunc = [&]() {
207+
auto RealtimeBlockingFunc = [&]() {
208208
__rtsan_disable();
209209
mutex.lock();
210210
mutex.unlock();
211211
__rtsan_enable();
212212
};
213-
RealtimeInvoke(RealtimeUnsafeFunc);
213+
RealtimeInvoke(RealtimeBlockingFunc);
214214
}

llvm/docs/LangRef.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ example:
23342334
This attribute indicates that RealtimeSanitizer checks
23352335
(realtime safety analysis - no allocations, syscalls or exceptions) are enabled
23362336
for this function.
2337-
``sanitize_realtime_unsafe``
2337+
``sanitize_realtime_blocking``
23382338
This attribute indicates that RealtimeSanitizer should error immediately
23392339
if the attributed function is called during invocation of a function
23402340
attributed with ``sanitize_realtime``.

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ enum AttributeKindCodes {
768768
ATTR_KIND_INITIALIZES = 94,
769769
ATTR_KIND_HYBRID_PATCHABLE = 95,
770770
ATTR_KIND_SANITIZE_REALTIME = 96,
771-
ATTR_KIND_SANITIZE_REALTIME_UNSAFE = 97,
771+
ATTR_KIND_SANITIZE_REALTIME_BLOCKING = 97,
772772
ATTR_KIND_CORO_ELIDE_SAFE = 98,
773773
ATTR_KIND_NO_EXT = 99,
774774
ATTR_KIND_NO_DIVERGENCE_SOURCE = 100,

llvm/include/llvm/IR/Attributes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def SanitizeRealtime : EnumAttr<"sanitize_realtime", IntersectPreserve, [FnAttr]
334334

335335
/// RealtimeSanitizer should error if a real-time unsafe function is invoked
336336
/// during a real-time sanitized function (see `sanitize_realtime`).
337-
def SanitizeRealtimeUnsafe : EnumAttr<"sanitize_realtime_unsafe", IntersectPreserve, [FnAttr]>;
337+
def SanitizeRealtimeBlocking : EnumAttr<"sanitize_realtime_blocking", IntersectPreserve, [FnAttr]>;
338338

339339
/// Speculative Load Hardening is enabled.
340340
///
@@ -430,7 +430,7 @@ def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
430430
def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
431431
def : CompatRule<"isEqual<SanitizeNumericalStabilityAttr>">;
432432
def : CompatRule<"isEqual<SanitizeRealtimeAttr>">;
433-
def : CompatRule<"isEqual<SanitizeRealtimeUnsafeAttr>">;
433+
def : CompatRule<"isEqual<SanitizeRealtimeBlockingAttr>">;
434434
def : CompatRule<"isEqual<SafeStackAttr>">;
435435
def : CompatRule<"isEqual<ShadowCallStackAttr>">;
436436
def : CompatRule<"isEqual<UseSampleProfileAttr>">;

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,8 +2165,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
21652165
return Attribute::SanitizeNumericalStability;
21662166
case bitc::ATTR_KIND_SANITIZE_REALTIME:
21672167
return Attribute::SanitizeRealtime;
2168-
case bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE:
2169-
return Attribute::SanitizeRealtimeUnsafe;
2168+
case bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING:
2169+
return Attribute::SanitizeRealtimeBlocking;
21702170
case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING:
21712171
return Attribute::SpeculativeLoadHardening;
21722172
case bitc::ATTR_KIND_SWIFT_ERROR:

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
853853
return bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY;
854854
case Attribute::SanitizeRealtime:
855855
return bitc::ATTR_KIND_SANITIZE_REALTIME;
856-
case Attribute::SanitizeRealtimeUnsafe:
857-
return bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE;
856+
case Attribute::SanitizeRealtimeBlocking:
857+
return bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING;
858858
case Attribute::SpeculativeLoadHardening:
859859
return bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING;
860860
case Attribute::SwiftError:

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,9 +2235,9 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
22352235
}
22362236

22372237
Check(!(Attrs.hasFnAttr(Attribute::SanitizeRealtime) &&
2238-
Attrs.hasFnAttr(Attribute::SanitizeRealtimeUnsafe)),
2238+
Attrs.hasFnAttr(Attribute::SanitizeRealtimeBlocking)),
22392239
"Attributes "
2240-
"'sanitize_realtime and sanitize_realtime_unsafe' are incompatible!",
2240+
"'sanitize_realtime and sanitize_realtime_blocking' are incompatible!",
22412241
V);
22422242

22432243
if (Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) {

llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static PreservedAnalyses runSanitizeRealtime(Function &Fn) {
6969
return rtsanPreservedCFGAnalyses();
7070
}
7171

72-
static PreservedAnalyses runSanitizeRealtimeUnsafe(Function &Fn) {
72+
static PreservedAnalyses runSanitizeRealtimeBlocking(Function &Fn) {
7373
IRBuilder<> Builder(&Fn.front().front());
7474
Value *Name = Builder.CreateGlobalString(demangle(Fn.getName()));
7575
insertCallAtFunctionEntryPoint(Fn, "__rtsan_notify_blocking_call", {Name});
@@ -84,8 +84,8 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &Fn,
8484
if (Fn.hasFnAttribute(Attribute::SanitizeRealtime))
8585
return runSanitizeRealtime(Fn);
8686

87-
if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe))
88-
return runSanitizeRealtimeUnsafe(Fn);
87+
if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeBlocking))
88+
return runSanitizeRealtimeBlocking(Fn);
8989

9090
return PreservedAnalyses::all();
9191
}

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
953953
case Attribute::SanitizeHWAddress:
954954
case Attribute::SanitizeMemTag:
955955
case Attribute::SanitizeRealtime:
956-
case Attribute::SanitizeRealtimeUnsafe:
956+
case Attribute::SanitizeRealtimeBlocking:
957957
case Attribute::SpeculativeLoadHardening:
958958
case Attribute::StackProtect:
959959
case Attribute::StackProtectReq:

llvm/test/Bitcode/attributes.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ define void @f92() sanitize_realtime
512512
}
513513

514514
; CHECK: define void @f93() #54
515-
define void @f93() sanitize_realtime_unsafe {
515+
define void @f93() sanitize_realtime_blocking {
516516
ret void;
517517
}
518518

@@ -616,7 +616,7 @@ define void @initializes(ptr initializes((-4, 0), (4, 8)) %a) {
616616
; CHECK: attributes #51 = { uwtable(sync) }
617617
; CHECK: attributes #52 = { nosanitize_bounds }
618618
; CHECK: attributes #53 = { sanitize_realtime }
619-
; CHECK: attributes #54 = { sanitize_realtime_unsafe }
619+
; CHECK: attributes #54 = { sanitize_realtime_blocking }
620620
; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern }
621621
; CHECK: attributes [[SKIPPROFILE]] = { skipprofile }
622622
; CHECK: attributes [[OPTDEBUG]] = { optdebug }

llvm/test/Bitcode/compatibility.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,8 +2048,8 @@ declare void @f.sanitize_numerical_stability() sanitize_numerical_stability
20482048
declare void @f.sanitize_realtime() sanitize_realtime
20492049
; CHECK: declare void @f.sanitize_realtime() #52
20502050

2051-
declare void @f.sanitize_realtime_unsafe() sanitize_realtime_unsafe
2052-
; CHECK: declare void @f.sanitize_realtime_unsafe() #53
2051+
declare void @f.sanitize_realtime_blocking() sanitize_realtime_blocking
2052+
; CHECK: declare void @f.sanitize_realtime_blocking() #53
20532053

20542054
; CHECK: declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
20552055
declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan))
@@ -2183,7 +2183,7 @@ define float @nofpclass_callsites(float %arg, { float } %arg1) {
21832183
; CHECK: attributes #50 = { allockind("alloc,uninitialized") }
21842184
; CHECK: attributes #51 = { sanitize_numerical_stability }
21852185
; CHECK: attributes #52 = { sanitize_realtime }
2186-
; CHECK: attributes #53 = { sanitize_realtime_unsafe }
2186+
; CHECK: attributes #53 = { sanitize_realtime_blocking }
21872187
; CHECK: attributes #54 = { builtin }
21882188

21892189
;; Metadata

llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll renamed to llvm/test/Instrumentation/RealtimeSanitizer/rtsan_blocking.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define noundef i32 @main() #2 {
2525
ret i32 0
2626
}
2727

28-
attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) }
28+
attributes #0 = { mustprogress noinline sanitize_realtime_blocking optnone ssp uwtable(sync) }
2929
;.
30-
; CHECK: attributes #[[ATTR0]] = { mustprogress noinline optnone sanitize_realtime_unsafe ssp uwtable(sync) }
30+
; CHECK: attributes #[[ATTR0]] = { mustprogress noinline optnone sanitize_realtime_blocking ssp uwtable(sync) }
3131
;.

llvm/test/Verifier/rtsan-attrs.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s
22

3-
; CHECK: Attributes 'sanitize_realtime and sanitize_realtime_unsafe' are incompatible!
3+
; CHECK: Attributes 'sanitize_realtime and sanitize_realtime_blocking' are incompatible!
44
; CHECK-NEXT: ptr @sanitize_unsafe
55
define void @sanitize_unsafe() #0 {
66
ret void
77
}
88

9-
attributes #0 = { sanitize_realtime sanitize_realtime_unsafe }
9+
attributes #0 = { sanitize_realtime sanitize_realtime_blocking }

0 commit comments

Comments
 (0)