From ddca9d5c3328fade6ceb9780e6b1cc8457bb511e Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Fri, 30 Aug 2024 15:14:24 +0100 Subject: [PATCH 01/10] Implement sanitize_realtime_unsafe Pass --- .../Instrumentation/RealtimeSanitizer.cpp | 28 +++++++++++++++++-- .../RealtimeSanitizer/rtsan_unsafe.ll | 16 +++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index 7854cf4f2c625..ae60122c13b07 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -45,6 +45,26 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn, insertCallBeforeInstruction(Fn, I, InsertFnName); } +static PreservedAnalyses rtsanPreservedAnalyses() { + PreservedAnalyses PA; + PA.preserveSet(); + return PA; +} + +static void transformRealtimeUnsafeFunction(Function &F) { + IRBuilder<> Builder(&F.front().front()); + Value *NameArg = Builder.CreateGlobalString(F.getName()); + + FunctionType *FuncType = + FunctionType::get(Type::getVoidTy(F.getContext()), + {PointerType::getUnqual(F.getContext())}, false); + + FunctionCallee Func = F.getParent()->getOrInsertFunction( + "__rtsan_expect_not_realtime", FuncType); + + Builder.CreateCall(Func, {NameArg}); +} + RealtimeSanitizerPass::RealtimeSanitizerPass( const RealtimeSanitizerOptions &Options) {} @@ -53,10 +73,12 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F, if (F.hasFnAttribute(Attribute::SanitizeRealtime)) { insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter"); insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit"); + return rtsanPreservedAnalyses(); + } - PreservedAnalyses PA; - PA.preserveSet(); - return PA; + if (F.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { + transformRealtimeUnsafeFunction(F); + return rtsanPreservedAnalyses(); } return PreservedAnalyses::all(); diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll new file mode 100644 index 0000000000000..646a9a0e22e21 --- /dev/null +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll @@ -0,0 +1,16 @@ +; RUN: opt < %s -passes=rtsan -S | FileCheck %s + +define void @blocking_function() #0 { + ret void +} + +define noundef i32 @main() #2 { + call void @blocking_function() #4 + ret i32 0 +} + +attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } + +; RealtimeSanitizer pass should insert __rtsan_expect_not_realtime at function entrypoint +; CHECK-LABEL: @blocking_function() +; CHECK-NEXT: call{{.*}}@__rtsan_expect_not_realtime({{ptr .*}}) From 144c637137e8c135ead07c76b426cd89e9bb4fff Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Fri, 30 Aug 2024 16:24:06 +0100 Subject: [PATCH 02/10] Rename rtsan pass functions to be more explicit --- .../Transforms/Instrumentation/RealtimeSanitizer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index ae60122c13b07..b977badc9d6c1 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -45,13 +45,13 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn, insertCallBeforeInstruction(Fn, I, InsertFnName); } -static PreservedAnalyses rtsanPreservedAnalyses() { +static PreservedAnalyses rtsanPreservedCFGAnalyses() { PreservedAnalyses PA; PA.preserveSet(); return PA; } -static void transformRealtimeUnsafeFunction(Function &F) { +static void insertExpectNotRealtimeAtFunctionEntryPoint(Function &F) { IRBuilder<> Builder(&F.front().front()); Value *NameArg = Builder.CreateGlobalString(F.getName()); @@ -73,12 +73,12 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F, if (F.hasFnAttribute(Attribute::SanitizeRealtime)) { insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter"); insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit"); - return rtsanPreservedAnalyses(); + return rtsanPreservedCFGAnalyses(); } if (F.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { - transformRealtimeUnsafeFunction(F); - return rtsanPreservedAnalyses(); + insertExpectNotRealtimeAtFunctionEntryPoint(F); + return rtsanPreservedCFGAnalyses(); } return PreservedAnalyses::all(); From 8cc5872c4648d77007c10eb1e21f3f34b3fbd668 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Sat, 31 Aug 2024 19:04:23 +0100 Subject: [PATCH 03/10] Demangle [[clang::blocking]] function names in rtsan pass --- .../Instrumentation/RealtimeSanitizer.cpp | 3 ++- .../RealtimeSanitizer/rtsan_unsafe.ll | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index b977badc9d6c1..c3ea1471796bd 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h" using namespace llvm; @@ -53,7 +54,7 @@ static PreservedAnalyses rtsanPreservedCFGAnalyses() { static void insertExpectNotRealtimeAtFunctionEntryPoint(Function &F) { IRBuilder<> Builder(&F.front().front()); - Value *NameArg = Builder.CreateGlobalString(F.getName()); + Value *NameArg = Builder.CreateGlobalString(demangle(F.getName())); FunctionType *FuncType = FunctionType::get(Type::getVoidTy(F.getContext()), diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll index 646a9a0e22e21..0df01b95a79ae 100644 --- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll @@ -1,16 +1,19 @@ ; RUN: opt < %s -passes=rtsan -S | FileCheck %s -define void @blocking_function() #0 { +define void @_Z17blocking_functionv() #0 { ret void } define noundef i32 @main() #2 { - call void @blocking_function() #4 + call void @_Z17blocking_functionv() #4 ret i32 0 } attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } -; RealtimeSanitizer pass should insert __rtsan_expect_not_realtime at function entrypoint -; CHECK-LABEL: @blocking_function() -; CHECK-NEXT: call{{.*}}@__rtsan_expect_not_realtime({{ptr .*}}) +; RealtimeSanitizer pass should create the demangled function name as a global string, and +; pass it as input to an inserted __rtsan_expect_not_realtime call at the function entrypoint +; CHECK: [[GLOBAL_STR:@[a-zA-Z0-9\.]+]] +; CHECK-SAME: c"blocking_function()\00" +; CHECK-LABEL: @_Z17blocking_functionv() +; CHECK-NEXT: call{{.*}}@__rtsan_expect_not_realtime(ptr{{.*}}[[GLOBAL_STR]]) From e3302a424fa1469d823edfac14452b663c9afcff Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Sat, 21 Sep 2024 12:47:43 -0600 Subject: [PATCH 04/10] [rtsan] Update notify function name in blocking Pass --- llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp | 6 +++--- llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index c3ea1471796bd..f27cf83cd3cf3 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -52,7 +52,7 @@ static PreservedAnalyses rtsanPreservedCFGAnalyses() { return PA; } -static void insertExpectNotRealtimeAtFunctionEntryPoint(Function &F) { +static void insertNotifyBlockingCallAtFunctionEntryPoint(Function &F) { IRBuilder<> Builder(&F.front().front()); Value *NameArg = Builder.CreateGlobalString(demangle(F.getName())); @@ -61,7 +61,7 @@ static void insertExpectNotRealtimeAtFunctionEntryPoint(Function &F) { {PointerType::getUnqual(F.getContext())}, false); FunctionCallee Func = F.getParent()->getOrInsertFunction( - "__rtsan_expect_not_realtime", FuncType); + "__rtsan_notify_blocking_call", FuncType); Builder.CreateCall(Func, {NameArg}); } @@ -78,7 +78,7 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F, } if (F.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { - insertExpectNotRealtimeAtFunctionEntryPoint(F); + insertNotifyBlockingCallAtFunctionEntryPoint(F); return rtsanPreservedCFGAnalyses(); } diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll index 0df01b95a79ae..fe9f13778e35a 100644 --- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll @@ -16,4 +16,4 @@ attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwt ; CHECK: [[GLOBAL_STR:@[a-zA-Z0-9\.]+]] ; CHECK-SAME: c"blocking_function()\00" ; CHECK-LABEL: @_Z17blocking_functionv() -; CHECK-NEXT: call{{.*}}@__rtsan_expect_not_realtime(ptr{{.*}}[[GLOBAL_STR]]) +; CHECK-NEXT: call{{.*}}@__rtsan_notify_blocking_call(ptr{{.*}}[[GLOBAL_STR]]) From 1a7b7e3e87ea356e37d2ac6266c02c04f5aaea43 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Tue, 24 Sep 2024 16:58:16 +0100 Subject: [PATCH 05/10] [rtsan][NFC] Update test comment and variable names --- .../Instrumentation/RealtimeSanitizer.cpp | 24 +++++++++---------- .../RealtimeSanitizer/rtsan_unsafe.ll | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index f27cf83cd3cf3..3885fe049adc0 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -52,15 +52,15 @@ static PreservedAnalyses rtsanPreservedCFGAnalyses() { return PA; } -static void insertNotifyBlockingCallAtFunctionEntryPoint(Function &F) { - IRBuilder<> Builder(&F.front().front()); - Value *NameArg = Builder.CreateGlobalString(demangle(F.getName())); +static void insertNotifyBlockingCallAtFunctionEntryPoint(Function &Fn) { + IRBuilder<> Builder(&Fn.front().front()); + Value *NameArg = Builder.CreateGlobalString(demangle(Fn.getName())); FunctionType *FuncType = - FunctionType::get(Type::getVoidTy(F.getContext()), - {PointerType::getUnqual(F.getContext())}, false); + FunctionType::get(Type::getVoidTy(Fn.getContext()), + {PointerType::getUnqual(Fn.getContext())}, false); - FunctionCallee Func = F.getParent()->getOrInsertFunction( + FunctionCallee Func = Fn.getParent()->getOrInsertFunction( "__rtsan_notify_blocking_call", FuncType); Builder.CreateCall(Func, {NameArg}); @@ -69,16 +69,16 @@ static void insertNotifyBlockingCallAtFunctionEntryPoint(Function &F) { RealtimeSanitizerPass::RealtimeSanitizerPass( const RealtimeSanitizerOptions &Options) {} -PreservedAnalyses RealtimeSanitizerPass::run(Function &F, +PreservedAnalyses RealtimeSanitizerPass::run(Function &Fn, AnalysisManager &AM) { - if (F.hasFnAttribute(Attribute::SanitizeRealtime)) { - insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter"); - insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit"); + if (Fn.hasFnAttribute(Attribute::SanitizeRealtime)) { + insertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter"); + insertCallAtAllFunctionExitPoints(Fn, "__rtsan_realtime_exit"); return rtsanPreservedCFGAnalyses(); } - if (F.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { - insertNotifyBlockingCallAtFunctionEntryPoint(F); + if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { + insertNotifyBlockingCallAtFunctionEntryPoint(Fn); return rtsanPreservedCFGAnalyses(); } diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll index fe9f13778e35a..68d9e0b195ba4 100644 --- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll @@ -11,8 +11,8 @@ define noundef i32 @main() #2 { attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } -; RealtimeSanitizer pass should create the demangled function name as a global string, and -; pass it as input to an inserted __rtsan_expect_not_realtime call at the function entrypoint +; RealtimeSanitizer pass should create the demangled function name as a global string and, +; at the function entrypoint, pass it as an argument to the rtsan notify method ; CHECK: [[GLOBAL_STR:@[a-zA-Z0-9\.]+]] ; CHECK-SAME: c"blocking_function()\00" ; CHECK-LABEL: @_Z17blocking_functionv() From 47754d4418898d8d38bab96b61622af67219ed29 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Tue, 24 Sep 2024 17:23:14 +0100 Subject: [PATCH 06/10] [LLVM][rtsan] Refactor rtsan pass for code re-use --- .../Instrumentation/RealtimeSanitizer.cpp | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index 3885fe049adc0..fd68f43f88254 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -20,30 +20,43 @@ #include "llvm/Demangle/Demangle.h" #include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h" +#include + using namespace llvm; +static std::vector getArgTypes(ArrayRef FunctionArgs) { + std::vector Types; + for (Value *Arg : FunctionArgs) + Types.push_back(Arg->getType()); + return Types; +} + static void insertCallBeforeInstruction(Function &Fn, Instruction &Instruction, - const char *FunctionName) { + const char *FunctionName, + ArrayRef FunctionArgs) { LLVMContext &Context = Fn.getContext(); - FunctionType *FuncType = FunctionType::get(Type::getVoidTy(Context), false); + FunctionType *FuncType = FunctionType::get(Type::getVoidTy(Context), + getArgTypes(FunctionArgs), false); FunctionCallee Func = Fn.getParent()->getOrInsertFunction(FunctionName, FuncType); IRBuilder<> Builder{&Instruction}; - Builder.CreateCall(Func, {}); + Builder.CreateCall(Func, FunctionArgs); } static void insertCallAtFunctionEntryPoint(Function &Fn, - const char *InsertFnName) { - - insertCallBeforeInstruction(Fn, Fn.front().front(), InsertFnName); + const char *InsertFnName, + ArrayRef FunctionArgs) { + insertCallBeforeInstruction(Fn, Fn.front().front(), InsertFnName, + FunctionArgs); } static void insertCallAtAllFunctionExitPoints(Function &Fn, - const char *InsertFnName) { + const char *InsertFnName, + ArrayRef FunctionArgs) { for (auto &BB : Fn) for (auto &I : BB) if (isa(&I)) - insertCallBeforeInstruction(Fn, I, InsertFnName); + insertCallBeforeInstruction(Fn, I, InsertFnName, FunctionArgs); } static PreservedAnalyses rtsanPreservedCFGAnalyses() { @@ -52,18 +65,17 @@ static PreservedAnalyses rtsanPreservedCFGAnalyses() { return PA; } -static void insertNotifyBlockingCallAtFunctionEntryPoint(Function &Fn) { - IRBuilder<> Builder(&Fn.front().front()); - Value *NameArg = Builder.CreateGlobalString(demangle(Fn.getName())); - - FunctionType *FuncType = - FunctionType::get(Type::getVoidTy(Fn.getContext()), - {PointerType::getUnqual(Fn.getContext())}, false); - - FunctionCallee Func = Fn.getParent()->getOrInsertFunction( - "__rtsan_notify_blocking_call", FuncType); +static PreservedAnalyses runSanitizeRealtime(Function &Fn) { + insertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter", {}); + insertCallAtAllFunctionExitPoints(Fn, "__rtsan_realtime_exit", {}); + return rtsanPreservedCFGAnalyses(); +} - Builder.CreateCall(Func, {NameArg}); +static PreservedAnalyses runSanitizeRealtimeUnsafe(Function &Fn) { + IRBuilder<> Builder(&Fn.front().front()); + Value *Name = Builder.CreateGlobalString(demangle(Fn.getName())); + insertCallAtFunctionEntryPoint(Fn, "__rtsan_notify_blocking_call", {Name}); + return rtsanPreservedCFGAnalyses(); } RealtimeSanitizerPass::RealtimeSanitizerPass( @@ -71,16 +83,11 @@ RealtimeSanitizerPass::RealtimeSanitizerPass( PreservedAnalyses RealtimeSanitizerPass::run(Function &Fn, AnalysisManager &AM) { - if (Fn.hasFnAttribute(Attribute::SanitizeRealtime)) { - insertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter"); - insertCallAtAllFunctionExitPoints(Fn, "__rtsan_realtime_exit"); - return rtsanPreservedCFGAnalyses(); - } + if (Fn.hasFnAttribute(Attribute::SanitizeRealtime)) + return runSanitizeRealtime(Fn); - if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { - insertNotifyBlockingCallAtFunctionEntryPoint(Fn); - return rtsanPreservedCFGAnalyses(); - } + if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) + return runSanitizeRealtimeUnsafe(Fn); return PreservedAnalyses::all(); } From 0e656bb4724014800fcf5595523a951d79565dbc Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Tue, 24 Sep 2024 18:08:36 +0100 Subject: [PATCH 07/10] [LLVM][rtsan] Reserve space for types vector in pass --- llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index fd68f43f88254..49e1ab17effe8 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -26,6 +26,7 @@ using namespace llvm; static std::vector getArgTypes(ArrayRef FunctionArgs) { std::vector Types; + Types.reserve(FunctionArgs.size()); for (Value *Arg : FunctionArgs) Types.push_back(Arg->getType()); return Types; From 384d92f24bcee9099c03cfc3c4fa2e2c8dad63e5 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Wed, 25 Sep 2024 12:19:03 +0100 Subject: [PATCH 08/10] [LLVM][rtsan] Switch to SmallVector in rtsan Pass --- llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index 49e1ab17effe8..707b447f4664a 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -20,13 +20,10 @@ #include "llvm/Demangle/Demangle.h" #include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h" -#include - using namespace llvm; -static std::vector getArgTypes(ArrayRef FunctionArgs) { - std::vector Types; - Types.reserve(FunctionArgs.size()); +static SmallVector getArgTypes(ArrayRef FunctionArgs) { + SmallVector Types; for (Value *Arg : FunctionArgs) Types.push_back(Arg->getType()); return Types; From bc0f8edf14c9f7cacaa3008668b58923ccad99e8 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Wed, 25 Sep 2024 12:53:41 +0100 Subject: [PATCH 09/10] [LLVM][rtsan] Update sanitize_realtime_unsafe test --- .../RealtimeSanitizer/rtsan_unsafe.ll | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll index 68d9e0b195ba4..5abf5de304481 100644 --- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll +++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll @@ -1,19 +1,31 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5 ; RUN: opt < %s -passes=rtsan -S | FileCheck %s +; RealtimeSanitizer pass should create the demangled function name as a global string and, +; at the function entrypoint, pass it as an argument to the rtsan notify method + +;. +; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [20 x i8] c"blocking_function()\00", align 1 +;. define void @_Z17blocking_functionv() #0 { +; CHECK-LABEL: define void @_Z17blocking_functionv( +; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: call void @__rtsan_notify_blocking_call(ptr @[[GLOB0]]) +; CHECK-NEXT: ret void +; ret void } define noundef i32 @main() #2 { +; CHECK-LABEL: define noundef i32 @main() { +; CHECK-NEXT: call void @_Z17blocking_functionv() +; CHECK-NEXT: ret i32 0 +; call void @_Z17blocking_functionv() #4 ret i32 0 } attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } - -; RealtimeSanitizer pass should create the demangled function name as a global string and, -; at the function entrypoint, pass it as an argument to the rtsan notify method -; CHECK: [[GLOBAL_STR:@[a-zA-Z0-9\.]+]] -; CHECK-SAME: c"blocking_function()\00" -; CHECK-LABEL: @_Z17blocking_functionv() -; CHECK-NEXT: call{{.*}}@__rtsan_notify_blocking_call(ptr{{.*}}[[GLOBAL_STR]]) +;. +; CHECK: attributes #[[ATTR0]] = { mustprogress noinline optnone sanitize_realtime_unsafe ssp uwtable(sync) } +;. From b4db72675b6ba8a50492c912fca8349021205784 Mon Sep 17 00:00:00 2001 From: David Trevelyan Date: Wed, 25 Sep 2024 22:35:39 +0100 Subject: [PATCH 10/10] [LLVM][rtsan] Use convenient instructions iterator --- llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index 707b447f4664a..c4cb72ab2e4da 100644 --- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp @@ -15,6 +15,7 @@ #include "llvm/IR/Analysis.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/Module.h" #include "llvm/Demangle/Demangle.h" @@ -51,10 +52,9 @@ static void insertCallAtFunctionEntryPoint(Function &Fn, static void insertCallAtAllFunctionExitPoints(Function &Fn, const char *InsertFnName, ArrayRef FunctionArgs) { - for (auto &BB : Fn) - for (auto &I : BB) - if (isa(&I)) - insertCallBeforeInstruction(Fn, I, InsertFnName, FunctionArgs); + for (auto &I : instructions(Fn)) + if (isa(&I)) + insertCallBeforeInstruction(Fn, I, InsertFnName, FunctionArgs); } static PreservedAnalyses rtsanPreservedCFGAnalyses() {