Skip to content

Commit 8877924

Browse files
[rtsan] Handle attributed IR function declarations
Addresses #169377. Previously, the RealtimeSanitizer pass only handled attributed function definitions in IR, and attributed function declarations caused it to crash. To fix the issue, we must check whether the IR function is empty before attempting to do any manipulation of its instructions.
1 parent 4604762 commit 8877924

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,21 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn,
6161
insertCallBeforeInstruction(Fn, I, InsertFnName, FunctionArgs);
6262
}
6363

64-
static PreservedAnalyses rtsanPreservedCFGAnalyses() {
65-
PreservedAnalyses PA;
66-
PA.preserveSet<CFGAnalyses>();
67-
return PA;
68-
}
64+
static void runSanitizeRealtime(Function &Fn) {
65+
if (Fn.empty())
66+
return;
6967

70-
static PreservedAnalyses runSanitizeRealtime(Function &Fn) {
7168
insertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter", {});
7269
insertCallAtAllFunctionExitPoints(Fn, "__rtsan_realtime_exit", {});
73-
return rtsanPreservedCFGAnalyses();
7470
}
7571

76-
static PreservedAnalyses runSanitizeRealtimeBlocking(Function &Fn) {
72+
static void runSanitizeRealtimeBlocking(Function &Fn) {
73+
if (Fn.empty())
74+
return;
75+
7776
IRBuilder<> Builder(&Fn.front().front());
7877
Value *Name = Builder.CreateGlobalString(demangle(Fn.getName()));
7978
insertCallAtFunctionEntryPoint(Fn, "__rtsan_notify_blocking_call", {Name});
80-
return rtsanPreservedCFGAnalyses();
8179
}
8280

8381
PreservedAnalyses RealtimeSanitizerPass::run(Module &M,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: opt < %s -passes='rtsan' -S | FileCheck %s
2+
3+
declare void @declared_realtime_function() sanitize_realtime #0
4+
5+
declare void @declared_blocking_function() sanitize_realtime_blocking #0
6+
7+
; RealtimeSanitizer pass should ignore attributed functions that are just declarations
8+
; CHECK: declared_realtime_function
9+
; CHECK-EMPTY:
10+
; CHECK: declared_blocking_function
11+
; CHECK-EMPTY:
12+

0 commit comments

Comments
 (0)