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)) {

0 commit comments

Comments
 (0)