Skip to content

Commit ee564ab

Browse files
committed
[LLVM][rtsan] Add nosanitize_realtime instrumentation
1 parent 556e9d0 commit ee564ab

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "llvm/Transforms/Instrumentation/RealtimeSanitizer.h"
2121

22+
#include <cassert>
23+
2224
using namespace llvm;
2325

2426
static void insertCallBeforeInstruction(Function &Fn, Instruction &Instruction,
@@ -51,6 +53,7 @@ RealtimeSanitizerPass::RealtimeSanitizerPass(
5153
PreservedAnalyses RealtimeSanitizerPass::run(Function &F,
5254
AnalysisManager<Function> &AM) {
5355
if (F.hasFnAttribute(Attribute::SanitizeRealtime)) {
56+
assert(!F.hasFnAttribute(Attribute::NoSanitizeRealtime));
5457
insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter");
5558
insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit");
5659

@@ -59,5 +62,15 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F,
5962
return PA;
6063
}
6164

65+
if (F.hasFnAttribute(Attribute::NoSanitizeRealtime)) {
66+
assert(!F.hasFnAttribute(Attribute::SanitizeRealtime));
67+
insertCallAtFunctionEntryPoint(F, "__rtsan_off");
68+
insertCallAtAllFunctionExitPoints(F, "__rtsan_on");
69+
70+
PreservedAnalyses PA;
71+
PA.preserveSet<CFGAnalyses>();
72+
return PA;
73+
}
74+
6275
return PreservedAnalyses::all();
6376
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: opt < %s -passes=rtsan -S | FileCheck %s
2+
3+
define void @nosanitized_function() #0 {
4+
%1 = alloca ptr, align 8
5+
%2 = call ptr @malloc(i64 noundef 2) #3
6+
store ptr %2, ptr %1, align 8
7+
ret void
8+
}
9+
10+
declare ptr @malloc(i64 noundef) #1
11+
12+
define noundef i32 @main() #2 {
13+
%1 = alloca i32, align 4
14+
store i32 0, ptr %1, align 4
15+
call void @nosanitized_function() #4
16+
ret i32 0
17+
}
18+
19+
attributes #0 = { nosanitize_realtime }
20+
21+
; CHECK-LABEL: @nosanitized_function()
22+
; CHECK-NEXT: call{{.*}}@__rtsan_off
23+
24+
; CHECK: call{{.*}}@__rtsan_on
25+
; CHECK-NEXT: ret{{.*}}void

0 commit comments

Comments
 (0)