From 4102625380823e58d7b13f01b5bd979a29bce19e Mon Sep 17 00:00:00 2001 From: davidtrevelyan Date: Sat, 26 Oct 2024 13:06:11 +0100 Subject: [PATCH] [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: https://github.com/llvm/llvm-project/pull/106754). Given that it hasn't been released in version 20 yet, am I correct in considering this to not be a breaking change? --- clang/lib/CodeGen/CodeGenFunction.cpp | 2 +- clang/test/CodeGen/rtsan_attribute_inserted.c | 2 +- clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c | 2 +- compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp | 4 ++-- llvm/docs/LangRef.rst | 2 +- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 2 +- llvm/include/llvm/IR/Attributes.td | 4 ++-- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 ++-- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 4 ++-- llvm/lib/IR/Verifier.cpp | 4 ++-- llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp | 6 +++--- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 2 +- llvm/test/Bitcode/attributes.ll | 4 ++-- llvm/test/Bitcode/compatibility.ll | 6 +++--- .../{rtsan_unsafe.ll => rtsan_blocking.ll} | 4 ++-- llvm/test/Verifier/rtsan-attrs.ll | 4 ++-- 16 files changed, 28 insertions(+), 28 deletions(-) rename llvm/test/Instrumentation/RealtimeSanitizer/{rtsan_unsafe.ll => rtsan_blocking.ll} (87%) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 573ced0857d5f5..6ead45793742d6 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -852,7 +852,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, 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); + Fn->addFnAttr(llvm::Attribute::SanitizeRealtimeBlocking); } // 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 b21ecb6b6b06a9..cebfe43c81234c 100644 --- a/clang/test/CodeGen/rtsan_attribute_inserted.c +++ b/clang/test/CodeGen/rtsan_attribute_inserted.c @@ -8,4 +8,4 @@ float process(float *a) [[clang::nonblocking]] { return *a; } int spinlock(int *a) [[clang::blocking]] { return *a; } // CHECK: @spinlock{{.*}} #1 { // CHECK: attributes #1 = { -// CHECK-SAME: {{.*sanitize_realtime_unsafe .*}} +// CHECK-SAME: {{.*sanitize_realtime_blocking .*}} diff --git a/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c b/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c index 0f43007c5e4c16..86305080c94ace 100644 --- a/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c +++ b/clang/test/CodeGen/rtsan_no_attribute_sanitizer_disabled.c @@ -5,4 +5,4 @@ int spinlock(int *a) [[clang::blocking]] { return *a; } // Without the -fsanitize=realtime flag, we shouldn't attach the attributes. // CHECK-NOT: {{.*sanitize_realtime .*}} -// CHECK-NOT: {{.*sanitize_realtime_unsafe .*}} +// CHECK-NOT: {{.*sanitize_realtime_blocking .*}} diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp index 9e455f0326a549..ed9ee4ded7b059 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_functional.cpp @@ -204,11 +204,11 @@ TEST(TestRtsan, ThrowingAnExceptionDiesWhenRealtime) { TEST(TestRtsan, DoesNotDieIfTurnedOff) { std::mutex mutex; - auto RealtimeUnsafeFunc = [&]() { + auto RealtimeBlockingFunc = [&]() { __rtsan_disable(); mutex.lock(); mutex.unlock(); __rtsan_enable(); }; - RealtimeInvoke(RealtimeUnsafeFunc); + RealtimeInvoke(RealtimeBlockingFunc); } diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index b83675c6ed97aa..f9ec33da1b651b 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -2334,7 +2334,7 @@ example: This attribute indicates that RealtimeSanitizer checks (realtime safety analysis - no allocations, syscalls or exceptions) are enabled for this function. -``sanitize_realtime_unsafe`` +``sanitize_realtime_blocking`` This attribute indicates that RealtimeSanitizer should error immediately if the attributed function is called during invocation of a function attributed with ``sanitize_realtime``. diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 08574cc356e514..41a6447356c23b 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -768,7 +768,7 @@ enum AttributeKindCodes { ATTR_KIND_INITIALIZES = 94, ATTR_KIND_HYBRID_PATCHABLE = 95, ATTR_KIND_SANITIZE_REALTIME = 96, - ATTR_KIND_SANITIZE_REALTIME_UNSAFE = 97, + ATTR_KIND_SANITIZE_REALTIME_BLOCKING = 97, ATTR_KIND_CORO_ELIDE_SAFE = 98, ATTR_KIND_NO_EXT = 99, ATTR_KIND_NO_DIVERGENCE_SOURCE = 100, diff --git a/llvm/include/llvm/IR/Attributes.td b/llvm/include/llvm/IR/Attributes.td index b6d36a5f7ae4fb..49f4527bde66e7 100644 --- a/llvm/include/llvm/IR/Attributes.td +++ b/llvm/include/llvm/IR/Attributes.td @@ -334,7 +334,7 @@ def SanitizeRealtime : EnumAttr<"sanitize_realtime", IntersectPreserve, [FnAttr] /// RealtimeSanitizer should error if a real-time unsafe function is invoked /// during a real-time sanitized function (see `sanitize_realtime`). -def SanitizeRealtimeUnsafe : EnumAttr<"sanitize_realtime_unsafe", IntersectPreserve, [FnAttr]>; +def SanitizeRealtimeBlocking : EnumAttr<"sanitize_realtime_blocking", IntersectPreserve, [FnAttr]>; /// Speculative Load Hardening is enabled. /// @@ -430,7 +430,7 @@ def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; -def : CompatRule<"isEqual">; +def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; def : CompatRule<"isEqual">; diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 4aea059551dedc..446c98c8cecd88 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2165,8 +2165,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) { return Attribute::SanitizeNumericalStability; case bitc::ATTR_KIND_SANITIZE_REALTIME: return Attribute::SanitizeRealtime; - case bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE: - return Attribute::SanitizeRealtimeUnsafe; + case bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING: + return Attribute::SanitizeRealtimeBlocking; case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING: return Attribute::SpeculativeLoadHardening; case bitc::ATTR_KIND_SWIFT_ERROR: diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index d9002149fba55a..ee9cc4b6e0c0eb 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -853,8 +853,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) { return bitc::ATTR_KIND_SANITIZE_NUMERICAL_STABILITY; case Attribute::SanitizeRealtime: return bitc::ATTR_KIND_SANITIZE_REALTIME; - case Attribute::SanitizeRealtimeUnsafe: - return bitc::ATTR_KIND_SANITIZE_REALTIME_UNSAFE; + case Attribute::SanitizeRealtimeBlocking: + return bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING; case Attribute::SpeculativeLoadHardening: return bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING; case Attribute::SwiftError: diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 60e65392218dad..ee807ca13787d5 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2235,9 +2235,9 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, } Check(!(Attrs.hasFnAttr(Attribute::SanitizeRealtime) && - Attrs.hasFnAttr(Attribute::SanitizeRealtimeUnsafe)), + Attrs.hasFnAttr(Attribute::SanitizeRealtimeBlocking)), "Attributes " - "'sanitize_realtime and sanitize_realtime_unsafe' are incompatible!", + "'sanitize_realtime and sanitize_realtime_blocking' are incompatible!", V); if (Attrs.hasFnAttr(Attribute::OptimizeForDebugging)) { diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index c4cb72ab2e4da9..88cb04695217d5 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -69,7 +69,7 @@ static PreservedAnalyses runSanitizeRealtime(Function &Fn) { return rtsanPreservedCFGAnalyses(); } -static PreservedAnalyses runSanitizeRealtimeUnsafe(Function &Fn) { +static PreservedAnalyses runSanitizeRealtimeBlocking(Function &Fn) { IRBuilder<> Builder(&Fn.front().front()); Value *Name = Builder.CreateGlobalString(demangle(Fn.getName())); insertCallAtFunctionEntryPoint(Fn, "__rtsan_notify_blocking_call", {Name}); @@ -84,8 +84,8 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &Fn, if (Fn.hasFnAttribute(Attribute::SanitizeRealtime)) return runSanitizeRealtime(Fn); - if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) - return runSanitizeRealtimeUnsafe(Fn); + if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeBlocking)) + return runSanitizeRealtimeBlocking(Fn); return PreservedAnalyses::all(); } diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 15b26a38cc28ef..ed4ad15e5ab695 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -953,7 +953,7 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs, case Attribute::SanitizeHWAddress: case Attribute::SanitizeMemTag: case Attribute::SanitizeRealtime: - case Attribute::SanitizeRealtimeUnsafe: + case Attribute::SanitizeRealtimeBlocking: case Attribute::SpeculativeLoadHardening: case Attribute::StackProtect: case Attribute::StackProtectReq: diff --git a/llvm/test/Bitcode/attributes.ll b/llvm/test/Bitcode/attributes.ll index 737f49aa86a7ba..492de663884df4 100644 --- a/llvm/test/Bitcode/attributes.ll +++ b/llvm/test/Bitcode/attributes.ll @@ -512,7 +512,7 @@ define void @f92() sanitize_realtime } ; CHECK: define void @f93() #54 -define void @f93() sanitize_realtime_unsafe { +define void @f93() sanitize_realtime_blocking { ret void; } @@ -616,7 +616,7 @@ define void @initializes(ptr initializes((-4, 0), (4, 8)) %a) { ; CHECK: attributes #51 = { uwtable(sync) } ; CHECK: attributes #52 = { nosanitize_bounds } ; CHECK: attributes #53 = { sanitize_realtime } -; CHECK: attributes #54 = { sanitize_realtime_unsafe } +; CHECK: attributes #54 = { sanitize_realtime_blocking } ; CHECK: attributes [[FNRETTHUNKEXTERN]] = { fn_ret_thunk_extern } ; CHECK: attributes [[SKIPPROFILE]] = { skipprofile } ; CHECK: attributes [[OPTDEBUG]] = { optdebug } diff --git a/llvm/test/Bitcode/compatibility.ll b/llvm/test/Bitcode/compatibility.ll index 280c3a99d7535f..a849789da536ac 100644 --- a/llvm/test/Bitcode/compatibility.ll +++ b/llvm/test/Bitcode/compatibility.ll @@ -2048,8 +2048,8 @@ declare void @f.sanitize_numerical_stability() sanitize_numerical_stability declare void @f.sanitize_realtime() sanitize_realtime ; CHECK: declare void @f.sanitize_realtime() #52 -declare void @f.sanitize_realtime_unsafe() sanitize_realtime_unsafe -; CHECK: declare void @f.sanitize_realtime_unsafe() #53 +declare void @f.sanitize_realtime_blocking() sanitize_realtime_blocking +; CHECK: declare void @f.sanitize_realtime_blocking() #53 ; CHECK: declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan)) declare nofpclass(snan) float @nofpclass_snan(float nofpclass(snan)) @@ -2183,7 +2183,7 @@ define float @nofpclass_callsites(float %arg, { float } %arg1) { ; CHECK: attributes #50 = { allockind("alloc,uninitialized") } ; CHECK: attributes #51 = { sanitize_numerical_stability } ; CHECK: attributes #52 = { sanitize_realtime } -; CHECK: attributes #53 = { sanitize_realtime_unsafe } +; CHECK: attributes #53 = { sanitize_realtime_blocking } ; CHECK: attributes #54 = { builtin } ;; Metadata diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_blocking.ll similarity index 87% rename from llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll rename to llvm/test/Instrumentation/RealtimeSanitizer/rtsan_blocking.ll index 5abf5de3044816..80eb28c3923c2d 100644 --- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_blocking.ll @@ -25,7 +25,7 @@ define noundef i32 @main() #2 { ret i32 0 } -attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } +attributes #0 = { mustprogress noinline sanitize_realtime_blocking optnone ssp uwtable(sync) } ;. -; CHECK: attributes #[[ATTR0]] = { mustprogress noinline optnone sanitize_realtime_unsafe ssp uwtable(sync) } +; CHECK: attributes #[[ATTR0]] = { mustprogress noinline optnone sanitize_realtime_blocking ssp uwtable(sync) } ;. diff --git a/llvm/test/Verifier/rtsan-attrs.ll b/llvm/test/Verifier/rtsan-attrs.ll index fcc44d8d63c1de..c813266b434f8c 100644 --- a/llvm/test/Verifier/rtsan-attrs.ll +++ b/llvm/test/Verifier/rtsan-attrs.ll @@ -1,9 +1,9 @@ ; RUN: not llvm-as -disable-output %s 2>&1 | FileCheck %s -; CHECK: Attributes 'sanitize_realtime and sanitize_realtime_unsafe' are incompatible! +; CHECK: Attributes 'sanitize_realtime and sanitize_realtime_blocking' are incompatible! ; CHECK-NEXT: ptr @sanitize_unsafe define void @sanitize_unsafe() #0 { ret void } -attributes #0 = { sanitize_realtime sanitize_realtime_unsafe } +attributes #0 = { sanitize_realtime sanitize_realtime_blocking }