Skip to content

Commit 5d4c441

Browse files
[rtsan] Handle attributed IR function declarations (#169577)
Addresses #169377. Previously, the RealtimeSanitizer pass only handled attributed function _definitions_ in IR, and we have recently found that 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. This PR: - Adds checks for whether IR `Function`s are `empty()` ~~in each relevant~~ at the top-level RTSan pass routine - ~~Removes the utility function `rtsanPreservedCFGAnalyses` from the pass, whose result was unused and which would otherwise have complicated the fix~~
1 parent af2e246 commit 5d4c441

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ PreservedAnalyses RealtimeSanitizerPass::run(Module &M,
9090
[&](Function *Ctor, FunctionCallee) { appendToGlobalCtors(M, Ctor, 0); });
9191

9292
for (Function &F : M) {
93+
if (F.empty())
94+
continue;
95+
9396
if (F.hasFnAttribute(Attribute::SanitizeRealtime))
9497
runSanitizeRealtime(F);
9598

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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:

0 commit comments

Comments
 (0)