Skip to content

Commit

Permalink
Demangle [[clang::blocking]] function names in rtsan pass
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrevelyan committed Sep 21, 2024
1 parent f4c722c commit b354df2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
Expand Down
13 changes: 8 additions & 5 deletions llvm/test/Instrumentation/RealtimeSanitizer/rtsan_unsafe.ll
Original file line number Diff line number Diff line change
@@ -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]])

0 comments on commit b354df2

Please sign in to comment.