diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp index b977badc9d6c1f5..c3ea1471796bdfd 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 646a9a0e22e213b..0df01b95a79aea4 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]])